ms-vite-plugin 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/build/index.js +1 -0
  2. package/dist/cli.js +6 -6
  3. package/dist/device/project.js +1 -0
  4. package/dist/mcp/device-log.js +1 -1
  5. package/dist/mcp/image-tools.js +1 -1
  6. package/dist/mcp/runtime-tools.js +1 -1
  7. package/dist/mcp-server.js +1 -1
  8. package/dist/packaging/index.js +1 -0
  9. package/package.json +1 -1
  10. package/dist/build.js +0 -1
  11. package/dist/luaObfuscator/addVararg.d.ts +0 -2
  12. package/dist/luaObfuscator/addVararg.js +0 -1
  13. package/dist/luaObfuscator/antiTamper.d.ts +0 -2
  14. package/dist/luaObfuscator/antiTamper.js +0 -26
  15. package/dist/luaObfuscator/ast.d.ts +0 -191
  16. package/dist/luaObfuscator/ast.js +0 -1
  17. package/dist/luaObfuscator/cipher.d.ts +0 -10
  18. package/dist/luaObfuscator/cipher.js +0 -28
  19. package/dist/luaObfuscator/compiler.d.ts +0 -31
  20. package/dist/luaObfuscator/compiler.js +0 -1
  21. package/dist/luaObfuscator/constantArray.d.ts +0 -5
  22. package/dist/luaObfuscator/constantArray.js +0 -1
  23. package/dist/luaObfuscator/flatten.d.ts +0 -2
  24. package/dist/luaObfuscator/flatten.js +0 -1
  25. package/dist/luaObfuscator/index.d.ts +0 -6
  26. package/dist/luaObfuscator/index.js +0 -1
  27. package/dist/luaObfuscator/lexer.d.ts +0 -14
  28. package/dist/luaObfuscator/lexer.js +0 -10
  29. package/dist/luaObfuscator/minify.d.ts +0 -3
  30. package/dist/luaObfuscator/minify.js +0 -1
  31. package/dist/luaObfuscator/numbers.d.ts +0 -2
  32. package/dist/luaObfuscator/numbers.js +0 -1
  33. package/dist/luaObfuscator/opcodes.d.ts +0 -3
  34. package/dist/luaObfuscator/opcodes.js +0 -1
  35. package/dist/luaObfuscator/parser.d.ts +0 -8
  36. package/dist/luaObfuscator/parser.js +0 -1
  37. package/dist/luaObfuscator/rename.d.ts +0 -3
  38. package/dist/luaObfuscator/rename.js +0 -1
  39. package/dist/luaObfuscator/reserved.d.ts +0 -5
  40. package/dist/luaObfuscator/reserved.js +0 -1
  41. package/dist/luaObfuscator/scope.d.ts +0 -11
  42. package/dist/luaObfuscator/scope.js +0 -1
  43. package/dist/luaObfuscator/selftest.d.ts +0 -1
  44. package/dist/luaObfuscator/selftest.js +0 -39
  45. package/dist/luaObfuscator/splitStrings.d.ts +0 -2
  46. package/dist/luaObfuscator/splitStrings.js +0 -1
  47. package/dist/luaObfuscator/strings.d.ts +0 -4
  48. package/dist/luaObfuscator/strings.js +0 -1
  49. package/dist/luaObfuscator/visit.d.ts +0 -5
  50. package/dist/luaObfuscator/visit.js +0 -1
  51. package/dist/luaObfuscator/vmEmit.d.ts +0 -2
  52. package/dist/luaObfuscator/vmEmit.js +0 -281
  53. package/dist/luaObfuscator/wrapInFunction.d.ts +0 -2
  54. package/dist/luaObfuscator/wrapInFunction.js +0 -1
  55. package/dist/packager.js +0 -1
  56. package/dist/project.js +0 -1
  57. /package/dist/{build.d.ts → build/index.d.ts} +0 -0
  58. /package/dist/{luaBundle.d.ts → build/luaBundle.d.ts} +0 -0
  59. /package/dist/{luaBundle.js → build/luaBundle.js} +0 -0
  60. /package/dist/{scriptProtect.d.ts → build/scriptProtect.d.ts} +0 -0
  61. /package/dist/{scriptProtect.js → build/scriptProtect.js} +0 -0
  62. /package/dist/{stopGuardPlugin.d.ts → build/stopGuardPlugin.d.ts} +0 -0
  63. /package/dist/{stopGuardPlugin.js → build/stopGuardPlugin.js} +0 -0
  64. /package/dist/{project.d.ts → device/project.d.ts} +0 -0
  65. /package/dist/{usb-forward.d.ts → device/usb-forward.d.ts} +0 -0
  66. /package/dist/{usb-forward.js → device/usb-forward.js} +0 -0
  67. /package/dist/{ws-manager.d.ts → device/ws-manager.d.ts} +0 -0
  68. /package/dist/{ws-manager.js → device/ws-manager.js} +0 -0
  69. /package/dist/{packager.d.ts → packaging/index.d.ts} +0 -0
@@ -1,31 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- import { type OpcodeName } from "./opcodes";
3
- export type ConstVal = {
4
- t: "nil";
5
- } | {
6
- t: "bool";
7
- v: boolean;
8
- } | {
9
- t: "num";
10
- v: number;
11
- raw: string;
12
- } | {
13
- t: "str";
14
- v: string;
15
- };
16
- export interface UpvalSpec {
17
- name: string;
18
- inStack: boolean;
19
- index: number;
20
- }
21
- export interface Proto {
22
- code: number[][];
23
- ops: OpcodeName[];
24
- consts: ConstVal[];
25
- protos: Proto[];
26
- upvals: UpvalSpec[];
27
- numparams: number;
28
- isVararg: boolean;
29
- maxStack: number;
30
- }
31
- export declare function compileChunk(chunk: Chunk): Proto;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(n,t=0,o=0,s=0){return this.ops.push(n),this.code.push([0,t,o,s]),this.code.length-1}patch(n,t,o,s){const a=this.code[n];t!==void 0&&(a[1]=t),o!==void 0&&(a[2]=o),s!==void 0&&(a[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(n){return this.intern({t:"bool",v:n})}kNum(n,t){return this.intern({t:"num",v:n,raw:t})}kStr(n){return this.intern({t:"str",v:n})}intern(n){for(let t=0;t<this.consts.length;t+=1){const o=this.consts[t];if(o.t===n.t&&(o.t==="nil"||o.t==="bool"&&n.t==="bool"&&o.v===n.v||o.t==="num"&&n.t==="num"&&o.v===n.v||o.t==="str"&&n.t==="str"&&o.v===n.v))return t+1}return this.consts.push(n),this.consts.length}alloc(n=1){const t=this.top;return this.top+=n,this.top-1>this.maxStack&&(this.maxStack=this.top-1),t}freeTo(n){this.top=n}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(n,t=!1){const o=this.alloc(1);return this.currentLocals().push({name:n,reg:o,close:t}),o}findLocal(n){for(let t=this.frames.length-1;t>=0;t-=1){const o=this.frames[t].locals;for(let s=o.length-1;s>=0;s-=1)if(o[s].name===n)return o[s].reg}}findUpval(n){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===n)return s+1;if(!this.parent)return;const t=this.parent.findLocal(n);if(t!==void 0)return this.upvals.push({name:n,inStack:!0,index:t}),this.upvals.length;const o=this.parent.findUpval(n);if(o!==void 0)return this.upvals.push({name:n,inStack:!1,index:o}),this.upvals.length}finish(){for(const n of this.gotos){const t=this.labels.get(n.name);if(t===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${n.name}::`);this.patch(n.pc,0,t-(n.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(e){const n=new O;return n.isVararg=!0,n.pushFrame(),u(n,e.body),n.emit("RETURN",1,0),n.finish()}function d(e,n){const t=new O;t.parent=e,t.numparams=n.params.length,t.isVararg=n.vararg,t.pushFrame();for(const o of n.params)t.bind(o);return u(t,n.body.body),t.emit("RETURN",1,0),e.protos.push(t.finish()),e.protos.length}function u(e,n){for(const t of n)B(e,t)}function p(e,n){for(const t of n.locals)e.emit("CLOSE",t.reg);e.freeTo(n.savedTop)}function B(e,n){switch(n.type){case"EmptyStat":return;case"BreakStat":{if(e.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const t=e.emit("JMP",0,0);e.breaks[e.breaks.length-1].push(t);return}case"GotoStat":{const t=e.emit("JMP",0,0);e.gotos.push({name:n.name,pc:t});return}case"LabelStat":e.labels.set(n.name,e.code.length);return;case"DoStat":{e.pushFrame(),u(e,n.body.body),p(e,e.frames.pop());return}case"WhileStat":{const t=e.code.length,o=r(e,n.cond);e.emit("TEST",o,0,0);const s=e.emit("JMP",0,0);e.freeTo(o),e.breaks.push([]),e.pushFrame(),u(e,n.body.body),p(e,e.frames.pop()),e.emit("JMP",0,t-(e.code.length+1)),e.patch(s,0,e.code.length-(s+1)),f(e,e.breaks.pop(),e.code.length);return}case"RepeatStat":{const t=e.code.length;e.breaks.push([]),e.pushFrame(),u(e,n.body.body);const o=r(e,n.cond);e.emit("TEST",o,0,0),e.emit("JMP",0,t-(e.code.length+1)),p(e,e.frames.pop()),f(e,e.breaks.pop(),e.code.length);return}case"IfStat":{const t=[];for(let o=0;o<n.clauses.length;o+=1){const s=r(e,n.clauses[o].cond);e.emit("TEST",s,0,0);const a=e.emit("JMP",0,0);e.freeTo(s),e.pushFrame(),u(e,n.clauses[o].body.body),p(e,e.frames.pop()),(o<n.clauses.length-1||n.elseBody)&&t.push(e.emit("JMP",0,0)),e.patch(a,0,e.code.length-(a+1))}n.elseBody&&(e.pushFrame(),u(e,n.elseBody.body),p(e,e.frames.pop()));for(const o of t)e.patch(o,0,e.code.length-(o+1));return}case"ForNumStat":{const t=e.alloc(4);r(e,n.start,t),r(e,n.end,t+1),n.step?r(e,n.step,t+2):e.emit("LOADK",t+2,e.kNum(1,"1"));const o=e.emit("FORPREP",t,0);e.breaks.push([]),e.pushFrame();const s=e.bind(n.name);e.emit("MOVE",s,t+3),u(e,n.body.body),p(e,e.frames.pop());const a=e.emit("FORLOOP",t,0);e.patch(o,t,a-(o+1)),e.patch(a,t,o+1-(a+1)),f(e,e.breaks.pop(),e.code.length),e.freeTo(t);return}case"ForInStat":{const t=e.alloc(3);h(e,n.exps,t,3);const o=e.emit("TFORCALL",t,n.names.length),s=e.emit("TFORLOOP",t,0);e.breaks.push([]),e.pushFrame();for(let a=0;a<n.names.length;a+=1){const i=e.bind(n.names[a]);e.emit("MOVE",i,t+3+a)}u(e,n.body.body),p(e,e.frames.pop()),e.emit("JMP",0,o-(e.code.length+1)),e.patch(s,t,e.code.length-(s+1)),f(e,e.breaks.pop(),e.code.length),e.freeTo(t);return}case"FuncStat":{const t=d(e,n.func),o=e.alloc(1);e.emit("CLOSURE",o,t),w(e,n.name.base,n.name.fields,n.name.method,o),e.freeTo(o);return}case"LocalFuncStat":{const t=e.bind(n.name),o=d(e,n.func);e.emit("CLOSURE",t,o);return}case"LocalStat":{const t=n.names.length,o=[];if(n.exps&&n.exps.length>0){const s=e.top;h(e,n.exps,s,t);for(let a=0;a<t;a+=1){const i=e.bind(n.names[a].name,n.names[a].attr==="close");e.emit("MOVE",i,s+a),o.push(i)}e.freeTo(o[0]),e.top=o[t-1]+1}else for(const s of n.names){const a=e.bind(s.name,s.attr==="close");e.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const t=e.top;h(e,n.exps,t,n.vars.length);for(let o=0;o<n.vars.length;o+=1)F(e,n.vars[o],t+o);e.freeTo(t);return}case"CallStat":{const t=e.top;r(e,n.exp,void 0,0),e.freeTo(t);return}case"ReturnStat":{if(n.exps.length===0){e.emit("RETURN",1,0);return}const t=e.top;h(e,n.exps,t,-1);const o=n.exps[n.exps.length-1],s=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";e.emit("RETURN",t,s?-1:n.exps.length);return}}}function f(e,n,t){for(const o of n)e.patch(o,0,t-(o+1))}function w(e,n,t,o,s){if(t.length===0&&!o){S(e,n,s);return}let a=T(e,n);const i=o?[...t,o]:t;for(let c=0;c<i.length-1;c+=1){const l=e.alloc(1);e.emit("GETTABLE",l,a,-e.kStr(i[c])),a=l}e.emit("SETTABLE",a,-e.kStr(i[i.length-1]),s)}function S(e,n,t){const o=e.findLocal(n);if(o!==void 0){e.emit("MOVE",o,t);return}const s=e.findUpval(n);if(s!==void 0){e.emit("SETUPVAL",t,s);return}e.emit("SETGLOBAL",t,e.kStr(n))}function T(e,n,t){const o=t??e.alloc(1),s=e.findLocal(n);if(s!==void 0)return o!==s&&e.emit("MOVE",o,s),o;const a=e.findUpval(n);return a!==void 0?(e.emit("GETUPVAL",o,a),o):(e.emit("GETGLOBAL",o,e.kStr(n)),o)}function F(e,n,t){if(n.type==="NameExpr"){S(e,n.name,t);return}if(n.type==="MemberExpr"){const o=r(e,n.object);e.emit("SETTABLE",o,-e.kStr(n.field),t);return}if(n.type==="IndexExpr"){const o=r(e,n.object),s=r(e,n.index);e.emit("SETTABLE",o,s,t);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function r(e,n,t,o=1){const s=t??e.alloc(1);switch(n.type){case"NilLiteral":return e.emit("LOADNIL",s),s;case"BoolLiteral":return e.emit("LOADBOOL",s,n.value?1:0),s;case"NumberLiteral":return e.emit("LOADK",s,e.kNum(n.value,n.raw)),s;case"StringLiteral":return e.emit("LOADK",s,e.kStr(n.value)),s;case"VarargExpr":return e.emit("VARARG",s,o),s;case"NameExpr":return T(e,n.name,s);case"ParenExpr":return r(e,n.exp,s,1);case"UnaryExpr":{const a=r(e,n.arg);return e.emit(A[n.op],s,a),s}case"BinaryExpr":return M(e,n.op,n.left,n.right,s);case"FuncExpr":{const a=d(e,n);return e.emit("CLOSURE",s,a),s}case"TableExpr":return R(e,n.fields,s);case"IndexExpr":{const a=r(e,n.object),i=r(e,n.index);return e.emit("GETTABLE",s,a,i),s}case"MemberExpr":{const a=r(e,n.object);return e.emit("GETTABLE",s,a,-e.kStr(n.field)),s}case"CallExpr":return y(e,n.callee,n.args,s,o,!1);case"MethodCallExpr":return y(e,n.object,n.args,s,o,n.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${n.type}`)}}function M(e,n,t,o,s){if(n==="and"||n==="or"){r(e,t,s),e.emit("TEST",s,0,n==="and"?0:1);const l=e.emit("JMP",0,0);return r(e,o,s),e.patch(l,0,e.code.length-(l+1)),s}if(n==="=="||n==="~="||n==="<"||n===">"||n==="<="||n===">="){const l=r(e,t),b=r(e,o);let m="EQ",g=l,E=b;n==="<"||n===">="?m="LT":n==="<="||n===">"?m="LE":m="EQ",(n===">"||n===">=")&&(g=b,E=l);const x=n==="~=";e.emit(m,g,E,x?1:0);const L=e.emit("JMP",0,0);e.emit("LOADBOOL",s,1);const v=e.emit("JMP",0,0);return e.patch(L,0,e.code.length-(L+1)),e.emit("LOADBOOL",s,0),e.patch(v,0,e.code.length-(v+1)),s}const a=k[n];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${n}`);const i=r(e,t),c=r(e,o);return e.emit(a,s,i,c),s}function N(e){return e.type==="CallExpr"||e.type==="MethodCallExpr"||e.type==="VarargExpr"}function y(e,n,t,o,s,a){const i=o,c=t.length>0&&N(t[t.length-1]);if(a){const l=r(e,n,i);return e.emit("SELF",i,l,-e.kStr(a)),h(e,t,i+2,-1),e.emit("CALL",i,c?-1:t.length+1,s),i}return r(e,n,i),h(e,t,i+1,-1),e.emit("CALL",i,c?-1:t.length,s),i}function h(e,n,t,o){const s=o>0?o:Math.max(n.length,1);if(e.top<t+s&&(e.top=t+s,e.top-1>e.maxStack&&(e.maxStack=e.top-1)),n.length===0){if(o>0)for(let a=0;a<o;a+=1)e.emit("LOADNIL",t+a);return}for(let a=0;a<n.length;a+=1){const i=a===n.length-1,c=i&&(o<0||o>n.length)?o===-1?-1:o-a:1;r(e,n[a],t+a,i?c:1)}if(o>n.length)for(let a=n.length;a<o;a+=1)e.emit("LOADNIL",t+a)}function R(e,n,t){e.emit("NEWTABLE",t);const o=[];for(const s of n)if(s.kind==="list")o.push(s.value);else if(s.kind==="name"){const a=r(e,s.value);e.emit("SETTABLE",t,-e.kStr(s.key),a)}else{const a=r(e,s.key),i=r(e,s.value);e.emit("SETTABLE",t,a,i)}if(o.length>0){const s=e.top;h(e,o,s,-1),e.emit("SETLIST",t,s,o.length),e.freeTo(s)}return t}
@@ -1,5 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export declare function applyConstantArray(chunk: Chunk, seed: number, options: {
3
- shuffle: boolean;
4
- rotate: boolean;
5
- }): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=h;const o=require("./visit"),s="__C",y="__G";function g(l,i){const n=l.slice();let a=i>>>0||1;for(let r=n.length-1;r>0;r-=1){a=Math.imul(a,1664525)+1013904223>>>0;const t=a%(r+1),p=n[r];n[r]=n[t],n[t]=p}return n}function h(l,i,n){const a=[],r=new Set;if((0,o.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),a.push(e.value)),e)),a.length===0)return;let t=n.shuffle?g(a,i):a.slice();const p=n.rotate?i%t.length:0;p>0&&(t=t.slice(p).concat(t.slice(0,p)));const c=new Map;for(let e=0;e<t.length;e+=1)c.set(t[e],e+1);(0,o.mapChunk)(l,e=>{if(e.type!=="StringLiteral")return e;const u=c.get(e.value);return u===void 0?e:{type:"CallExpr",callee:{type:"NameExpr",name:y},args:[{type:"NumberLiteral",raw:String(u),value:u}]}});const m=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),d={type:"LocalStat",names:[{name:s}],exps:[{type:"TableExpr",fields:m}]},f={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:s},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(d,f)}
@@ -1,2 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export declare function flattenControlFlow(chunk: Chunk, seed: number): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(e){return{type:"NumberLiteral",raw:String(e),value:e}}function y(e){return{type:"NameExpr",name:e}}function b(e,t){return{type:"AssignStat",vars:e.map(a=>y(a)),exps:t}}function u(e,t){return b([e.stateName],[typeof t=="number"?m(t):t])}function k(e,t,a){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:y(e),right:m(t)},right:m(a)}}function E(e,t,a){return{type:"BinaryExpr",op:e,left:t,right:a}}function S(e){const t=`__t${e.nextTemp}`;return e.nextTemp+=1,e.temps.push(t),t}function x(e){const t=e.nextState;return e.nextState+=1,e.states.set(t,[]),t}function r(e,t,a){e.states.get(t).push(a)}function L(e,t){for(const a of e)if(a.type==="LocalStat")for(const o of a.names)t.push(o.name);else if(a.type==="LocalFuncStat")t.push(a.name);else if(a.type==="ForNumStat")t.push(a.name),L(a.body.body,t);else if(a.type==="ForInStat")t.push(...a.names),L(a.body.body,t);else if(a.type==="DoStat"||a.type==="WhileStat"||a.type==="RepeatStat")L(a.body.body,t);else if(a.type==="IfStat"){for(const o of a.clauses)L(o.body.body,t);a.elseBody&&L(a.elseBody.body,t)}}function h(e,t,a,o){if(e.length===0)return t;const p=e.map(()=>x(a));for(let n=0;n<e.length;n+=1){const c=e[n];c.type==="LabelStat"&&a.userLabels.set(c.name,p[n])}for(let n=0;n<e.length;n+=1){const c=n+1<e.length?p[n+1]:t;I(a,p[n],e[n],c,o)}return p[0]}function I(e,t,a,o,p){switch(a.type){case"EmptyStat":case"LabelStat":r(e,t,u(e,o));return;case"AssignStat":case"CallStat":case"FuncStat":r(e,t,a),r(e,t,u(e,o));return;case"LocalStat":a.exps&&a.exps.length>0&&r(e,t,b(a.names.map(n=>n.name),a.exps)),r(e,t,u(e,o));return;case"LocalFuncStat":r(e,t,b([a.name],[a.func])),r(e,t,u(e,o));return;case"ReturnStat":r(e,t,a);return;case"BreakStat":r(e,t,u(e,p));return;case"GotoStat":{const n=e.userLabels.get(a.name);if(n===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${a.name}::`);r(e,t,u(e,n));return}case"DoStat":r(e,t,u(e,h(a.body.body,o,e,p)));return;case"IfStat":{const n=S(e);let c=t;for(let l=0;l<a.clauses.length;l+=1){const f=l===a.clauses.length-1,d=h(a.clauses[l].body.body,o,e,p);let i=o;f?a.elseBody&&(i=h(a.elseBody.body,o,e,p)):i=x(e),r(e,c,b([n],[a.clauses[l].cond])),r(e,c,u(e,k(n,d,i))),f||(c=i)}a.clauses.length===0&&r(e,t,u(e,o));return}case"WhileStat":{const n=S(e),c=h(a.body.body,t,e,o);r(e,t,b([n],[a.cond])),r(e,t,u(e,k(n,c,o)));return}case"RepeatStat":{const n=S(e),c=x(e),l=h(a.body.body,c,e,o);r(e,t,u(e,l)),r(e,c,b([n],[a.cond])),r(e,c,u(e,k(n,o,l)));return}case"ForNumStat":{const n=a.name,c=S(e),l=S(e),f=S(e),d=x(e),i=x(e),F=x(e),g=x(e),N=h(a.body.body,g,e,o);r(e,t,b([n],[a.start])),r(e,t,b([c],[a.end])),r(e,t,b([l],[a.step??m(1)])),r(e,t,u(e,d)),r(e,d,b([f],[E(">=",y(l),m(0))])),r(e,d,u(e,k(f,i,F))),r(e,i,b([f],[E("<=",y(n),y(c))])),r(e,i,u(e,k(f,N,o))),r(e,F,b([f],[E(">=",y(n),y(c))])),r(e,F,u(e,k(f,N,o))),r(e,g,b([n],[E("+",y(n),y(l))])),r(e,g,u(e,d));return}case"ForInStat":{const n=S(e),c=S(e),l=S(e),f=S(e),d=x(e),i=[b([l],[y(a.names[0])]),...a.body.body],F=h(i,d,e,o),g=a.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});r(e,t,b([n,c,l],g.slice(0,3))),r(e,t,u(e,d)),r(e,d,{type:"AssignStat",vars:a.names.map(N=>y(N)),exps:[{type:"CallExpr",callee:y(n),args:[y(c),y(l)]}]}),r(e,d,b([f],[E("~=",y(a.names[0]),{type:"NilLiteral"})])),r(e,d,u(e,k(f,F,o)));return}default:r(e,t,u(e,o))}}function v(e,t){const a=e.slice();let o=t>>>0||1;for(let p=a.length-1;p>0;p-=1){o=Math.imul(o,1664525)+1013904223>>>0;const n=o%(p+1),c=a[p];a[p]=a[n],a[n]=c}return a}function w(e,t){if(e.length===0)return e;const a={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},o=[];L(e,o);const p=h(e,0,a,0),n=[...new Set([...o,...a.temps,a.stateName])],c=v([...a.states.keys()],t).map(l=>({cond:E("==",y(a.stateName),m(l)),body:{type:"Block",body:a.states.get(l)}}));return[{type:"LocalStat",names:n.map(l=>({name:l}))},b([a.stateName],[m(p)]),{type:"WhileStat",cond:E("~=",y(a.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:c}]}}]}function s(e,t){switch(e.type){case"FuncExpr":B(e.body.body,t),e.body.body=w(e.body.body,t);break;case"UnaryExpr":s(e.arg,t);break;case"BinaryExpr":s(e.left,t),s(e.right,t);break;case"TableExpr":for(const a of e.fields)a.kind==="index"&&s(a.key,t),s(a.value,t);break;case"IndexExpr":s(e.object,t),s(e.index,t);break;case"MemberExpr":s(e.object,t);break;case"CallExpr":s(e.callee,t);for(const a of e.args)s(a,t);break;case"MethodCallExpr":s(e.object,t);for(const a of e.args)s(a,t);break;case"ParenExpr":s(e.exp,t);break;default:break}}function B(e,t){for(const a of e)switch(a.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((a.type==="WhileStat"||a.type==="RepeatStat")&&s(a.cond,t),a.type==="ForNumStat"&&(s(a.start,t),s(a.end,t),a.step&&s(a.step,t)),a.type==="ForInStat")for(const o of a.exps)s(o,t);B(a.body.body,t);break;case"IfStat":for(const o of a.clauses)s(o.cond,t),B(o.body.body,t);a.elseBody&&B(a.elseBody.body,t);break;case"FuncStat":case"LocalFuncStat":B(a.func.body.body,t),a.func.body.body=w(a.func.body.body,t);break;case"LocalStat":if(a.exps)for(const o of a.exps)s(o,t);break;case"AssignStat":for(const o of a.vars)s(o,t);for(const o of a.exps)s(o,t);break;case"CallStat":s(a.exp,t);break;case"ReturnStat":for(const o of a.exps)s(o,t);break;default:break}}function C(e,t){B(e.body,t),e.body=w(e.body,t)}
@@ -1,6 +0,0 @@
1
- export declare const luaObfuscatorPresets: readonly ["Minify", "Weak", "Medium", "Strong"];
2
- export type LuaObfuscatorPreset = (typeof luaObfuscatorPresets)[number];
3
- export declare function obfuscateLua(source: string, preset: LuaObfuscatorPreset): string;
4
- export { LuaLexError } from "./lexer";
5
- export { LuaParseError } from "./parser";
6
- export { foldDecrypt, foldEncrypt, createFoldMixParams } from "./strings";
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=E;const l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),n=require("./flatten"),c=require("./minify"),a=require("./numbers"),p=require("./parser"),m=require("./rename"),d=require("./splitStrings"),L=require("./vmEmit"),q=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function P(t){let u=2166136261;for(let r=0;r<t.length;r+=1)u=Math.imul(u^t.charCodeAt(r),16777619);return u>>>0||1}function o(t){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(t)))}function i(t,u,r){(0,y.applyConstantArray)(t,u,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(t,(u^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(t);return(0,m.renameLocals)(t),(0,c.minifyLua)(t)}function E(t,u){const r=P(t);let e=(0,p.parseLua)(t);return(0,m.renameLocals)(e),u==="Minify"?(0,c.minifyLua)(e):u==="Weak"?((0,n.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):u==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,n.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,l.addVararg)(e),(0,d.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,(r^2246822507)>>>0),(0,n.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var O=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return O.LuaLexError}});var g=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return g.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
@@ -1,14 +0,0 @@
1
- export type TokenKind = "eof" | "name" | "string" | "number" | "vararg" | "keyword" | "+" | "-" | "*" | "/" | "//" | "%" | "^" | "#" | "&" | "|" | "~" | "<<" | ">>" | "==" | "~=" | "<=" | ">=" | "<" | ">" | "=" | "(" | ")" | "{" | "}" | "[" | "]" | "::" | ";" | ":" | "," | "." | "..";
2
- export interface Token {
3
- kind: TokenKind;
4
- value: string;
5
- line: number;
6
- column: number;
7
- parsed?: number | string;
8
- }
9
- export declare class LuaLexError extends Error {
10
- readonly line: number;
11
- readonly column: number;
12
- constructor(message: string, line: number, column: number);
13
- }
14
- export declare function lexLua(source: string): Token[];
@@ -1,10 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=y;const L=require("./reserved");class F extends Error{constructor(s,l,c){super(`${s} (${l}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function y(v){const s=v.replace(/^\uFEFF/,""),l=[];let c=0,m=1,d=1;const n=(e=0)=>s[c+e]??"",h=()=>c>=s.length,u=()=>{const e=s[c++];return e===`
2
- `?(m+=1,d=1):d+=1,e},a=e=>{throw new F(e,m,d)},b=e=>e>="A"&&e<="Z"||e>="a"&&e<="z"||e==="_",E=e=>e>="0"&&e<="9",p=e=>E(e)||e>="a"&&e<="f"||e>="A"&&e<="F",C=e=>{const t=Buffer.from(e,"utf8");let r="";for(const i of t)r+=String.fromCharCode(i);return r},g=e=>e===" "||e===" "||e==="\r"||e===`
3
- `||e==="\f"||e==="\v",B=e=>{if(s[e]!=="[")return-1;let t=0,r=e+1;for(;s[r]==="=";)t+=1,r+=1;return s[r]==="["?t:-1},k=e=>{u();for(let r=0;r<e;r+=1)u();u(),n()==="\r"&&u(),n()===`
4
- `&&u();let t="";for(;!h();){if(n()==="]"){let r=c+1,i=0;for(;s[r]==="=";)i+=1,r+=1;if(i===e&&s[r]==="]"){u();for(let o=0;o<e;o+=1)u();return u(),t}}t+=C(u())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&n()!==`
5
- `;)u()},A=e=>{u();let t="";for(;!h();){const r=n();if(r===e)return u(),t;if(r===`
6
- `)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(r!=="\\"){t+=C(u());continue}u();const i=n();if(i==="a")u(),t+="\x07";else if(i==="b")u(),t+="\b";else if(i==="f")u(),t+="\f";else if(i==="n")u(),t+=`
7
- `;else if(i==="r")u(),t+="\r";else if(i==="t")u(),t+=" ";else if(i==="v")u(),t+="\v";else if(i==="\\"||i==='"'||i==="'"||i===`
8
- `)t+=u();else if(i==="\r")u(),n()===`
9
- `&&u(),t+=`
10
- `;else if(i==="x"){u();const o=n(),f=n(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");u(),u(),t+=String.fromCharCode(parseInt(o+f,16))}else if(i==="u"){if(u(),n()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");u();let o="";for(;p(n());)o+=u();if(n()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");u(),t+=C(String.fromCodePoint(parseInt(o,16)))}else if(i==="z")for(u();g(n());)u();else if(E(i)){let o="";for(;E(n())&&o.length<3;)o+=u();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");t+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${i}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},D=()=>{const e=m,t=d;let r="";if(n()==="0"&&(n(1)==="x"||n(1)==="X")){for(r+=u(),r+=u();p(n())||n()===".";)r+=u();if(n()==="p"||n()==="P")for(r+=u(),(n()==="+"||n()==="-")&&(r+=u());E(n());)r+=u()}else{for(;E(n())||n()===".";)r+=u();if(n()==="e"||n()==="E")for(r+=u(),(n()==="+"||n()==="-")&&(r+=u());E(n());)r+=u()}const i=Number(r);if(!Number.isFinite(i))throw new F(`\u65E0\u6548\u6570\u5B57 ${r}`,e,t);return{kind:"number",value:r,line:e,column:t,parsed:i}};for(;!h();){const e=n();if(g(e)){u();continue}if(e==="-"&&n(1)==="-"){const f=m,$=d;u(),u();const x=B(c);x>=0?k(x):w();continue}const t=m,r=d;if(e==="'"||e==='"'){const f=A(e);l.push({kind:"string",value:f,line:t,column:r,parsed:f});continue}const i=B(c);if(i>=0){const f=k(i);l.push({kind:"string",value:f,line:t,column:r,parsed:f});continue}if(E(e)||e==="."&&E(n(1))){l.push(D());continue}if(b(e)){let f="";for(;b(n())||E(n());)f+=u();l.push({kind:L.luaKeywords.has(f)?"keyword":"name",value:f,line:t,column:r});continue}const o=e+n(1);if(o+n(2)==="..."){u(),u(),u(),l.push({kind:"vararg",value:"...",line:t,column:r});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){u(),u(),l.push({kind:o,value:o,line:t,column:r});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(e)){u(),l.push({kind:e,value:e,line:t,column:r});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(e)}`)}return l.push({kind:"eof",value:"",line:m,column:d}),l}
@@ -1,3 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export declare function escapeLuaString(value: string): string;
3
- export declare function minifyLua(chunk: Chunk): string;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=e,exports.minifyLua=w;const l=new Set(["and","or"]);function e(t){let r='"';for(let a=0;a<t.length;a+=1){const u=t.charCodeAt(a)&255;r+=`\\${String(u).padStart(3,"0")}`}return r+='"',r}class i{constructor(){Object.defineProperty(this,"parts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"last",{enumerable:!0,configurable:!0,writable:!0,value:"none"})}word(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="word"}num(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="num"}punct(r){r===".."&&this.last==="num"&&this.parts.push(" "),r==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(r),this.last="punct"}toString(){return this.parts.join("")}}function w(t){const r=new i;return d(r,t.body,!0),r.toString()}function s(t,r){d(t,r.body,!1)}function d(t,r,a){for(let u=0;u<r.length;u+=1)h(t,r[u]),u<r.length-1&&t.punct(";")}function h(t,r){switch(r.type){case"EmptyStat":t.punct(";");return;case"BreakStat":t.word("break");return;case"GotoStat":t.word("goto"),t.word(r.name);return;case"LabelStat":t.punct("::"),t.word(r.name),t.punct("::");return;case"DoStat":t.word("do"),s(t,r.body),t.word("end");return;case"WhileStat":t.word("while"),o(t,r.cond),t.word("do"),s(t,r.body),t.word("end");return;case"RepeatStat":t.word("repeat"),s(t,r.body),t.word("until"),o(t,r.cond);return;case"IfStat":for(let a=0;a<r.clauses.length;a+=1)t.word(a===0?"if":"elseif"),o(t,r.clauses[a].cond),t.word("then"),s(t,r.clauses[a].body);r.elseBody&&(t.word("else"),s(t,r.elseBody)),t.word("end");return;case"ForNumStat":t.word("for"),t.word(r.name),t.punct("="),o(t,r.start),t.punct(","),o(t,r.end),r.step&&(t.punct(","),o(t,r.step)),t.word("do"),s(t,r.body),t.word("end");return;case"ForInStat":t.word("for");for(let a=0;a<r.names.length;a+=1)a>0&&t.punct(","),t.word(r.names[a]);t.word("in"),c(t,r.exps),t.word("do"),s(t,r.body),t.word("end");return;case"FuncStat":t.word("function"),t.word(r.name.base);for(const a of r.name.fields)t.punct("."),t.word(a);r.name.method&&(t.punct(":"),t.word(r.name.method)),p(t,r.func,!!r.name.method);return;case"LocalFuncStat":t.word("local"),t.word("function"),t.word(r.name),p(t,r.func,!1);return;case"LocalStat":t.word("local");for(let a=0;a<r.names.length;a+=1)a>0&&t.punct(","),t.word(r.names[a].name),r.names[a].attr&&(t.punct("<"),t.word(r.names[a].attr),t.punct(">"));r.exps&&r.exps.length>0&&(t.punct("="),c(t,r.exps));return;case"AssignStat":c(t,r.vars),t.punct("="),c(t,r.exps);return;case"CallStat":o(t,r.exp);return;case"ReturnStat":t.word("return"),r.exps.length>0&&c(t,r.exps);return}}function p(t,r,a){t.punct("(");const u=a?r.params.filter(n=>n!=="self"):r.params;for(let n=0;n<u.length;n+=1)n>0&&t.punct(","),t.word(u[n]);r.vararg&&(u.length>0&&t.punct(","),t.punct("...")),t.punct(")"),s(t,r.body),t.word("end")}function c(t,r){for(let a=0;a<r.length;a+=1)a>0&&t.punct(","),o(t,r[a])}function o(t,r){switch(r.type){case"NilLiteral":t.word("nil");return;case"BoolLiteral":t.word(r.value?"true":"false");return;case"NumberLiteral":t.num(r.raw);return;case"StringLiteral":t.punct(e(r.value));return;case"VarargExpr":t.punct("...");return;case"NameExpr":t.word(r.name);return;case"UnaryExpr":r.op==="not"?t.word("not"):t.punct(r.op),o(t,r.arg);return;case"BinaryExpr":o(t,r.left),l.has(r.op)?t.word(r.op):t.punct(r.op),o(t,r.right);return;case"FuncExpr":t.word("function"),p(t,r,!1);return;case"TableExpr":t.punct("{");for(let a=0;a<r.fields.length;a+=1)a>0&&t.punct(","),f(t,r.fields[a]);t.punct("}");return;case"IndexExpr":o(t,r.object),t.punct("["),o(t,r.index),t.punct("]");return;case"MemberExpr":o(t,r.object),t.punct("."),t.word(r.field);return;case"CallExpr":o(t,r.callee),t.punct("("),c(t,r.args),t.punct(")");return;case"MethodCallExpr":o(t,r.object),t.punct(":"),t.word(r.method),t.punct("("),c(t,r.args),t.punct(")");return;case"ParenExpr":t.punct("("),o(t,r.exp),t.punct(")");return}}function f(t,r){if(r.kind==="index"){t.punct("["),o(t,r.key),t.punct("]"),t.punct("="),o(t,r.value);return}if(r.kind==="name"){t.word(r.key),t.punct("="),o(t,r.value);return}o(t,r.value)}
@@ -1,2 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export declare function numbersToExpressions(chunk: Chunk, seed: number): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=o;const y=require("./visit");function l(e,a){const t=Math.abs(a)%9+2,r=e-t;if(e<0)return{type:"UnaryExpr",op:"-",arg:l(-e,a+3)};if(e<=2)return{type:"NumberLiteral",raw:String(e),value:e};if(a%3===0){const p=e%7+2,i=Math.floor(e/p),n=e-p*i,u={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(p),value:p},right:{type:"NumberLiteral",raw:String(i),value:i}};return n===0?{type:"ParenExpr",exp:u}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:u,right:{type:"NumberLiteral",raw:String(n),value:n}}}}return{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:{type:"NumberLiteral",raw:String(t),value:t},right:{type:"NumberLiteral",raw:String(r),value:r}}}}function o(e,a){let t=0;(0,y.mapChunk)(e,r=>r.type!=="NumberLiteral"||!Number.isInteger(r.value)||!Number.isSafeInteger(r.value)?r:(t+=1,l(r.value,a+t*17)))}
@@ -1,3 +0,0 @@
1
- export declare const OPCODE_NAMES: readonly ["MOVE", "LOADK", "LOADBOOL", "LOADNIL", "GETGLOBAL", "SETGLOBAL", "GETTABLE", "SETTABLE", "NEWTABLE", "SELF", "ADD", "SUB", "MUL", "DIV", "IDIV", "MOD", "POW", "BAND", "BOR", "BXOR", "SHL", "SHR", "UNM", "BNOT", "NOT", "LEN", "CONCAT", "JMP", "EQ", "LT", "LE", "TEST", "CALL", "RETURN", "FORPREP", "FORLOOP", "TFORCALL", "TFORLOOP", "CLOSURE", "VARARG", "SETLIST", "GETUPVAL", "SETUPVAL", "CLOSE"];
2
- export type OpcodeName = (typeof OPCODE_NAMES)[number];
3
- export declare function shuffleOpcodes(seed: number): Record<OpcodeName, number>;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=t,exports.OPCODE_NAMES=["MOVE","LOADK","LOADBOOL","LOADNIL","GETGLOBAL","SETGLOBAL","GETTABLE","SETTABLE","NEWTABLE","SELF","ADD","SUB","MUL","DIV","IDIV","MOD","POW","BAND","BOR","BXOR","SHL","SHR","UNM","BNOT","NOT","LEN","CONCAT","JMP","EQ","LT","LE","TEST","CALL","RETURN","FORPREP","FORLOOP","TFORCALL","TFORLOOP","CLOSURE","VARARG","SETLIST","GETUPVAL","SETUPVAL","CLOSE"];function t(e){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=e>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),S=E[O];E[O]=E[L],E[L]=S}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
@@ -1,8 +0,0 @@
1
- import type { Chunk, UnaryOp } from "./ast";
2
- export declare class LuaParseError extends Error {
3
- readonly line: number;
4
- readonly column: number;
5
- constructor(message: string, line: number, column: number);
6
- }
7
- export declare function parseLua(source: string): Chunk;
8
- export type { UnaryOp };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,l,p){super(`${b} (${l}:${p})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:p}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let l=0;const p=()=>b[l],u=(e,t)=>{const n=p();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),h=e=>{const t=p();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=p();return n.kind!==e||t!==void 0&&n.value!==t?h(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(l+=1,n)},o=(e,t)=>{if(u(e,t)){const n=p();return l+=1,n}},a=e=>w(e)?(l+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(p().kind==="keyword"&&e.includes(p().value));){if(w("return")){t.push($()),o(";");break}const n=D();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),u("eof")||u(";")||p().kind==="keyword"&&["end","else","elseif","until"].includes(p().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:k()}),D=()=>{if(o(";"))return{type:"EmptyStat"};if(a("break"))return{type:"BreakStat"};if(a("goto"))return{type:"GotoStat",name:s()};if(a("do")){const e=c(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(a("while")){const e=i();r("keyword","do");const t=c(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(a("repeat")){const e=c(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(a("if"))return N();if(a("for"))return U();if(a("function")){const e=I(),t=v(!!e.method);return{type:"FuncStat",name:e,func:t}}if(a("local")){if(a("function")){const e=s(),t=v(!1);return{type:"LocalFuncStat",name:e,func:t}}return M()}if(u("::")){r("::");const e=s();return r("::"),{type:"LabelStat",name:e}}return O()},N=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:c(["elseif","else","end"])});a("elseif");){const d=i();r("keyword","then"),e.push({cond:d,body:c(["elseif","else","end"])})}let n;return a("else")&&(n=c(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},U=()=>{const e=s();if(o("=")){const m=i();r(",");const g=i();let P;o(",")&&(P=i()),r("keyword","do");const Y=c(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:m,end:g,step:P,body:Y}}const t=[e];for(;o(",");)t.push(s());r("keyword","in");const n=k();r("keyword","do");const d=c(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:d}},I=()=>{const e=s(),t=[];for(;o(".");)t.push(s());let n;return o(":")&&(n=s()),{base:e,fields:t,method:n}},v=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!u(")"))if(u("vararg"))r("vararg"),n=!0;else for(t.push(s());o(",");){if(u("vararg")){r("vararg"),n=!0;break}t.push(s())}r(")");const d=c(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:d}},M=()=>{const e=[S()];for(;o(",");)e.push(S());let t;return o("=")&&(t=k()),{type:"LocalStat",names:e,exps:t}},S=()=>{const e=s();if(o("<")){const t=s();return r(">"),t!=="const"&&t!=="close"&&h(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},O=()=>{const e=x();if(u("=")||u(",")){const t=[e];for(;o(",");)t.push(x());r("=");const n=k();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:h("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},k=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>R(),y=(e,t)=>{let n=e();for(;;){const d=p(),m=d.kind==="keyword"?d.value:d.kind;if(!t.includes(m))break;l+=1;const g=e();n={type:"BinaryExpr",op:m,left:n,right:g}}return n},R=()=>y(q,["or"]),q=()=>y(A,["and"]),A=()=>y(_,["<",">","<=",">=","~=","=="]),_=()=>y(G,["|"]),G=()=>y(T,["~"]),T=()=>y(V,["&"]),V=()=>y(B,["<<",">>"]),B=()=>{const e=W();return u("..")?(l+=1,{type:"BinaryExpr",op:"..",left:e,right:B()}):e},W=()=>y(z,["+","-"]),z=()=>y(f,["*","/","//","%"]),f=()=>a("not")?{type:"UnaryExpr",op:"not",arg:f()}:o("#")?{type:"UnaryExpr",op:"#",arg:f()}:o("-")?{type:"UnaryExpr",op:"-",arg:f()}:o("~")?{type:"UnaryExpr",op:"~",arg:f()}:H(),H=()=>{const e=J();return u("^")?(l+=1,{type:"BinaryExpr",op:"^",left:e,right:f()}):e},J=()=>{if(a("nil"))return{type:"NilLiteral"};if(a("true"))return{type:"BoolLiteral",value:!0};if(a("false"))return{type:"BoolLiteral",value:!1};if(u("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(u("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(a("function"))return v(!1);if(u("{")){let e=C();return e=F(e),e}return x()},F=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:s()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=s(),d=L();t={type:"MethodCallExpr",object:t,method:n,args:d};continue}if(u("(")||u("{")||u("string")){t={type:"CallExpr",callee:t,args:L()};continue}break}return t},x=()=>F(K()),K=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return u("name")?{type:"NameExpr",name:s()}:h("\u671F\u671B\u8868\u8FBE\u5F0F")},L=()=>{if(u("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(u("{"))return[C()];if(r("("),o(")"))return[];const e=k();return r(")"),e},C=()=>{r("{");const e=[];for(;!u("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(u("name")&&b[l+1]?.kind==="="){const e=s();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=c([]);return r("eof"),{type:"Chunk",body:X.body}}
@@ -1,3 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export declare function shortName(n: number): string;
3
- export declare function renameLocals(chunk: Chunk): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=o,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function o(r){let e=r,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function c(r){let e=0;const t=new Set;(0,d.collectAndRename)(r,(a,s)=>{if(a.newName!==a.original)return;let n=o(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=o(e),e+=1;a.newName=n,t.add(n),s.add(n)})}
@@ -1,5 +0,0 @@
1
- export declare const luaKeywords: Set<string>;
2
- export declare const hostLuaModuleNames: Set<string>;
3
- export declare const hostLuaGlobals: Set<string>;
4
- export declare const luaStdlibNames: Set<string>;
5
- export declare function isReservedGlobal(name: string): boolean;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.luaStdlibNames=exports.hostLuaGlobals=exports.hostLuaModuleNames=exports.luaKeywords=void 0,exports.isReservedGlobal=t,exports.luaKeywords=new Set(["and","break","do","else","elseif","end","false","for","function","goto","if","in","local","nil","not","or","repeat","return","then","true","until","while"]),exports.hostLuaModuleNames=new Set(["action","appleocr","cloud","config","cryptoUtils","cv","device","dotocr","file","hid","hotupdate","http","image","ime","logger","media","mysql","netcard","node","paddleocr","pip","system","tomatoocr","tts","ui","utils","yolo","yolocls"]),exports.hostLuaGlobals=new Set(["IsDebug","RunMode","Platform","AppVersion","AppBuildNumber","AppName","AppBundleId","PackageJson","TakeMeToFront","RestartScript","Exit","SetStopCallback","SetExceptionCallback","Sleep","Time","ToJsonString","StartThread","StopThread","ShouldInterruptThread","SetAgentFastMode","GetAgentFastMode","SetAgentTouchMode","GetAgentTouchMode","SetCpuAutoThrottle","GetCpuAutoThrottle","SetCpuThrottleDelay","GetCpuThrottleDelay","logd","logi","logw","loge"]),exports.luaStdlibNames=new Set(["_G","_ENV","_VERSION","assert","collectgarbage","dofile","error","getmetatable","ipairs","load","loadfile","next","pairs","pcall","print","rawequal","rawget","rawlen","rawset","require","select","setmetatable","tonumber","tostring","type","warn","xpcall","coroutine","debug","io","math","os","package","string","table","utf8"]);function t(e){return exports.luaKeywords.has(e)||exports.hostLuaModuleNames.has(e)||exports.hostLuaGlobals.has(e)||exports.luaStdlibNames.has(e)}
@@ -1,11 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export interface Binding {
3
- original: string;
4
- newName: string;
5
- }
6
- export interface Scope {
7
- parent?: Scope;
8
- locals: Map<string, Binding>;
9
- }
10
- export declare function resolveLocal(scope: Scope, name: string): Binding | undefined;
11
- export declare function collectAndRename(chunk: Chunk, rename: (binding: Binding, used: Set<string>) => void): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(e,o){let n=e;for(;n;){const a=n.locals.get(o);if(a)return a;n=n.parent}}function s(e){return{parent:e,locals:new Map}}function f(e,o){const n=e.locals.get(o);if(n)return n;const a={original:o,newName:o};return e.locals.set(o,a),a}function x(e,o){const n=new Set,a={locals:new Map};d(e.body,a,n,o)}function u(e,o,n,a){d(e.body,o,n,a)}function d(e,o,n,a){for(const c of e)b(c,o,n,a)}function m(e,o,n,a){const c=s(o),r=e.params.slice();for(let l=0;l<r.length;l+=1){const p=f(c,r[l]);a(p,n),e.params[l]=p.newName}u(e.body,c,n,a)}function b(e,o,n,a){switch(e.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":u(e.body,s(o),n,a);return;case"WhileStat":t(e.cond,o,n,a),u(e.body,s(o),n,a);return;case"RepeatStat":{const c=s(o);u(e.body,c,n,a),t(e.cond,c,n,a);return}case"IfStat":for(const c of e.clauses)t(c.cond,o,n,a),u(c.body,s(o),n,a);e.elseBody&&u(e.elseBody,s(o),n,a);return;case"ForNumStat":{t(e.start,o,n,a),t(e.end,o,n,a),e.step&&t(e.step,o,n,a);const c=s(o),r=f(c,e.name);a(r,n),e.name=r.newName,u(e.body,c,n,a);return}case"ForInStat":{for(const r of e.exps)t(r,o,n,a);const c=s(o);for(let r=0;r<e.names.length;r+=1){const l=f(c,e.names[r]);a(l,n),e.names[r]=l.newName}u(e.body,c,n,a);return}case"FuncStat":{const c=i(o,e.name.base);c&&(e.name.base=c.newName),m(e.func,o,n,a);return}case"LocalFuncStat":{const c=f(o,e.name);a(c,n),e.name=c.newName,m(e.func,o,n,a);return}case"LocalStat":if(e.exps)for(const c of e.exps)t(c,o,n,a);for(let c=0;c<e.names.length;c+=1){const r=f(o,e.names[c].name);a(r,n),e.names[c].name=r.newName}return;case"AssignStat":for(const c of e.vars)t(c,o,n,a);for(const c of e.exps)t(c,o,n,a);return;case"CallStat":t(e.exp,o,n,a);return;case"ReturnStat":for(const c of e.exps)t(c,o,n,a);return}}function t(e,o,n,a){switch(e.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const c=i(o,e.name);c&&(e.name=c.newName);return}case"UnaryExpr":t(e.arg,o,n,a);return;case"BinaryExpr":t(e.left,o,n,a),t(e.right,o,n,a);return;case"FuncExpr":m(e,o,n,a);return;case"TableExpr":for(const c of e.fields)c.kind==="index"&&t(c.key,o,n,a),t(c.value,o,n,a);return;case"IndexExpr":t(e.object,o,n,a),t(e.index,o,n,a);return;case"MemberExpr":t(e.object,o,n,a);return;case"CallExpr":t(e.callee,o,n,a);for(const c of e.args)t(c,o,n,a);return;case"MethodCallExpr":t(e.object,o,n,a);for(const c of e.args)t(c,o,n,a);return;case"ParenExpr":t(e.exp,o,n,a);return}}
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const p=require("child_process"),c=require("./cipher"),F=require("./flatten"),a=require("./minify"),o=require("./parser"),r=require("./index");let s=0;function e(u,n){u?console.log(`\u2705 ${n}`):(s+=1,console.error(`\u274C ${n}`))}const l=`
2
- local helper = require("device")
3
- local wait = 10
4
- Sleep(wait)
5
- helper.tap(1, 2)
6
- local function add(a, b)
7
- return a + b
8
- end
9
- if add(1, 2) == 3 then
10
- logi("ok")
11
- end
12
- `;function E(){const u=(0,c.createFoldMixParams)(42),n=["device","\u4F60\u597D","Sleep",""];for(const t of n){if(t.length===0)continue;const i=(0,c.foldEncrypt)(t,u,99),d=(0,c.foldDecrypt)(i,u,99),D=Buffer.from(t,"utf8").toString("latin1");e(d===D,`FoldMix \u5F80\u8FD4 ${t}`),e(!i.includes("device")||t!=="device","FoldMix \u8F7D\u8377\u4E0D\u542B\u660E\u6587 device")}}function C(){const u=(0,o.parseLua)(l),n=(0,a.minifyLua)(u),t=(0,o.parseLua)(n);e(t.body.length>0,"\u89E3\u6790\u5F80\u8FD4\u5F97\u5230\u975E\u7A7A AST"),e(n.includes("Sleep"),"Minify \u53D1\u5C04\u4FDD\u7559 Sleep")}function S(){const u=(0,r.obfuscateLua)(l,"Minify");e(u.includes("Sleep"),"Minify \u4E0D\u6539 Sleep"),e(u.includes("require"),"Minify \u4FDD\u7559 require"),e(!u.includes('"device"'),"Minify \u4E0D\u4FDD\u7559\u660E\u6587 device \u5B57\u9762\u91CF"),e(u.includes("\\100\\101\\118\\105\\099\\101"),"Minify \u7528\u5341\u8FDB\u5236\u8F6C\u4E49\u4FDD\u7559 device"),e(!/\bwait\b/.test(u),"Minify \u91CD\u547D\u540D\u5C40\u90E8 wait"),(0,o.parseLua)(u)}function _(){const u=(0,o.parseLua)(`local n=0
13
- for i=1,3 do n=n+i end
14
- if n==6 then Sleep(n) else Sleep(0) end`);(0,F.flattenControlFlow)(u,1);const n=(0,a.minifyLua)(u);e(n.includes("while"),"\u5C55\u5E73\u540E\u662F\u72B6\u6001\u673A\u5FAA\u73AF"),e(!/for\s+i\s*=\s*1\s*,\s*3/.test(n),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F for i=1,3"),e(!/if\s+n\s*==\s*6/.test(n),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F if n==6")}function b(){const u=(0,r.obfuscateLua)(l,"Weak");e(u.includes("function"),"Weak \u542B Vmify \u89E3\u91CA\u5668"),e(!u.includes("Sleep(wait)"),"Weak \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(wait)"),e(!u.includes("helper.tap"),"Weak \u4E0D\u518D\u4FDD\u7559 helper.tap \u6E90\u7801\u7ED3\u6784"),e(!/\bhelper\b/.test(u),"Weak \u6539\u6389\u5C40\u90E8 helper"),(0,o.parseLua)(u),e(!0,"Weak \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function m(){const u=(0,r.obfuscateLua)(l,"Medium");e(u.includes("function"),"Medium \u542B\u865A\u62DF\u673A"),e(!u.includes('logi("ok")'),"Medium \u52A0\u5BC6\u7528\u6237\u5B57\u7B26\u4E32"),e(!u.includes("Tamper Detected!")||u.includes("pcall"),"Medium \u542B\u5B8C\u6574\u6027\u68C0\u67E5\u6216\u5DF2\u7F16\u8FDB VM"),(0,o.parseLua)(u),e(!0,"Medium \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function g(){const u=(0,r.obfuscateLua)('local d=require("device"); Sleep(1)',"Strong");e(u.includes("function"),"Strong \u542B\u89E3\u91CA\u5668\u51FD\u6570"),e(!u.includes("Sleep(1)"),"Strong \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(1) \u8C03\u7528"),(0,o.parseLua)(u),e(!0,"Strong \u4EA7\u7269\u662F\u5408\u6CD5 Lua")}function y(){const u=(0,r.obfuscateLua)(`
15
- local x <const> = 1
16
- local y = 10 // 3
17
- local z = y & 1 | 2
18
- goto skip
19
- ::skip::
20
- for i = 1, 2 do
21
- break
22
- end
23
- `,"Minify");(0,o.parseLua)(u),e(u.includes("<const>"),"Minify \u4FDD\u7559 <const>"),e(u.includes("//"),"Minify \u4FDD\u7559\u6574\u9664")}function M(u){const n=["/opt/homebrew/bin/lua","lua5.4","lua54","lua"];for(const t of n){const i=(0,p.spawnSync)(t,["-e",u],{encoding:"utf8"});if(!i.error)return{ok:i.status===0,out:(i.stdout||"")+(i.stderr||"")}}return{ok:!1,out:""}}function f(u){const n=(0,r.obfuscateLua)('local m=require("device"); Sleep(3)',u),t=`
24
- local env = setmetatable({
25
- require = function(n) _G.__req = n; return {} end,
26
- Sleep = function(ms) _G.__slept = ms end,
27
- string = string, table = table, math = math,
28
- getmetatable = getmetatable, pcall = pcall, error = error,
29
- }, {__index = _G})
30
- env._ENV = env
31
- local fn, err = load(${JSON.stringify(n)}, "obf", "t", env)
32
- if not fn then error(err) end
33
- fn()
34
- if _G.__req ~= "device" then error("require name "..tostring(_G.__req)) end
35
- if _G.__slept ~= 3 then error("Sleep "..tostring(_G.__slept)) end
36
- print("${u}-ok")
37
- `,i=M(t);if(!i.out&&i.ok===!1){console.log(`\u2139\uFE0F \u672C\u673A\u65E0 lua \u89E3\u91CA\u5668\uFF0C\u8DF3\u8FC7 ${u} \u8FD0\u884C\u65F6\u68C0\u67E5`);return}e(i.ok&&i.out.includes(`${u}-ok`),`${u} \u8FD0\u884C\u65F6\u8FD8\u539F require/Sleep: ${i.out.trim()}`)}E(),C(),S(),_(),b(),m(),g(),y(),f("Medium"),f("Strong"),s>0&&(console.error(`
38
- \u81EA\u68C0\u5931\u8D25 ${s} \u9879`),process.exit(1)),console.log(`
39
- \u81EA\u68C0\u901A\u8FC7`);
@@ -1,2 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- export declare function splitStrings(chunk: Chunk, seed: number): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=o;const u=require("./visit");function a(e){let r={type:"StringLiteral",value:e[0]};for(let n=1;n<e.length;n+=1)r={type:"BinaryExpr",op:"..",left:r,right:{type:"StringLiteral",value:e[n]}};return{type:"ParenExpr",exp:r}}function p(e,r){if(e.length<4)return[e];const n=r%2+2,t=Math.max(1,Math.ceil(e.length/n)),l=[];for(let i=0;i<e.length;i+=t)l.push(e.slice(i,i+t));return l}function o(e,r){let n=0;(0,u.mapChunk)(e,t=>{if(t.type!=="StringLiteral"||t.encoded||t.value.length<4)return t;n+=1;const l=p(t.value,r+n);return l.length<2?t:a(l)})}
@@ -1,4 +0,0 @@
1
- import type { Chunk } from "./ast";
2
- import { createFoldMixParams, foldDecrypt, foldEncrypt, type FoldMixParams } from "./cipher";
3
- export declare function encryptStrings(chunk: Chunk, seed: number): void;
4
- export { createFoldMixParams, foldDecrypt, foldEncrypt, type FoldMixParams, };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const u=require("./parser"),i=require("./visit"),l="__d";function d(t,o){let e=2166136261^o;for(let r=0;r<t.length;r+=1)e=Math.imul(e^t.charCodeAt(r),16777619);return e>>>0||1}function p(t,o,e){const r=(0,a.foldEncrypt)(t,o,e);return{type:"CallExpr",callee:{type:"NameExpr",name:l},args:[{type:"StringLiteral",value:r,encoded:!0},{type:"NumberLiteral",raw:String(e),value:e}]}}function y(t,o){const e=(0,a.createFoldMixParams)(o);let r=0;(0,i.mapChunk)(t,n=>n.type!=="StringLiteral"||n.encoded||n.value.length===0?n:(r+=1,p(n.value,e,d(n.value,r))));const c=(0,u.parseLua)((0,a.emitFoldDecoderLua)(e,l));t.body.unshift(...c.body)}
@@ -1,5 +0,0 @@
1
- import type { Chunk, Expression, FuncExpr, Statement } from "./ast";
2
- export declare function mapExp(exp: Expression, fn: (e: Expression) => Expression): Expression;
3
- export declare function mapFunc(fnExpr: FuncExpr, fn: (e: Expression) => Expression): void;
4
- export declare function mapStats(stats: Statement[], fn: (e: Expression) => Expression): void;
5
- export declare function mapChunk(chunk: Chunk, fn: (e: Expression) => Expression): void;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=s,exports.mapFunc=b,exports.mapStats=o,exports.mapChunk=p;function s(t,e){switch(t.type){case"UnaryExpr":t.arg=s(t.arg,e);break;case"BinaryExpr":t.left=s(t.left,e),t.right=s(t.right,e);break;case"FuncExpr":b(t,e);break;case"TableExpr":for(const a of t.fields)a.kind==="index"&&(a.key=s(a.key,e)),a.value=s(a.value,e);break;case"IndexExpr":t.object=s(t.object,e),t.index=s(t.index,e);break;case"MemberExpr":t.object=s(t.object,e);break;case"CallExpr":t.callee=s(t.callee,e),t.args=t.args.map(a=>s(a,e));break;case"MethodCallExpr":t.object=s(t.object,e),t.args=t.args.map(a=>s(a,e));break;case"ParenExpr":t.exp=s(t.exp,e);break;default:break}return e(t)}function b(t,e){o(t.body.body,e)}function o(t,e){for(const a of t)switch(a.type){case"DoStat":o(a.body.body,e);break;case"WhileStat":a.cond=s(a.cond,e),o(a.body.body,e);break;case"RepeatStat":o(a.body.body,e),a.cond=s(a.cond,e);break;case"IfStat":for(const c of a.clauses)c.cond=s(c.cond,e),o(c.body.body,e);a.elseBody&&o(a.elseBody.body,e);break;case"ForNumStat":a.start=s(a.start,e),a.end=s(a.end,e),a.step&&(a.step=s(a.step,e)),o(a.body.body,e);break;case"ForInStat":a.exps=a.exps.map(c=>s(c,e)),o(a.body.body,e);break;case"FuncStat":b(a.func,e);break;case"LocalFuncStat":b(a.func,e);break;case"LocalStat":a.exps&&(a.exps=a.exps.map(c=>s(c,e)));break;case"AssignStat":a.vars=a.vars.map(c=>s(c,e)),a.exps=a.exps.map(c=>s(c,e));break;case"CallStat":a.exp=s(a.exp,e);break;case"ReturnStat":a.exps=a.exps.map(c=>s(c,e));break;default:break}}function p(t,e){o(t.body,e)}
@@ -1,2 +0,0 @@
1
- import type { Proto } from "./compiler";
2
- export declare function emitVm(root: Proto): string;
@@ -1,281 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.emitVm=j;const p=require("./cipher"),d=require("./minify"),s=require("./opcodes");function h(e){let n=2166136261^e.code.length;return n=Math.imul(n,16777619)^e.consts.length,n>>>0}function b(e,n,l){if(e.t==="nil")return"nil";if(e.t==="bool")return e.v?"true":"false";if(e.t==="num")return e.raw;const a=(0,p.foldEncrypt)(e.v,n,l);return`D(${(0,d.escapeLuaString)(a)},${l})`}function u(e,n,l,a){const i=e.code.map((t,o)=>{const r=e.ops[o];return`{${n[r]},${t[1]},${t[2]},${t[3]}}`}).join(","),c=e.consts.map((t,o)=>b(t,l,a+o*131>>>0||1)).join(","),R=e.protos.map((t,o)=>u(t,n,l,a+(o+1)*4099>>>0)).join(","),f=e.upvals.map(t=>`{${t.inStack?1:0},${t.index}}`).join(",");return`{p={${i}},k={${c}},t={${R}},u={${f}},n=${e.numparams},v=${e.isVararg?"true":"false"}}`}function j(e){const n=h(e)||1,l=(0,s.shuffleOpcodes)(n),a=(0,p.createFoldMixParams)(n),i=s.OPCODE_NAMES.join(","),c=s.OPCODE_NAMES.map(f=>String(l[f])).join(","),R=u(e,l,a,n);return`(function()
2
- ${(0,p.emitFoldDecoderLua)(a,"D")}
3
- local ${i}=${c}
4
- local function G(u)
5
- if u.R then
6
- return u.R[u.i]
7
- end
8
- return u.v
9
- end
10
- local function S(u,x)
11
- if u.R then
12
- u.R[u.i]=x
13
- else
14
- u.v=x
15
- end
16
- end
17
- local function C(u)
18
- if u.R then
19
- u.v=u.R[u.i]
20
- u.R=nil
21
- u.i=nil
22
- end
23
- end
24
- local function V(P,U,A)
25
- local R={}
26
- local K=P.k
27
- local code=P.p
28
- local top=0
29
- local pc=1
30
- local open={}
31
- for i=1,P.n do
32
- R[i]=A[i]
33
- end
34
- local VA={}
35
- if P.v then
36
- for i=P.n+1,A.n do
37
- VA[#VA+1]=A[i]
38
- end
39
- end
40
- local function rk(x)
41
- if x<0 then
42
- return K[-x]
43
- end
44
- return R[x]
45
- end
46
- while true do
47
- local i=code[pc]
48
- if not i then
49
- return
50
- end
51
- local op=i[1]
52
- local a=i[2]
53
- local b=i[3]
54
- local c=i[4]
55
- pc=pc+1
56
- if op==MOVE then
57
- R[a]=R[b]
58
- elseif op==LOADK then
59
- R[a]=K[b]
60
- elseif op==LOADBOOL then
61
- R[a]=b~=0
62
- elseif op==LOADNIL then
63
- R[a]=nil
64
- elseif op==GETGLOBAL then
65
- R[a]=_ENV[K[b]]
66
- elseif op==SETGLOBAL then
67
- _ENV[K[b]]=R[a]
68
- elseif op==GETTABLE then
69
- R[a]=R[b][rk(c)]
70
- elseif op==SETTABLE then
71
- R[a][rk(b)]=rk(c)
72
- elseif op==NEWTABLE then
73
- R[a]={}
74
- elseif op==SELF then
75
- R[a+1]=R[b]
76
- R[a]=R[b][rk(c)]
77
- elseif op==ADD then
78
- R[a]=R[b]+R[c]
79
- elseif op==SUB then
80
- R[a]=R[b]-R[c]
81
- elseif op==MUL then
82
- R[a]=R[b]*R[c]
83
- elseif op==DIV then
84
- R[a]=R[b]/R[c]
85
- elseif op==IDIV then
86
- R[a]=R[b]//R[c]
87
- elseif op==MOD then
88
- R[a]=R[b]%R[c]
89
- elseif op==POW then
90
- R[a]=R[b]^R[c]
91
- elseif op==BAND then
92
- R[a]=R[b]&R[c]
93
- elseif op==BOR then
94
- R[a]=R[b]|R[c]
95
- elseif op==BXOR then
96
- R[a]=R[b]~R[c]
97
- elseif op==SHL then
98
- R[a]=R[b]<<R[c]
99
- elseif op==SHR then
100
- R[a]=R[b]>>R[c]
101
- elseif op==UNM then
102
- R[a]=-R[b]
103
- elseif op==BNOT then
104
- R[a]=~R[b]
105
- elseif op==NOT then
106
- R[a]=not R[b]
107
- elseif op==LEN then
108
- R[a]=#R[b]
109
- elseif op==CONCAT then
110
- R[a]=R[b]..R[c]
111
- elseif op==JMP then
112
- pc=pc+b
113
- elseif op==EQ then
114
- local eq=R[a]==R[b]
115
- local want=c==0
116
- if eq==want then
117
- pc=pc+1
118
- end
119
- elseif op==LT then
120
- local lt=R[a]<R[b]
121
- local want=c==0
122
- if lt==want then
123
- pc=pc+1
124
- end
125
- elseif op==LE then
126
- local le=R[a]<=R[b]
127
- local want=c==0
128
- if le==want then
129
- pc=pc+1
130
- end
131
- elseif op==TEST then
132
- -- C=0\uFF1A\u771F\u5219\u8DF3\u8FC7 JMP\uFF1BC=1\uFF1A\u5047\u5219\u8DF3\u8FC7\uFF08or\uFF09\u3002\u4E0D\u7528 and/or\uFF0C\u65B9\u4FBF\u518D\u7F16\u8BD1\u3002
133
- local take=false
134
- if c==0 then
135
- if R[a] then
136
- take=true
137
- end
138
- else
139
- if not R[a] then
140
- take=true
141
- end
142
- end
143
- if take then
144
- pc=pc+1
145
- end
146
- elseif op==CALL then
147
- local n=b
148
- local args={}
149
- local an=n
150
- if n<0 then
151
- an=0
152
- local last=top
153
- if last<a then
154
- last=a
155
- end
156
- for j=a+1,last do
157
- an=an+1
158
- args[an]=R[j]
159
- end
160
- else
161
- for j=1,n do
162
- args[j]=R[a+j]
163
- end
164
- end
165
- local rets=table.pack(R[a](table.unpack(args,1,an)))
166
- if c==0 then
167
- elseif c<0 then
168
- for j=1,rets.n do
169
- R[a+j-1]=rets[j]
170
- end
171
- top=a+rets.n-1
172
- else
173
- for j=1,c do
174
- R[a+j-1]=rets[j]
175
- end
176
- top=a+c-1
177
- end
178
- elseif op==RETURN then
179
- for _,u in pairs(open) do
180
- C(u)
181
- end
182
- if b==0 then
183
- return
184
- end
185
- if b<0 then
186
- return table.unpack(R,a,top)
187
- end
188
- return table.unpack(R,a,a+b-1)
189
- elseif op==FORPREP then
190
- R[a]=R[a]-R[a+2]
191
- pc=pc+b
192
- elseif op==FORLOOP then
193
- R[a]=R[a]+R[a+2]
194
- local idx=R[a]
195
- local lim=R[a+1]
196
- local step=R[a+2]
197
- local cont=false
198
- if step>=0 then
199
- if idx<=lim then
200
- cont=true
201
- end
202
- else
203
- if idx>=lim then
204
- cont=true
205
- end
206
- end
207
- if cont then
208
- R[a+3]=idx
209
- pc=pc+b
210
- end
211
- elseif op==TFORCALL then
212
- local rets=table.pack(R[a](R[a+1],R[a+2]))
213
- for j=1,b do
214
- R[a+2+j]=rets[j]
215
- end
216
- elseif op==TFORLOOP then
217
- if R[a+3]~=nil then
218
- R[a+2]=R[a+3]
219
- else
220
- pc=pc+b
221
- end
222
- elseif op==CLOSURE then
223
- local Q=P.t[b]
224
- local nu={}
225
- for j=1,#Q.u do
226
- local sp=Q.u[j]
227
- if sp[1]==1 then
228
- local rg=sp[2]
229
- if not open[rg] then
230
- open[rg]={R=R,i=rg}
231
- end
232
- nu[j]=open[rg]
233
- else
234
- nu[j]=U[sp[2]]
235
- end
236
- end
237
- R[a]=function(...)
238
- return V(Q,nu,table.pack(...))
239
- end
240
- elseif op==VARARG then
241
- if b<0 then
242
- for j=1,#VA do
243
- R[a+j-1]=VA[j]
244
- end
245
- top=a+#VA-1
246
- else
247
- for j=1,b do
248
- R[a+j-1]=VA[j]
249
- end
250
- end
251
- elseif op==SETLIST then
252
- for j=1,c do
253
- R[a][j]=R[b+j-1]
254
- end
255
- elseif op==GETUPVAL then
256
- R[a]=G(U[b])
257
- elseif op==SETUPVAL then
258
- S(U[b],R[a])
259
- elseif op==CLOSE then
260
- if open[a] then
261
- C(open[a])
262
- open[a]=nil
263
- end
264
- local v=R[a]
265
- if type(v)=="table" then
266
- local mt=getmetatable(v)
267
- local cl=v.close
268
- if not cl then
269
- if mt then
270
- cl=mt.__close
271
- end
272
- end
273
- if cl then
274
- pcall(cl,v)
275
- end
276
- end
277
- end
278
- end
279
- end
280
- V(${R},{},table.pack())
281
- end)()`}