ms-vite-plugin 1.4.59 → 1.4.60

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 (80) hide show
  1. package/dist/luaBundle.js +1 -1
  2. package/dist/luaObfuscator/addVararg.d.ts +2 -0
  3. package/dist/luaObfuscator/addVararg.js +1 -0
  4. package/dist/luaObfuscator/antiTamper.d.ts +2 -0
  5. package/dist/luaObfuscator/antiTamper.js +26 -0
  6. package/dist/luaObfuscator/ast.d.ts +191 -0
  7. package/dist/luaObfuscator/ast.js +1 -0
  8. package/dist/luaObfuscator/cipher.d.ts +10 -0
  9. package/dist/luaObfuscator/cipher.js +28 -0
  10. package/dist/luaObfuscator/compiler.d.ts +31 -0
  11. package/dist/luaObfuscator/compiler.js +1 -0
  12. package/dist/luaObfuscator/constantArray.d.ts +5 -0
  13. package/dist/luaObfuscator/constantArray.js +1 -0
  14. package/dist/luaObfuscator/flatten.d.ts +2 -0
  15. package/dist/luaObfuscator/flatten.js +1 -0
  16. package/dist/luaObfuscator/index.d.ts +6 -0
  17. package/dist/luaObfuscator/index.js +1 -0
  18. package/dist/luaObfuscator/lexer.d.ts +14 -0
  19. package/dist/luaObfuscator/lexer.js +10 -0
  20. package/dist/luaObfuscator/minify.d.ts +3 -0
  21. package/dist/luaObfuscator/minify.js +1 -0
  22. package/dist/luaObfuscator/numbers.d.ts +2 -0
  23. package/dist/luaObfuscator/numbers.js +1 -0
  24. package/dist/luaObfuscator/opcodes.d.ts +3 -0
  25. package/dist/luaObfuscator/opcodes.js +1 -0
  26. package/dist/luaObfuscator/parser.d.ts +8 -0
  27. package/dist/luaObfuscator/parser.js +1 -0
  28. package/dist/luaObfuscator/rename.d.ts +3 -0
  29. package/dist/luaObfuscator/rename.js +1 -0
  30. package/dist/luaObfuscator/reserved.d.ts +5 -0
  31. package/dist/luaObfuscator/reserved.js +1 -0
  32. package/dist/luaObfuscator/scope.d.ts +11 -0
  33. package/dist/luaObfuscator/scope.js +1 -0
  34. package/dist/luaObfuscator/selftest.d.ts +1 -0
  35. package/dist/luaObfuscator/selftest.js +39 -0
  36. package/dist/luaObfuscator/splitStrings.d.ts +2 -0
  37. package/dist/luaObfuscator/splitStrings.js +1 -0
  38. package/dist/luaObfuscator/strings.d.ts +4 -0
  39. package/dist/luaObfuscator/strings.js +1 -0
  40. package/dist/luaObfuscator/visit.d.ts +5 -0
  41. package/dist/luaObfuscator/visit.js +1 -0
  42. package/dist/luaObfuscator/vmEmit.d.ts +2 -0
  43. package/dist/luaObfuscator/vmEmit.js +281 -0
  44. package/dist/luaObfuscator/wrapInFunction.d.ts +2 -0
  45. package/dist/luaObfuscator/wrapInFunction.js +1 -0
  46. package/docs/AGENTS.md +1 -1
  47. package/docs/SKILL.md +1 -1
  48. package/docs/apilua/action.md +2 -27
  49. package/docs/apilua/appleocr.md +2 -6
  50. package/docs/apilua/cloud.md +2 -6
  51. package/docs/apilua/config.md +2 -6
  52. package/docs/apilua/cryptoUtils.md +2 -7
  53. package/docs/apilua/device.md +2 -19
  54. package/docs/apilua/dotocr.md +2 -5
  55. package/docs/apilua/file.md +2 -17
  56. package/docs/apilua/global.md +1 -1
  57. package/docs/apilua/hid.md +2 -44
  58. package/docs/apilua/hotUpdate.md +2 -3
  59. package/docs/apilua/http.md +2 -7
  60. package/docs/apilua/image.md +2 -20
  61. package/docs/apilua/ime.md +2 -10
  62. package/docs/apilua/logger.md +3 -9
  63. package/docs/apilua/media.md +2 -9
  64. package/docs/apilua/mysql.md +2 -10
  65. package/docs/apilua/netCard.md +2 -6
  66. package/docs/apilua/node.md +2 -3
  67. package/docs/apilua/opencv.md +1 -27
  68. package/docs/apilua/paddleocr.md +2 -7
  69. package/docs/apilua/pip.md +2 -12
  70. package/docs/apilua/system.md +2 -23
  71. package/docs/apilua/tomatoocr.md +2 -16
  72. package/docs/apilua/tts.md +2 -9
  73. package/docs/apilua/ui.md +3 -9
  74. package/docs/apilua/utils.md +2 -9
  75. package/docs/apilua/yolo.md +2 -4
  76. package/docs/apilua/yolocls.md +2 -5
  77. package/docs/mcp-agent-description.md +1 -1
  78. package/docs/quick/vscode/createProject.md +1 -1
  79. package/docs/quick/vscode/packProject.md +1 -1
  80. package/package.json +1 -1
package/dist/luaBundle.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var b=exports&&exports.__createBinding||(Object.create?(function(t,e,i,n){n===void 0&&(n=i);var a=Object.getOwnPropertyDescriptor(e,i);(!a||("get"in a?!e.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,n,a)}):(function(t,e,i,n){n===void 0&&(n=i),t[n]=e[i]})),_=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),m=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(i){var n=[];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(n[n.length]=a);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var i={};if(e!=null)for(var n=t(e),a=0;a<n.length;a++)n[a]!=="default"&&b(i,e,n[a]);return _(i,e),i}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.bundleLuaScripts=v;const c=m(require("fs-extra")),d=m(require("path")),w=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"]),F=new Set(["coroutine","debug","io","math","os","package","string","table","utf8"]);async function v(t){const e=d.join(t,"main.lua");await c.pathExists(e)||(console.error("\u274C \u672A\u627E\u5230 scripts/main.lua\uFF0C\u65E0\u6CD5\u5408\u5E76 Lua"),process.exit(1));const i=await j(t),n=new Map;for(const o of i){const u=p(t,o),l=h(u);if(!l)continue;if(w.has(l)||F.has(l)){const g=w.has(l)?"\u5BBF\u4E3B":"\u6807\u51C6\u5E93";console.warn(`\u26A0\uFE0F \u8DF3\u8FC7 ${u}\uFF1A\u6A21\u5757\u540D ${l} \u4E0E${g} require \u51B2\u7A81\uFF0C\u8FD0\u884C\u65F6\u672C\u6765\u4E5F\u4E0D\u4F1A\u52A0\u8F7D\u8BE5\u6587\u4EF6`);continue}if(n.has(l))continue;let f=await c.readFile(o,"utf8");f=y(f),n.set(l,{rel:u,source:f})}const a=y(await c.readFile(e,"utf8"));if(n.size===0)return console.log("\u2139\uFE0F Lua \u4EC5\u6709 main.lua\uFF0C\u65E0\u9700\u5408\u5E76"),0;const r=[];r.push("-- KuaiJS Lua bundle: package.preload + main.lua");const s=[...n.keys()].sort((o,u)=>o.localeCompare(u));for(const o of s){const u=n.get(o);r.push(`package.preload[${O(o)}] = function(...)`),r.push(u.source.replace(/\s+$/,"")),r.push("end")}r.push(a.replace(/^\uFEFF/,"")),await c.writeFile(e,`${r.join(`
1
+ "use strict";var b=exports&&exports.__createBinding||(Object.create?(function(t,e,i,n){n===void 0&&(n=i);var a=Object.getOwnPropertyDescriptor(e,i);(!a||("get"in a?!e.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,n,a)}):(function(t,e,i,n){n===void 0&&(n=i),t[n]=e[i]})),_=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),m=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(i){var n=[];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(n[n.length]=a);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var i={};if(e!=null)for(var n=t(e),a=0;a<n.length;a++)n[a]!=="default"&&b(i,e,n[a]);return _(i,e),i}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.bundleLuaScripts=v;const c=m(require("fs-extra")),d=m(require("path")),w=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"]),F=new Set(["coroutine","debug","io","math","os","package","string","table","utf8"]);async function v(t){const e=d.join(t,"main.lua");await c.pathExists(e)||(console.error("\u274C \u672A\u627E\u5230 scripts/main.lua\uFF0C\u65E0\u6CD5\u5408\u5E76 Lua"),process.exit(1));const i=await j(t),n=new Map;for(const o of i){const u=p(t,o),l=h(u);if(!l)continue;if(w.has(l)||F.has(l)){const g=w.has(l)?"\u5BBF\u4E3B":"\u6807\u51C6\u5E93";console.warn(`\u26A0\uFE0F \u8DF3\u8FC7 ${u}\uFF1A\u6A21\u5757\u540D ${l} \u4E0E${g}\u5168\u5C40\u540D\u51B2\u7A81\uFF0C\u4E0D\u8981\u5360\u7528\u5BBF\u4E3B\u6216\u6807\u51C6\u5E93\u540D\u79F0`);continue}if(n.has(l))continue;let f=await c.readFile(o,"utf8");f=y(f),n.set(l,{rel:u,source:f})}const a=y(await c.readFile(e,"utf8"));if(n.size===0)return console.log("\u2139\uFE0F Lua \u4EC5\u6709 main.lua\uFF0C\u65E0\u9700\u5408\u5E76"),0;const r=[];r.push("-- KuaiJS Lua bundle: package.preload + main.lua");const s=[...n.keys()].sort((o,u)=>o.localeCompare(u));for(const o of s){const u=n.get(o);r.push(`package.preload[${O(o)}] = function(...)`),r.push(u.source.replace(/\s+$/,"")),r.push("end")}r.push(a.replace(/^\uFEFF/,"")),await c.writeFile(e,`${r.join(`
2
2
  `)}
3
3
  `,"utf8");for(const o of i)p(t,o)!=="main.lua"&&await c.remove(o);return await $(t),console.log(`\u2705 Lua \u5DF2\u5408\u5E76\u4E3A scripts/main.lua\uFF08${n.size} \u4E2A\u6A21\u5757\uFF09`),n.size}async function j(t){const e=[],i=async n=>{const a=await c.readdir(n,{withFileTypes:!0});for(const r of a){const s=d.join(n,r.name);r.isDirectory()?await i(s):r.isFile()&&r.name.endsWith(".lua")&&e.push(s)}};return await i(t),e.sort((n,a)=>{const r=p(t,n),s=p(t,a),o=h(r)??"",u=h(s)??"";if(o===u&&o){const l=r.endsWith("/init.lua")?1:0,f=s.endsWith("/init.lua")?1:0;return l-f}return r.localeCompare(s)}),e}function h(t){const e=t.replace(/\\/g,"/");if(e!=="main.lua"){if(e.endsWith("/init.lua")){const i=e.slice(0,-9);return i?i.replace(/\//g,"."):"init"}if(e.endsWith(".lua"))return e.slice(0,-4).replace(/\//g,".")}}function p(t,e){return d.relative(t,e).split(d.sep).join("/")}function y(t){let e=t.replace(/^\uFEFF/,"");if(e.startsWith("#!")){const i=e.indexOf(`
4
4
  `);e=i>=0?e.slice(i+1):""}return e}function O(t){if(!/["\\\n\r]/.test(t))return`"${t}"`;let e="";for(;t.includes(`]${e}]`);)e+="=";return`[${e}[${t}]${e}]`}async function $(t){const e=async i=>{const n=await c.readdir(i,{withFileTypes:!0});let a=!0;for(const r of n){const s=d.join(i,r.name);r.isDirectory()&&await e(s)?await c.remove(s):a=!1}return a};await e(t)}
@@ -0,0 +1,2 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function addVararg(chunk: Chunk): void;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(t){t.vararg=!0,o(t.body.body)}function e(t){switch(t.type){case"FuncExpr":s(t);break;case"UnaryExpr":e(t.arg);break;case"BinaryExpr":e(t.left),e(t.right);break;case"TableExpr":for(const a of t.fields)a.kind==="index"&&e(a.key),e(a.value);break;case"IndexExpr":e(t.object),e(t.index);break;case"MemberExpr":e(t.object);break;case"CallExpr":e(t.callee);for(const a of t.args)e(a);break;case"MethodCallExpr":e(t.object);for(const a of t.args)e(a);break;case"ParenExpr":e(t.exp);break;default:break}}function o(t){for(const a of t)switch(a.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(a.type==="WhileStat"&&e(a.cond),a.type==="RepeatStat"&&e(a.cond),a.type==="ForNumStat"&&(e(a.start),e(a.end),a.step&&e(a.step)),a.type==="ForInStat")for(const r of a.exps)e(r);o(a.body.body);break;case"IfStat":for(const r of a.clauses)e(r.cond),o(r.body.body);a.elseBody&&o(a.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(a.func);break;case"LocalStat":if(a.exps)for(const r of a.exps)e(r);break;case"AssignStat":for(const r of a.vars)e(r);for(const r of a.exps)e(r);break;case"CallStat":e(a.exp);break;case"ReturnStat":for(const r of a.exps)e(r);break;default:break}}function c(t){o(t.body)}
@@ -0,0 +1,2 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function applyAntiTamper(chunk: Chunk, seed: number): void;
@@ -0,0 +1,26 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=i;const s=require("./parser");function d(n){return(n>>>0)%9e3+100}function i(n,o){const a=o>>>0,t=d(a),e=a%17+3,c=t*e,r=`
2
+ do
3
+ local valid = true
4
+ local acc = ${t}
5
+ if acc * ${e} ~= ${c} then
6
+ valid = false
7
+ end
8
+ local ok = pcall(function()
9
+ return acc * ${e} == ${c}
10
+ end)
11
+ if not ok then
12
+ valid = false
13
+ end
14
+ local s = 0
15
+ for i = 1, 7 do
16
+ s = (s + i * ${e}) % 256
17
+ end
18
+ if s ~= ${(1*e+2*e+3*e+4*e+5*e+6*e+7*e)%256} then
19
+ valid = false
20
+ end
21
+ if valid then
22
+ else
23
+ error("Tamper Detected!")
24
+ end
25
+ end
26
+ `,l=(0,s.parseLua)(r);n.body.unshift(...l.body)}
@@ -0,0 +1,191 @@
1
+ export interface SourceLoc {
2
+ line: number;
3
+ column: number;
4
+ }
5
+ export interface Block {
6
+ type: "Block";
7
+ body: Statement[];
8
+ }
9
+ export interface Chunk {
10
+ type: "Chunk";
11
+ body: Statement[];
12
+ }
13
+ export type Statement = EmptyStat | AssignStat | CallStat | LabelStat | BreakStat | GotoStat | DoStat | WhileStat | RepeatStat | IfStat | ForNumStat | ForInStat | FuncStat | LocalFuncStat | LocalStat | ReturnStat;
14
+ export interface EmptyStat {
15
+ type: "EmptyStat";
16
+ }
17
+ export interface AssignStat {
18
+ type: "AssignStat";
19
+ vars: Expression[];
20
+ exps: Expression[];
21
+ }
22
+ export interface CallStat {
23
+ type: "CallStat";
24
+ exp: CallExpr | MethodCallExpr;
25
+ }
26
+ export interface LabelStat {
27
+ type: "LabelStat";
28
+ name: string;
29
+ }
30
+ export interface BreakStat {
31
+ type: "BreakStat";
32
+ }
33
+ export interface GotoStat {
34
+ type: "GotoStat";
35
+ name: string;
36
+ }
37
+ export interface DoStat {
38
+ type: "DoStat";
39
+ body: Block;
40
+ }
41
+ export interface WhileStat {
42
+ type: "WhileStat";
43
+ cond: Expression;
44
+ body: Block;
45
+ }
46
+ export interface RepeatStat {
47
+ type: "RepeatStat";
48
+ body: Block;
49
+ cond: Expression;
50
+ }
51
+ export interface IfClause {
52
+ cond: Expression;
53
+ body: Block;
54
+ }
55
+ export interface IfStat {
56
+ type: "IfStat";
57
+ clauses: IfClause[];
58
+ elseBody?: Block;
59
+ }
60
+ export interface ForNumStat {
61
+ type: "ForNumStat";
62
+ name: string;
63
+ start: Expression;
64
+ end: Expression;
65
+ step?: Expression;
66
+ body: Block;
67
+ }
68
+ export interface ForInStat {
69
+ type: "ForInStat";
70
+ names: string[];
71
+ exps: Expression[];
72
+ body: Block;
73
+ }
74
+ export interface FuncName {
75
+ base: string;
76
+ fields: string[];
77
+ method?: string;
78
+ }
79
+ export interface FuncStat {
80
+ type: "FuncStat";
81
+ name: FuncName;
82
+ func: FuncExpr;
83
+ }
84
+ export interface LocalFuncStat {
85
+ type: "LocalFuncStat";
86
+ name: string;
87
+ func: FuncExpr;
88
+ }
89
+ export type LocalAttr = "const" | "close";
90
+ export interface LocalName {
91
+ name: string;
92
+ attr?: LocalAttr;
93
+ }
94
+ export interface LocalStat {
95
+ type: "LocalStat";
96
+ names: LocalName[];
97
+ exps?: Expression[];
98
+ }
99
+ export interface ReturnStat {
100
+ type: "ReturnStat";
101
+ exps: Expression[];
102
+ }
103
+ export type Expression = NilLiteral | BoolLiteral | NumberLiteral | StringLiteral | VarargExpr | NameExpr | UnaryExpr | BinaryExpr | FuncExpr | TableExpr | IndexExpr | MemberExpr | CallExpr | MethodCallExpr | ParenExpr;
104
+ export interface NilLiteral {
105
+ type: "NilLiteral";
106
+ }
107
+ export interface BoolLiteral {
108
+ type: "BoolLiteral";
109
+ value: boolean;
110
+ }
111
+ export interface NumberLiteral {
112
+ type: "NumberLiteral";
113
+ raw: string;
114
+ value: number;
115
+ }
116
+ export interface StringLiteral {
117
+ type: "StringLiteral";
118
+ value: string;
119
+ encoded?: boolean;
120
+ }
121
+ export interface VarargExpr {
122
+ type: "VarargExpr";
123
+ }
124
+ export interface NameExpr {
125
+ type: "NameExpr";
126
+ name: string;
127
+ }
128
+ export type UnaryOp = "not" | "#" | "-" | "~";
129
+ export interface UnaryExpr {
130
+ type: "UnaryExpr";
131
+ op: UnaryOp;
132
+ arg: Expression;
133
+ }
134
+ export type BinaryOp = "or" | "and" | "<" | ">" | "<=" | ">=" | "~=" | "==" | "|" | "~" | "&" | "<<" | ">>" | ".." | "+" | "-" | "*" | "/" | "//" | "%" | "^";
135
+ export interface BinaryExpr {
136
+ type: "BinaryExpr";
137
+ op: BinaryOp;
138
+ left: Expression;
139
+ right: Expression;
140
+ }
141
+ export interface FuncExpr {
142
+ type: "FuncExpr";
143
+ params: string[];
144
+ vararg: boolean;
145
+ body: Block;
146
+ }
147
+ export type TableField = TableIndexField | TableNameField | TableListField;
148
+ export interface TableIndexField {
149
+ kind: "index";
150
+ key: Expression;
151
+ value: Expression;
152
+ }
153
+ export interface TableNameField {
154
+ kind: "name";
155
+ key: string;
156
+ value: Expression;
157
+ }
158
+ export interface TableListField {
159
+ kind: "list";
160
+ value: Expression;
161
+ }
162
+ export interface TableExpr {
163
+ type: "TableExpr";
164
+ fields: TableField[];
165
+ }
166
+ export interface IndexExpr {
167
+ type: "IndexExpr";
168
+ object: Expression;
169
+ index: Expression;
170
+ }
171
+ export interface MemberExpr {
172
+ type: "MemberExpr";
173
+ object: Expression;
174
+ field: string;
175
+ }
176
+ export interface CallExpr {
177
+ type: "CallExpr";
178
+ callee: Expression;
179
+ args: Expression[];
180
+ }
181
+ export interface MethodCallExpr {
182
+ type: "MethodCallExpr";
183
+ object: Expression;
184
+ method: string;
185
+ args: Expression[];
186
+ }
187
+ export interface ParenExpr {
188
+ type: "ParenExpr";
189
+ exp: Expression;
190
+ }
191
+ export declare function isCallExpression(exp: Expression): exp is CallExpr | MethodCallExpr;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isCallExpression=l;function l(e){return e.type==="CallExpr"||e.type==="MethodCallExpr"}
@@ -0,0 +1,10 @@
1
+ export interface FoldMixParams {
2
+ mul45: number;
3
+ add45: number;
4
+ mul8: number;
5
+ secret8: number;
6
+ }
7
+ export declare function createFoldMixParams(seed: number): FoldMixParams;
8
+ export declare function foldEncrypt(plain: string, params: FoldMixParams, itemSeed: number): string;
9
+ export declare function foldDecrypt(payload: string, params: FoldMixParams, itemSeed: number): string;
10
+ export declare function emitFoldDecoderLua(params: FoldMixParams, fnName: string): string;
@@ -0,0 +1,28 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=m,exports.foldEncrypt=p,exports.foldDecrypt=g,exports.emitFoldDecoderLua=q;const f=35184372088832n,s=[3,5,6,7,10,12,14,19,20,24];function m(t){const e=t>>>0||1;return{mul45:e%15*4+1,add45:e%99991*2+1,mul8:s[e%s.length],secret8:e%256}}function h(t,e){t.p=(t.p*BigInt(e.mul45)+BigInt(e.add45))%f;do t.q=t.q*e.mul8%257;while(t.q===1);const o=Number(t.p%256n),n=Number(t.p/256n%256n),c=Number(t.p/65536n%256n);return(o+n*(t.q%13)+c+t.q)%256}function a(t,e){return{p:BigInt(e>>>0)%f,q:(e>>>0)%255+2}}function b(t){const e=[];for(let o=0;o<t.length;o+=1){const n=t.charCodeAt(o);if(n<=255)e.push(n);else{const c=Buffer.from(t[o],"utf8");for(const l of c)e.push(l)}}return Buffer.from(e)}function p(t,e,o){const n=b(t),c=a(e,o);let l=e.secret8,r="";for(let u=0;u<n.length;u+=1){const i=h(c,e),d=n[u];r+=String.fromCharCode((d-i-l+512)%256),l=d}return r}function g(t,e,o){const n=a(e,o);let c=e.secret8;const l=Buffer.alloc(t.length);for(let r=0;r<t.length;r+=1){const u=h(n,e),i=(t.charCodeAt(r)+u+c)%256;l[r]=i,c=i}return l.toString("latin1")}function q(t,e){return`local ${e}
2
+ do
3
+ local mul45=${t.mul45}
4
+ local add45=${t.add45}
5
+ local mul8=${t.mul8}
6
+ local secret8=${t.secret8}
7
+ local cache={}
8
+ ${e}=function(s,seed)
9
+ local hit=cache[seed]
10
+ if hit then return hit end
11
+ local p=seed%35184372088832
12
+ local q=seed%255+2
13
+ local prev=secret8
14
+ local n=#s
15
+ local t={}
16
+ for i=1,n do
17
+ p=(p*mul45+add45)%35184372088832
18
+ repeat q=q*mul8%257 until q~=1
19
+ local mix=(p%256+((p//256)%256)*(q%13)+((p//65536)%256)+q)%256
20
+ local b=(s:byte(i)+mix+prev)%256
21
+ t[i]=string.char(b)
22
+ prev=b
23
+ end
24
+ local out=table.concat(t)
25
+ cache[seed]=out
26
+ return out
27
+ end
28
+ end`}
@@ -0,0 +1,31 @@
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;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=M;class T{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(t,r=0,o=0,i=0){return this.ops.push(t),this.code.push([0,r,o,i]),this.code.length-1}patch(t,r,o,i){const a=this.code[t];r!==void 0&&(a[1]=r),o!==void 0&&(a[2]=o),i!==void 0&&(a[3]=i)}kNil(){return this.intern({t:"nil"})}kBool(t){return this.intern({t:"bool",v:t})}kNum(t,r){return this.intern({t:"num",v:t,raw:r})}kStr(t){return this.intern({t:"str",v:t})}intern(t){for(let r=0;r<this.consts.length;r+=1){const o=this.consts[r];if(o.t===t.t&&(o.t==="nil"||o.t==="bool"&&t.t==="bool"&&o.v===t.v||o.t==="num"&&t.t==="num"&&o.v===t.v||o.t==="str"&&t.t==="str"&&o.v===t.v))return r+1}return this.consts.push(t),this.consts.length}alloc(t=1){const r=this.top;return this.top+=t,this.top-1>this.maxStack&&(this.maxStack=this.top-1),r}freeTo(t){this.top=t}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(t,r=!1){const o=this.alloc(1);return this.currentLocals().push({name:t,reg:o,close:r}),o}findLocal(t){for(let r=this.frames.length-1;r>=0;r-=1){const o=this.frames[r].locals;for(let i=o.length-1;i>=0;i-=1)if(o[i].name===t)return o[i].reg}}findUpval(t){for(let i=0;i<this.upvals.length;i+=1)if(this.upvals[i].name===t)return i+1;if(!this.parent)return;const r=this.parent.findLocal(t);if(r!==void 0)return this.upvals.push({name:t,inStack:!0,index:r}),this.upvals.length;const o=this.parent.findUpval(t);if(o!==void 0)return this.upvals.push({name:t,inStack:!1,index:o}),this.upvals.length}finish(){for(const t of this.gotos){const r=this.labels.get(t.name);if(r===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${t.name}::`);this.patch(t.pc,0,r-(t.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 P={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function M(e){const t=new T;return t.isVararg=!0,t.pushFrame(),n(t,e.body),t.emit("RETURN",1,0),t.finish()}function g(e,t){const r=new T;r.parent=e,r.numparams=t.params.length,r.isVararg=t.vararg,r.pushFrame();for(const o of t.params)r.bind(o);return n(r,t.body.body),r.emit("RETURN",1,0),e.protos.push(r.finish()),e.protos.length}function n(e,t){for(const r of t)B(e,r)}function h(e,t){for(const r of t.locals)e.emit("CLOSE",r.reg);e.freeTo(t.savedTop)}function B(e,t){switch(t.type){case"EmptyStat":return;case"BreakStat":{if(e.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const r=e.emit("JMP",0,0);e.breaks[e.breaks.length-1].push(r);return}case"GotoStat":{const r=e.emit("JMP",0,0);e.gotos.push({name:t.name,pc:r});return}case"LabelStat":e.labels.set(t.name,e.code.length);return;case"DoStat":{e.pushFrame(),n(e,t.body.body),h(e,e.frames.pop());return}case"WhileStat":{const r=e.code.length,o=c(e,t.cond);e.emit("TEST",o,0,0);const i=e.emit("JMP",0,0);e.freeTo(o),e.breaks.push([]),e.pushFrame(),n(e,t.body.body),h(e,e.frames.pop()),e.emit("JMP",0,r-(e.code.length+1)),e.patch(i,0,e.code.length-(i+1)),b(e,e.breaks.pop(),e.code.length);return}case"RepeatStat":{const r=e.code.length;e.breaks.push([]),e.pushFrame(),n(e,t.body.body);const o=c(e,t.cond);e.emit("TEST",o,0,0),e.emit("JMP",0,r-(e.code.length+1)),h(e,e.frames.pop()),b(e,e.breaks.pop(),e.code.length);return}case"IfStat":{const r=[];for(let o=0;o<t.clauses.length;o+=1){const i=c(e,t.clauses[o].cond);e.emit("TEST",i,0,0);const a=e.emit("JMP",0,0);e.freeTo(i),e.pushFrame(),n(e,t.clauses[o].body.body),h(e,e.frames.pop()),(o<t.clauses.length-1||t.elseBody)&&r.push(e.emit("JMP",0,0)),e.patch(a,0,e.code.length-(a+1))}t.elseBody&&(e.pushFrame(),n(e,t.elseBody.body),h(e,e.frames.pop()));for(const o of r)e.patch(o,0,e.code.length-(o+1));return}case"ForNumStat":{const r=e.alloc(4);c(e,t.start,r),c(e,t.end,r+1),t.step?c(e,t.step,r+2):e.emit("LOADK",r+2,e.kNum(1,"1"));const o=e.emit("FORPREP",r,0);e.breaks.push([]),e.pushFrame();const i=e.bind(t.name);e.emit("MOVE",i,r+3),n(e,t.body.body),h(e,e.frames.pop());const a=e.emit("FORLOOP",r,0);e.patch(o,r,a-(o+1)),e.patch(a,r,o+1-(a+1)),b(e,e.breaks.pop(),e.code.length),e.freeTo(r);return}case"ForInStat":{const r=e.alloc(3);m(e,t.exps,r,3);const o=e.emit("TFORCALL",r,t.names.length),i=e.emit("TFORLOOP",r,0);e.breaks.push([]),e.pushFrame();for(let a=0;a<t.names.length;a+=1){const s=e.bind(t.names[a]);e.emit("MOVE",s,r+3+a)}n(e,t.body.body),h(e,e.frames.pop()),e.emit("JMP",0,o-(e.code.length+1)),e.patch(i,r,e.code.length-(i+1)),b(e,e.breaks.pop(),e.code.length),e.freeTo(r);return}case"FuncStat":{const r=g(e,t.func),o=e.alloc(1);e.emit("CLOSURE",o,r),N(e,t.name.base,t.name.fields,t.name.method,o),e.freeTo(o);return}case"LocalFuncStat":{const r=e.bind(t.name),o=g(e,t.func);e.emit("CLOSURE",r,o);return}case"LocalStat":{const r=t.names.length,o=[];if(t.exps&&t.exps.length>0){const i=e.top;m(e,t.exps,i,r);for(let a=0;a<r;a+=1){const s=e.bind(t.names[a].name,t.names[a].attr==="close");e.emit("MOVE",s,i+a),o.push(s)}e.freeTo(o[0]),e.top=o[r-1]+1}else for(const i of t.names){const a=e.bind(i.name,i.attr==="close");e.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const r=e.top;m(e,t.exps,r,t.vars.length);for(let o=0;o<t.vars.length;o+=1)R(e,t.vars[o],r+o);e.freeTo(r);return}case"CallStat":{const r=e.top;c(e,t.exp,void 0,0),e.freeTo(r);return}case"ReturnStat":{if(t.exps.length===0){e.emit("RETURN",1,0);return}const r=e.top;m(e,t.exps,r,-1);const o=t.exps[t.exps.length-1],i=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";e.emit("RETURN",r,i?-1:t.exps.length);return}}}function b(e,t,r){for(const o of t)e.patch(o,0,r-(o+1))}function N(e,t,r,o,i){if(r.length===0&&!o){y(e,t,i);return}let s=k(e,t);const l=o?[...r,o]:r;for(let u=0;u<l.length-1;u+=1){const p=e.alloc(1);e.emit("GETTABLE",p,s,-e.kStr(l[u])),s=p}e.emit("SETTABLE",s,-e.kStr(l[l.length-1]),i)}function y(e,t,r){const o=e.findLocal(t);if(o!==void 0){e.emit("MOVE",o,r);return}const i=e.findUpval(t);if(i!==void 0){e.emit("SETUPVAL",r,i);return}e.emit("SETGLOBAL",r,e.kStr(t))}function k(e,t,r){const o=r??e.alloc(1),i=e.findLocal(t);if(i!==void 0)return o!==i&&e.emit("MOVE",o,i),o;const a=e.findUpval(t);return a!==void 0?(e.emit("GETUPVAL",o,a),o):(e.emit("GETGLOBAL",o,e.kStr(t)),o)}function R(e,t,r){if(t.type==="NameExpr"){y(e,t.name,r);return}if(t.type==="MemberExpr"){const o=c(e,t.object);e.emit("SETTABLE",o,-e.kStr(t.field),r);return}if(t.type==="IndexExpr"){const o=c(e,t.object),i=c(e,t.index);e.emit("SETTABLE",o,i,r);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function c(e,t,r,o=1){const i=r??e.alloc(1);switch(t.type){case"NilLiteral":return e.emit("LOADNIL",i),i;case"BoolLiteral":return e.emit("LOADBOOL",i,t.value?1:0),i;case"NumberLiteral":return e.emit("LOADK",i,e.kNum(t.value,t.raw)),i;case"StringLiteral":return e.emit("LOADK",i,e.kStr(t.value)),i;case"VarargExpr":return e.emit("VARARG",i,o),i;case"NameExpr":return k(e,t.name,i);case"ParenExpr":return c(e,t.exp,i,1);case"UnaryExpr":{const a=c(e,t.arg);return e.emit(A[t.op],i,a),i}case"BinaryExpr":return F(e,t.op,t.left,t.right,i);case"FuncExpr":{const a=g(e,t);return e.emit("CLOSURE",i,a),i}case"TableExpr":return x(e,t.fields,i);case"IndexExpr":{const a=c(e,t.object),s=c(e,t.index);return e.emit("GETTABLE",i,a,s),i}case"MemberExpr":{const a=c(e,t.object);return e.emit("GETTABLE",i,a,-e.kStr(t.field)),i}case"CallExpr":return v(e,t.callee,t.args,i,o,!1);case"MethodCallExpr":return v(e,t.object,t.args,i,o,t.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${t.type}`)}}function F(e,t,r,o,i){if(t==="and"||t==="or"){c(e,r,i),e.emit("TEST",i,0,t==="and"?0:1);const u=e.emit("JMP",0,0);return c(e,o,i),e.patch(u,0,e.code.length-(u+1)),i}if(t==="=="||t==="~="||t==="<"||t===">"||t==="<="||t===">="){const u=c(e,r),p=c(e,o);let d="EQ",E=u,L=p;t==="<"||t===">="?d="LT":t==="<="||t===">"?d="LE":d="EQ",(t===">"||t===">=")&&(E=p,L=u);const j=t==="~=";e.emit(d,E,L,j?1:0);const O=e.emit("JMP",0,0);e.emit("LOADBOOL",i,1);const S=e.emit("JMP",0,0);return e.patch(O,0,e.code.length-(O+1)),e.emit("LOADBOOL",i,0),e.patch(S,0,e.code.length-(S+1)),i}const a=P[t];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${t}`);const s=c(e,r),l=c(e,o);return e.emit(a,i,s,l),i}function w(e){return e.type==="CallExpr"||e.type==="MethodCallExpr"||e.type==="VarargExpr"}function v(e,t,r,o,i,a){const s=o,l=r.length>0&&w(r[r.length-1]);if(a){const u=c(e,t,s);return e.emit("SELF",s,u,-e.kStr(a)),m(e,r,s+2,-1),e.emit("CALL",s,l?-1:r.length+1,i),s}return c(e,t,s),m(e,r,s+1,-1),e.emit("CALL",s,l?-1:r.length,i),s}function m(e,t,r,o){const i=o>0?o:Math.max(t.length,1);if(e.top<r+i&&(e.top=r+i,e.top-1>e.maxStack&&(e.maxStack=e.top-1)),t.length===0){if(o>0)for(let a=0;a<o;a+=1)e.emit("LOADNIL",r+a);return}for(let a=0;a<t.length;a+=1){const s=a===t.length-1,l=s&&(o<0||o>t.length)?o===-1?-1:o-a:1;c(e,t[a],r+a,s?l:1)}if(o>t.length)for(let a=t.length;a<o;a+=1)e.emit("LOADNIL",r+a)}function x(e,t,r){e.emit("NEWTABLE",r);const o=[];for(const i of t)if(i.kind==="list")o.push(i.value);else if(i.kind==="name"){const a=c(e,i.value);e.emit("SETTABLE",r,-e.kStr(i.key),a)}else{const a=c(e,i.key),s=c(e,i.value);e.emit("SETTABLE",r,a,s)}if(o.length>0){const i=e.top;m(e,o,i,-1),e.emit("SETLIST",r,i,o.length),e.freeTo(i)}return r}
@@ -0,0 +1,5 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function applyConstantArray(chunk: Chunk, seed: number, options: {
3
+ shuffle: boolean;
4
+ rotate: boolean;
5
+ }): void;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=v;const o=require("./visit"),p="__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),s=n[r];n[r]=n[t],n[t]=s}return n}function v(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 s=n.rotate?i%t.length:0;s>0&&(t=t.slice(s).concat(t.slice(0,s)));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 f=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),m={type:"LocalStat",names:[{name:p}],exps:[{type:"TableExpr",fields:f}]},d={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:p},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(m,d)}
@@ -0,0 +1,2 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function flattenControlFlow(chunk: Chunk, seed: number): void;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=R;function m(e){return{type:"NumberLiteral",raw:String(e),value:e}}function p(e){return{type:"NameExpr",name:e}}function c(e,a){return{type:"AssignStat",vars:e.map(t=>p(t)),exps:a}}function y(e,a){return c([e.stateName],[typeof a=="number"?m(a):a])}function F(e,a,t){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(e),right:m(a)},right:m(t)}}function E(e,a,t){return{type:"BinaryExpr",op:e,left:a,right:t}}function d(e){const a=`__t${e.nextTemp}`;return e.nextTemp+=1,e.temps.push(a),a}function h(e){const a=e.nextState;return e.nextState+=1,e.states.set(a,[]),a}function r(e,a,t){e.states.get(a).push(t)}function L(e,a){for(const t of e)if(t.type==="LocalStat")for(const o of t.names)a.push(o.name);else if(t.type==="LocalFuncStat")a.push(t.name);else if(t.type==="ForNumStat")a.push(t.name),L(t.body.body,a);else if(t.type==="ForInStat")a.push(...t.names),L(t.body.body,a);else if(t.type==="DoStat"||t.type==="WhileStat"||t.type==="RepeatStat")L(t.body.body,a);else if(t.type==="IfStat"){for(const o of t.clauses)L(o.body.body,a);t.elseBody&&L(t.elseBody.body,a)}}function g(e,a,t,o){if(e.length===0)return a;const i=e.map(()=>h(t));for(let n=0;n<e.length;n+=1){const s=e[n];s.type==="LabelStat"&&t.userLabels.set(s.name,i[n])}for(let n=0;n<e.length;n+=1){const s=n+1<e.length?i[n+1]:a;C(t,i[n],e[n],s,o)}return i[0]}function C(e,a,t,o,i){switch(t.type){case"EmptyStat":case"LabelStat":r(e,a,y(e,o));return;case"AssignStat":case"CallStat":case"FuncStat":r(e,a,t),r(e,a,y(e,o));return;case"LocalStat":t.exps&&t.exps.length>0&&r(e,a,c(t.names.map(n=>n.name),t.exps)),r(e,a,y(e,o));return;case"LocalFuncStat":r(e,a,c([t.name],[t.func])),r(e,a,y(e,o));return;case"ReturnStat":r(e,a,t);return;case"BreakStat":r(e,a,y(e,i));return;case"GotoStat":{const n=e.userLabels.get(t.name);if(n===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${t.name}::`);r(e,a,y(e,n));return}case"DoStat":r(e,a,y(e,g(t.body.body,o,e,i)));return;case"IfStat":{const n=d(e);let s=a;for(let f=0;f<t.clauses.length;f+=1){const u=f===t.clauses.length-1,b=g(t.clauses[f].body.body,o,e,i);let S=o;u?t.elseBody&&(S=g(t.elseBody.body,o,e,i)):S=h(e),r(e,s,c([n],[t.clauses[f].cond])),r(e,s,y(e,F(n,b,S))),u||(s=S)}t.clauses.length===0&&r(e,a,y(e,o));return}case"WhileStat":{const n=d(e),s=g(t.body.body,a,e,o);r(e,a,c([n],[t.cond])),r(e,a,y(e,F(n,s,o)));return}case"RepeatStat":{const n=d(e),s=h(e),f=g(t.body.body,s,e,o);r(e,a,y(e,f)),r(e,s,c([n],[t.cond])),r(e,s,y(e,F(n,o,f)));return}case"ForNumStat":{const n=t.name,s=d(e),f=d(e),u=d(e),b=h(e),S=h(e),B=h(e),k=h(e),w=g(t.body.body,k,e,o);r(e,a,c([n],[t.start])),r(e,a,c([s],[t.end])),r(e,a,c([f],[t.step??m(1)])),r(e,a,y(e,b)),r(e,b,c([u],[E(">=",p(f),m(0))])),r(e,b,y(e,F(u,S,B))),r(e,S,c([u],[E("<=",p(n),p(s))])),r(e,S,y(e,F(u,w,o))),r(e,B,c([u],[E(">=",p(n),p(s))])),r(e,B,y(e,F(u,w,o))),r(e,k,c([n],[E("+",p(n),p(f))])),r(e,k,y(e,b));return}case"ForInStat":{const n=d(e),s=d(e),f=d(e),u=d(e),b=h(e),S=[c([f],[p(t.names[0])]),...t.body.body],B=g(S,b,e,o),k=t.exps.slice();for(;k.length<3;)k.push({type:"NilLiteral"});r(e,a,c([n,s,f],k.slice(0,3))),r(e,a,y(e,b)),r(e,b,{type:"AssignStat",vars:t.names.map(w=>p(w)),exps:[{type:"CallExpr",callee:p(n),args:[p(s),p(f)]}]}),r(e,b,c([u],[E("~=",p(t.names[0]),{type:"NilLiteral"})])),r(e,b,y(e,F(u,B,o)));return}default:r(e,a,y(e,o))}}function M(e,a){const t=e.slice();let o=a>>>0||1;for(let i=t.length-1;i>0;i-=1){o=Math.imul(o,1664525)+1013904223>>>0;const n=o%(i+1),s=t[i];t[i]=t[n],t[n]=s}return t}function I(e,a){if(e.length===0)return e;const t={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},o=[];L(e,o);const i=g(e,0,t,0),n=[...new Set([...o,...t.temps,t.stateName])],f=M([...t.states.keys()],a).map(u=>({cond:E("==",p(t.stateName),m(u)),body:{type:"Block",body:t.states.get(u)}}));return[{type:"LocalStat",names:n.map(u=>({name:u}))},c([t.stateName],[m(i)]),{type:"WhileStat",cond:E("~=",p(t.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:f}]}}]}function l(e,a){switch(e.type){case"FuncExpr":N(e.body.body,a),e.body.body=I(e.body.body,a);break;case"UnaryExpr":l(e.arg,a);break;case"BinaryExpr":l(e.left,a),l(e.right,a);break;case"TableExpr":for(const t of e.fields)t.kind==="index"&&l(t.key,a),l(t.value,a);break;case"IndexExpr":l(e.object,a),l(e.index,a);break;case"MemberExpr":l(e.object,a);break;case"CallExpr":l(e.callee,a);for(const t of e.args)l(t,a);break;case"MethodCallExpr":l(e.object,a);for(const t of e.args)l(t,a);break;case"ParenExpr":l(e.exp,a);break;default:break}}function N(e,a){for(const t of e)switch(t.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((t.type==="WhileStat"||t.type==="RepeatStat")&&l(t.cond,a),t.type==="ForNumStat"&&(l(t.start,a),l(t.end,a),t.step&&l(t.step,a)),t.type==="ForInStat")for(const o of t.exps)l(o,a);N(t.body.body,a);break;case"IfStat":for(const o of t.clauses)l(o.cond,a),N(o.body.body,a);t.elseBody&&N(t.elseBody.body,a);break;case"FuncStat":case"LocalFuncStat":N(t.func.body.body,a),t.func.body.body=I(t.func.body.body,a);break;case"LocalStat":if(t.exps)for(const o of t.exps)l(o,a);break;case"AssignStat":for(const o of t.vars)l(o,a);for(const o of t.exps)l(o,a);break;case"CallStat":l(t.exp,a);break;case"ReturnStat":for(const o of t.exps)l(o,a);break;default:break}}function R(e,a){N(e.body,a),e.body=I(e.body,a)}
@@ -0,0 +1,6 @@
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";
@@ -0,0 +1 @@
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=g;const f=require("./addVararg"),l=require("./antiTamper"),d=require("./compiler"),y=require("./constantArray"),u=require("./flatten"),c=require("./minify"),a=require("./numbers"),m=require("./parser"),p=require("./rename"),b=require("./splitStrings"),L=require("./vmEmit"),_=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function q(t){let n=2166136261;for(let r=0;r<t.length;r+=1)n=Math.imul(n^t.charCodeAt(r),16777619);return n>>>0||1}function i(t){return(0,m.parseLua)((0,L.emitVm)((0,d.compileChunk)(t)))}function o(t,n,r){(0,y.applyConstantArray)(t,n,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(t,(n^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,_.wrapInFunction)(t);return(0,p.renameLocals)(t),(0,c.minifyLua)(t)}function g(t,n){const r=q(t);let e=(0,m.parseLua)(t);return(0,p.renameLocals)(e),n==="Minify"?(0,c.minifyLua)(e):n==="Weak"?((0,u.flattenControlFlow)(e,r),e=i(e),o(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):n==="Medium"?((0,f.addVararg)(e),(0,b.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,l.applyAntiTamper)(e,r),(0,u.flattenControlFlow)(e,r),e=i(e),o(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,f.addVararg)(e),(0,b.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,l.applyAntiTamper)(e,(r^2246822507)>>>0),(0,u.flattenControlFlow)(e,(r^2246822507)>>>0),e=i(e),o(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var x=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return x.LuaLexError}});var P=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return P.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}});
@@ -0,0 +1,14 @@
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[];
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=N;const P=require("./reserved");class b extends Error{constructor(f,l,c){super(`${f} (${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=b;function N(L){const f=L.replace(/^\uFEFF/,""),l=[];let c=0,p=1,d=1;const t=(e=0)=>f[c+e]??"",w=()=>c>=f.length,n=()=>{const e=f[c++];return e===`
2
+ `?(p+=1,d=1):d+=1,e},a=e=>{throw new b(e,p,d)},k=e=>e>="A"&&e<="Z"||e>="a"&&e<="z"||e==="_",h=e=>e>="0"&&e<="9",v=e=>h(e)||e>="a"&&e<="f"||e>="A"&&e<="F",g=e=>{const i=Buffer.from(e,"utf8");let r="";for(const o of i)r+=String.fromCharCode(o);return r},x=e=>e===" "||e===" "||e==="\r"||e===`
3
+ `||e==="\f"||e==="\v",C=e=>{if(f[e]!=="[")return-1;let i=0,r=e+1;for(;f[r]==="=";)i+=1,r+=1;return f[r]==="["?i:-1},E=e=>{n();for(let r=0;r<e;r+=1)n();n(),t()==="\r"&&n(),t()===`
4
+ `&&n();let i="";for(;!w();){if(t()==="]"){let r=c+1,o=0;for(;f[r]==="=";)o+=1,r+=1;if(o===e&&f[r]==="]"){n();for(let s=0;s<e;s+=1)n();return n(),i}}i+=g(n())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},y=()=>{for(;!w()&&t()!==`
5
+ `;)n()},O=e=>{n();let i="";for(;!w();){const r=t();if(r===e)return n(),i;if(r===`
6
+ `)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(r!=="\\"){i+=g(n());continue}n();const o=t();if(o==="a")n(),i+="\x07";else if(o==="b")n(),i+="\b";else if(o==="f")n(),i+="\f";else if(o==="n")n(),i+=`
7
+ `;else if(o==="r")n(),i+="\r";else if(o==="t")n(),i+=" ";else if(o==="v")n(),i+="\v";else if(o==="\\"||o==='"'||o==="'"||o===`
8
+ `)i+=n();else if(o==="\r")n(),t()===`
9
+ `&&n(),i+=`
10
+ `;else if(o==="x"){n();const s=t(),m=t(1);if(!v(s)||!v(m))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");n(),n(),i+=String.fromCharCode(parseInt(s+m,16))}else if(o==="u"){if(n(),t()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");n();let s="";for(;v(t());)s+=n();if(t()!=="}"||s.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");n(),i+=g(String.fromCodePoint(parseInt(s,16)))}else if(o==="z")for(n();x(t());)n();else if(h(o)){let s="";for(;h(t())&&s.length<3;)s+=n();const m=parseInt(s,10);if(m>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");i+=String.fromCharCode(m)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${o}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},F=()=>{const e=p,i=d;let r="";if(t()==="0"&&(t(1)==="x"||t(1)==="X")){for(r+=n(),r+=n();v(t())||t()===".";)r+=n();if(t()==="p"||t()==="P")for(r+=n(),(t()==="+"||t()==="-")&&(r+=n());h(t());)r+=n()}else{for(;h(t())||t()===".";)r+=n();if(t()==="e"||t()==="E")for(r+=n(),(t()==="+"||t()==="-")&&(r+=n());h(t());)r+=n()}const s=Number(r);if(!Number.isFinite(s))throw new b(`\u65E0\u6548\u6570\u5B57 ${r}`,e,i);return{kind:"number",value:r,line:e,column:i,parsed:s}};for(;!w();){const e=t();if(x(e)){n();continue}if(e==="-"&&t(1)==="-"){const u=p,$=d;n(),n();const S=C(c);S>=0?E(S):y();continue}const i=p,r=d;if(e==="'"||e==='"'){const u=O(e);l.push({kind:"string",value:u,line:i,column:r,parsed:u});continue}const o=C(c);if(o>=0){const u=E(o);l.push({kind:"string",value:u,line:i,column:r,parsed:u});continue}if(h(e)||e==="."&&h(t(1))){l.push(F());continue}if(k(e)){let u="";for(;k(t())||h(t());)u+=n();l.push({kind:P.luaKeywords.has(u)?"keyword":"name",value:u,line:i,column:r});continue}const s=e+t(1);if(s+t(2)==="..."){n(),n(),n(),l.push({kind:"vararg",value:"...",line:i,column:r});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(s)){n(),n(),l.push({kind:s,value:s,line:i,column:r});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(e)){n(),l.push({kind:e,value:e,line:i,column:r});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(e)}`)}return l.push({kind:"eof",value:"",line:p,column:d}),l}
@@ -0,0 +1,3 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function escapeLuaString(value: string): string;
3
+ export declare function minifyLua(chunk: Chunk): string;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=d,exports.minifyLua=f;const l=new Set(["and","or"]);function d(t){let r='"';for(let n=0;n<t.length;n+=1){const u=t.charCodeAt(n)&255;r+=`\\${String(u).padStart(3,"0")}`}return r+='"',r}class p{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 f(t){const r=new p;return s(r,t.body,!0),r.toString()}function o(t,r){s(t,r.body,!1)}function s(t,r,n){for(let u=0;u<r.length;u+=1)w(t,r[u]),u<r.length-1&&t.punct(";")}function w(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"),o(t,r.body),t.word("end");return;case"WhileStat":t.word("while"),a(t,r.cond),t.word("do"),o(t,r.body),t.word("end");return;case"RepeatStat":t.word("repeat"),o(t,r.body),t.word("until"),a(t,r.cond);return;case"IfStat":for(let n=0;n<r.clauses.length;n+=1)t.word(n===0?"if":"elseif"),a(t,r.clauses[n].cond),t.word("then"),o(t,r.clauses[n].body);r.elseBody&&(t.word("else"),o(t,r.elseBody)),t.word("end");return;case"ForNumStat":t.word("for"),t.word(r.name),t.punct("="),a(t,r.start),t.punct(","),a(t,r.end),r.step&&(t.punct(","),a(t,r.step)),t.word("do"),o(t,r.body),t.word("end");return;case"ForInStat":t.word("for");for(let n=0;n<r.names.length;n+=1)n>0&&t.punct(","),t.word(r.names[n]);t.word("in"),c(t,r.exps),t.word("do"),o(t,r.body),t.word("end");return;case"FuncStat":t.word("function"),t.word(r.name.base);for(const n of r.name.fields)t.punct("."),t.word(n);r.name.method&&(t.punct(":"),t.word(r.name.method)),e(t,r.func,!!r.name.method);return;case"LocalFuncStat":t.word("local"),t.word("function"),t.word(r.name),e(t,r.func,!1);return;case"LocalStat":t.word("local");for(let n=0;n<r.names.length;n+=1)n>0&&t.punct(","),t.word(r.names[n].name),r.names[n].attr&&(t.punct("<"),t.word(r.names[n].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":a(t,r.exp);return;case"ReturnStat":t.word("return"),r.exps.length>0&&c(t,r.exps);return}}function e(t,r,n){t.punct("(");const u=n?r.params.filter(i=>i!=="self"):r.params;for(let i=0;i<u.length;i+=1)i>0&&t.punct(","),t.word(u[i]);r.vararg&&(u.length>0&&t.punct(","),t.punct("...")),t.punct(")"),o(t,r.body),t.word("end")}function c(t,r){for(let n=0;n<r.length;n+=1)n>0&&t.punct(","),a(t,r[n])}function a(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(d(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),a(t,r.arg);return;case"BinaryExpr":a(t,r.left),l.has(r.op)?t.word(r.op):t.punct(r.op),a(t,r.right);return;case"FuncExpr":t.word("function"),e(t,r,!1);return;case"TableExpr":t.punct("{");for(let n=0;n<r.fields.length;n+=1)n>0&&t.punct(","),h(t,r.fields[n]);t.punct("}");return;case"IndexExpr":a(t,r.object),t.punct("["),a(t,r.index),t.punct("]");return;case"MemberExpr":a(t,r.object),t.punct("."),t.word(r.field);return;case"CallExpr":a(t,r.callee),t.punct("("),c(t,r.args),t.punct(")");return;case"MethodCallExpr":a(t,r.object),t.punct(":"),t.word(r.method),t.punct("("),c(t,r.args),t.punct(")");return;case"ParenExpr":t.punct("("),a(t,r.exp),t.punct(")");return}}function h(t,r){if(r.kind==="index"){t.punct("["),a(t,r.key),t.punct("]"),t.punct("="),a(t,r.value);return}if(r.kind==="name"){t.word(r.key),t.punct("="),a(t,r.value);return}a(t,r.value)}
@@ -0,0 +1,2 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function numbersToExpressions(chunk: Chunk, seed: number): void;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=s;const o=require("./visit");function l(r,i){const t=Math.abs(i)%9+2,e=r-t;if(r<0)return{type:"UnaryExpr",op:"-",arg:l(-r,i+3)};if(r<=2)return{type:"NumberLiteral",raw:String(r),value:r};if(i%3===0){const u=r%7+2,a=Math.floor(r/u),n=r-u*a,p={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(u),value:u},right:{type:"NumberLiteral",raw:String(a),value:a}};return n===0?{type:"ParenExpr",exp:p}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:p,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(e),value:e}}}}function s(r,i){let t=0;(0,o.mapChunk)(r,e=>e.type!=="NumberLiteral"||!Number.isInteger(e.value)||!Number.isSafeInteger(e.value)?e:(t+=1,l(e.value,i+t*17)))}
@@ -0,0 +1,3 @@
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>;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=S,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 S(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),t=E[O];E[O]=E[L],E[L]=t}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
@@ -0,0 +1,8 @@
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 };
@@ -0,0 +1 @@
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(k,p,c){super(`${k} (${p}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:p}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const k=(0,ee.lexLua)(E);let p=0;const c=()=>k[p],s=(e,t)=>{const n=c();return!(n.kind!==e||t!==void 0&&n.value!==t)},S=e=>s("keyword",e),h=e=>{const t=c();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=c();return n.kind!==e||t!==void 0&&n.value!==t?h(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(p+=1,n)},o=(e,t)=>{if(s(e,t)){const n=c();return p+=1,n}},u=e=>S(e)?(p+=1,!0):!1,a=()=>r("name").value,f=e=>{const t=[];for(;!s("eof")&&!(c().kind==="keyword"&&e.includes(c().value));){if(S("return")){t.push($()),o(";");break}const n=F();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),s("eof")||s(";")||c().kind==="keyword"&&["end","else","elseif","until"].includes(c().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:x()}),F=()=>{if(o(";"))return{type:"EmptyStat"};if(u("break"))return{type:"BreakStat"};if(u("goto"))return{type:"GotoStat",name:a()};if(u("do")){const e=f(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(u("while")){const e=i();r("keyword","do");const t=f(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(u("repeat")){const e=f(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(u("if"))return U();if(u("for"))return A();if(u("function")){const e=M(),t=w(!!e.method);return{type:"FuncStat",name:e,func:t}}if(u("local")){if(u("function")){const e=a(),t=w(!1);return{type:"LocalFuncStat",name:e,func:t}}return O()}if(s("::")){r("::");const e=a();return r("::"),{type:"LabelStat",name:e}}return _()},U=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:f(["elseif","else","end"])});u("elseif");){const l=i();r("keyword","then"),e.push({cond:l,body:f(["elseif","else","end"])})}let n;return u("else")&&(n=f(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},A=()=>{const e=a();if(o("=")){const b=i();r(",");const g=i();let N;o(",")&&(N=i()),r("keyword","do");const Y=f(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:b,end:g,step:N,body:Y}}const t=[e];for(;o(",");)t.push(a());r("keyword","in");const n=x();r("keyword","do");const l=f(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:l}},M=()=>{const e=a(),t=[];for(;o(".");)t.push(a());let n;return o(":")&&(n=a()),{base:e,fields:t,method:n}},w=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!s(")"))if(s("vararg"))r("vararg"),n=!0;else for(t.push(a());o(",");){if(s("vararg")){r("vararg"),n=!0;break}t.push(a())}r(")");const l=f(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:l}},O=()=>{const e=[v()];for(;o(",");)e.push(v());let t;return o("=")&&(t=x()),{type:"LocalStat",names:e,exps:t}},v=()=>{const e=a();if(o("<")){const t=a();return r(">"),t!=="const"&&t!=="close"&&h(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},_=()=>{const e=m();if(s("=")||s(",")){const t=[e];for(;o(",");)t.push(m());r("=");const n=x();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")},x=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>I(),d=(e,t)=>{let n=e();for(;;){const l=c(),b=l.kind==="keyword"?l.value:l.kind;if(!t.includes(b))break;p+=1;const g=e();n={type:"BinaryExpr",op:b,left:n,right:g}}return n},I=()=>d(R,["or"]),R=()=>d(q,["and"]),q=()=>d(D,["<",">","<=",">=","~=","=="]),D=()=>d(G,["|"]),G=()=>d(K,["~"]),K=()=>d(T,["&"]),T=()=>d(L,["<<",">>"]),L=()=>{const e=V();return s("..")?(p+=1,{type:"BinaryExpr",op:"..",left:e,right:L()}):e},V=()=>d(W,["+","-"]),W=()=>d(y,["*","/","//","%"]),y=()=>u("not")?{type:"UnaryExpr",op:"not",arg:y()}:o("#")?{type:"UnaryExpr",op:"#",arg:y()}:o("-")?{type:"UnaryExpr",op:"-",arg:y()}:o("~")?{type:"UnaryExpr",op:"~",arg:y()}:z(),z=()=>{const e=H();return s("^")?(p+=1,{type:"BinaryExpr",op:"^",left:e,right:y()}):e},H=()=>{if(u("nil"))return{type:"NilLiteral"};if(u("true"))return{type:"BoolLiteral",value:!0};if(u("false"))return{type:"BoolLiteral",value:!1};if(s("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(s("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(u("function"))return w(!1);if(s("{")){let e=C();return e=B(e),e}return m()},B=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:a()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=a(),l=P();t={type:"MethodCallExpr",object:t,method:n,args:l};continue}if(s("(")||s("{")||s("string")){t={type:"CallExpr",callee:t,args:P()};continue}break}return t},m=()=>B(J()),J=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return s("name")?{type:"NameExpr",name:a()}:h("\u671F\u671B\u8868\u8FBE\u5F0F")},P=()=>{if(s("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(s("{"))return[C()];if(r("("),o(")"))return[];const e=x();return r(")"),e},C=()=>{r("{");const e=[];for(;!s("}")&&(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(s("name")&&k[p+1]?.kind==="="){const e=a();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=f([]);return r("eof"),{type:"Chunk",body:X.body}}
@@ -0,0 +1,3 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function shortName(n: number): string;
3
+ export declare function renameLocals(chunk: Chunk): void;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=l,exports.renameLocals=h;const c=require("./reserved"),u=require("./scope"),o="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function l(r){let e=r,t="";do t=o[e%o.length]+t,e=Math.floor(e/o.length)-1;while(e>=0);return c.luaKeywords.has(t)?`_${t}`:t}function h(r){let e=0;const t=new Set;(0,u.collectAndRename)(r,(n,s)=>{if(n.newName!==n.original)return;let a=l(e);for(e+=1;s.has(a)||t.has(a)||c.luaKeywords.has(a);)a=l(e),e+=1;n.newName=a,t.add(a),s.add(a)})}
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1 @@
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)}
@@ -0,0 +1,11 @@
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;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=e,exports.collectAndRename=g;function e(t,r){let n=t;for(;n;){const a=n.locals.get(r);if(a)return a;n=n.parent}}function i(t){return{parent:t,locals:new Map}}function S(t,r){const n=t.locals.get(r);if(n)return n;const a={original:r,newName:r};return t.locals.set(r,a),a}function g(t,r){const n=new Set,a={locals:new Map};y(t.body,a,n,r)}function f(t,r,n,a){y(t.body,r,n,a)}function y(t,r,n,a){for(const o of t)E(o,r,n,a)}function w(t,r,n,a){const o=i(r),l=t.params.slice();for(let b=0;b<l.length;b+=1){const u=S(o,l[b]);a(u,n),t.params[b]=u.newName}f(t.body,o,n,a)}function E(t,r,n,a){switch(t.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":f(t.body,i(r),n,a);return;case"WhileStat":c(t.cond,r,n,a),f(t.body,i(r),n,a);return;case"RepeatStat":{const o=i(r);f(t.body,o,n,a),c(t.cond,o,n,a);return}case"IfStat":for(const o of t.clauses)c(o.cond,r,n,a),f(o.body,i(r),n,a);t.elseBody&&f(t.elseBody,i(r),n,a);return;case"ForNumStat":{c(t.start,r,n,a),c(t.end,r,n,a),t.step&&c(t.step,r,n,a);const o=i(r),l=S(o,t.name);a(l,n),t.name=l.newName,f(t.body,o,n,a);return}case"ForInStat":{for(const l of t.exps)c(l,r,n,a);const o=i(r);for(let l=0;l<t.names.length;l+=1){const b=S(o,t.names[l]);a(b,n),t.names[l]=b.newName}f(t.body,o,n,a);return}case"FuncStat":{const o=e(r,t.name.base);o&&(t.name.base=o.newName),w(t.func,r,n,a);return}case"LocalFuncStat":{const o=S(r,t.name);a(o,n),t.name=o.newName,w(t.func,r,n,a);return}case"LocalStat":if(t.exps)for(const o of t.exps)c(o,r,n,a);for(let o=0;o<t.names.length;o+=1){const l=S(r,t.names[o].name);a(l,n),t.names[o].name=l.newName}return;case"AssignStat":for(const o of t.vars)c(o,r,n,a);for(const o of t.exps)c(o,r,n,a);return;case"CallStat":c(t.exp,r,n,a);return;case"ReturnStat":for(const o of t.exps)c(o,r,n,a);return}}function c(t,r,n,a){switch(t.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const o=e(r,t.name);o&&(t.name=o.newName);return}case"UnaryExpr":c(t.arg,r,n,a);return;case"BinaryExpr":c(t.left,r,n,a),c(t.right,r,n,a);return;case"FuncExpr":w(t,r,n,a);return;case"TableExpr":for(const o of t.fields)o.kind==="index"&&c(o.key,r,n,a),c(o.value,r,n,a);return;case"IndexExpr":c(t.object,r,n,a),c(t.index,r,n,a);return;case"MemberExpr":c(t.object,r,n,a);return;case"CallExpr":c(t.callee,r,n,a);for(const o of t.args)c(o,r,n,a);return;case"MethodCallExpr":c(t.object,r,n,a);for(const o of t.args)c(o,r,n,a);return;case"ParenExpr":c(t.exp,r,n,a);return}}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const m=require("child_process"),l=require("./cipher"),S=require("./flatten"),f=require("./minify"),r=require("./parser"),c=require("./index");let a=0;function n(e,t){e?console.log(`\u2705 ${t}`):(a+=1,console.error(`\u274C ${t}`))}const u=`
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 _(){const e=(0,l.createFoldMixParams)(42),t=["device","\u4F60\u597D","Sleep",""];for(const i of t){if(i.length===0)continue;const o=(0,l.foldEncrypt)(i,e,99),s=(0,l.foldDecrypt)(o,e,99),p=Buffer.from(i,"utf8").toString("latin1");n(s===p,`FoldMix \u5F80\u8FD4 ${i}`),n(!o.includes("device")||i!=="device","FoldMix \u8F7D\u8377\u4E0D\u542B\u660E\u6587 device")}}function b(){const e=(0,r.parseLua)(u),t=(0,f.minifyLua)(e),i=(0,r.parseLua)(t);n(i.body.length>0,"\u89E3\u6790\u5F80\u8FD4\u5F97\u5230\u975E\u7A7A AST"),n(t.includes("Sleep"),"Minify \u53D1\u5C04\u4FDD\u7559 Sleep")}function y(){const e=(0,c.obfuscateLua)(u,"Minify");n(e.includes("Sleep"),"Minify \u4E0D\u6539 Sleep"),n(e.includes("require"),"Minify \u4FDD\u7559 require"),n(!e.includes('"device"'),"Minify \u4E0D\u4FDD\u7559\u660E\u6587 device \u5B57\u9762\u91CF"),n(e.includes("\\100\\101\\118\\105\\099\\101"),"Minify \u7528\u5341\u8FDB\u5236\u8F6C\u4E49\u4FDD\u7559 device"),n(!/\bwait\b/.test(e),"Minify \u91CD\u547D\u540D\u5C40\u90E8 wait"),(0,r.parseLua)(e)}function M(){const t=(0,r.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,S.flattenControlFlow)(t,1);const i=(0,f.minifyLua)(t);n(i.includes("while"),"\u5C55\u5E73\u540E\u662F\u72B6\u6001\u673A\u5FAA\u73AF"),n(!/for\s+i\s*=\s*1\s*,\s*3/.test(i),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F for i=1,3"),n(!/if\s+n\s*==\s*6/.test(i),"\u5C55\u5E73\u540E\u4E0D\u518D\u662F if n==6")}function g(){const e=(0,c.obfuscateLua)(u,"Weak");n(e.includes("function"),"Weak \u542B Vmify \u89E3\u91CA\u5668"),n(!e.includes("Sleep(wait)"),"Weak \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(wait)"),n(!e.includes("helper.tap"),"Weak \u4E0D\u518D\u4FDD\u7559 helper.tap \u6E90\u7801\u7ED3\u6784"),n(!/\bhelper\b/.test(e),"Weak \u6539\u6389\u5C40\u90E8 helper"),(0,r.parseLua)(e),n(!0,"Weak \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function h(){const e=(0,c.obfuscateLua)(u,"Medium");n(e.includes("function"),"Medium \u542B\u865A\u62DF\u673A"),n(!e.includes('logi("ok")'),"Medium \u52A0\u5BC6\u7528\u6237\u5B57\u7B26\u4E32"),n(!e.includes("Tamper Detected!")||e.includes("pcall"),"Medium \u542B\u5B8C\u6574\u6027\u68C0\u67E5\u6216\u5DF2\u7F16\u8FDB VM"),(0,r.parseLua)(e),n(!0,"Medium \u4EA7\u7269\u53EF\u518D\u89E3\u6790")}function L(){const t=(0,c.obfuscateLua)('local d=require("device"); Sleep(1)',"Strong");n(t.includes("function"),"Strong \u542B\u89E3\u91CA\u5668\u51FD\u6570"),n(!t.includes("Sleep(1)"),"Strong \u4E0D\u518D\u4FDD\u7559\u660E\u6587 Sleep(1) \u8C03\u7528"),(0,r.parseLua)(t),n(!0,"Strong \u4EA7\u7269\u662F\u5408\u6CD5 Lua")}function k(){const t=(0,c.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,r.parseLua)(t),n(t.includes("<const>"),"Minify \u4FDD\u7559 <const>"),n(t.includes("//"),"Minify \u4FDD\u7559\u6574\u9664")}function q(e){const t=["/opt/homebrew/bin/lua","lua5.4","lua54","lua"];for(const i of t){const o=(0,m.spawnSync)(i,["-e",e],{encoding:"utf8"});if(!o.error)return{ok:o.status===0,out:(o.stdout||"")+(o.stderr||"")}}return{ok:!1,out:""}}function d(e){const i=(0,c.obfuscateLua)('local m=require("device"); Sleep(3)',e),o=`
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(i)}, "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("${e}-ok")
37
+ `,s=q(o);if(!s.out&&s.ok===!1){console.log(`\u2139\uFE0F \u672C\u673A\u65E0 lua \u89E3\u91CA\u5668\uFF0C\u8DF3\u8FC7 ${e} \u8FD0\u884C\u65F6\u68C0\u67E5`);return}n(s.ok&&s.out.includes(`${e}-ok`),`${e} \u8FD0\u884C\u65F6\u8FD8\u539F require/Sleep: ${s.out.trim()}`)}_(),b(),y(),M(),g(),h(),L(),k(),d("Medium"),d("Strong"),a>0&&(console.error(`
38
+ \u81EA\u68C0\u5931\u8D25 ${a} \u9879`),process.exit(1)),console.log(`
39
+ \u81EA\u68C0\u901A\u8FC7`);
@@ -0,0 +1,2 @@
1
+ import type { Chunk } from "./ast";
2
+ export declare function splitStrings(chunk: Chunk, seed: number): void;