ms-vite-plugin 1.4.59 → 1.4.61
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.
- package/dist/luaBundle.js +1 -1
- package/dist/luaObfuscator/addVararg.d.ts +2 -0
- package/dist/luaObfuscator/addVararg.js +1 -0
- package/dist/luaObfuscator/antiTamper.d.ts +2 -0
- package/dist/luaObfuscator/antiTamper.js +26 -0
- package/dist/luaObfuscator/ast.d.ts +191 -0
- package/dist/luaObfuscator/ast.js +1 -0
- package/dist/luaObfuscator/cipher.d.ts +10 -0
- package/dist/luaObfuscator/cipher.js +28 -0
- package/dist/luaObfuscator/compiler.d.ts +31 -0
- package/dist/luaObfuscator/compiler.js +1 -0
- package/dist/luaObfuscator/constantArray.d.ts +5 -0
- package/dist/luaObfuscator/constantArray.js +1 -0
- package/dist/luaObfuscator/flatten.d.ts +2 -0
- package/dist/luaObfuscator/flatten.js +1 -0
- package/dist/luaObfuscator/index.d.ts +6 -0
- package/dist/luaObfuscator/index.js +1 -0
- package/dist/luaObfuscator/lexer.d.ts +14 -0
- package/dist/luaObfuscator/lexer.js +10 -0
- package/dist/luaObfuscator/minify.d.ts +3 -0
- package/dist/luaObfuscator/minify.js +1 -0
- package/dist/luaObfuscator/numbers.d.ts +2 -0
- package/dist/luaObfuscator/numbers.js +1 -0
- package/dist/luaObfuscator/opcodes.d.ts +3 -0
- package/dist/luaObfuscator/opcodes.js +1 -0
- package/dist/luaObfuscator/parser.d.ts +8 -0
- package/dist/luaObfuscator/parser.js +1 -0
- package/dist/luaObfuscator/rename.d.ts +3 -0
- package/dist/luaObfuscator/rename.js +1 -0
- package/dist/luaObfuscator/reserved.d.ts +5 -0
- package/dist/luaObfuscator/reserved.js +1 -0
- package/dist/luaObfuscator/scope.d.ts +11 -0
- package/dist/luaObfuscator/scope.js +1 -0
- package/dist/luaObfuscator/selftest.d.ts +1 -0
- package/dist/luaObfuscator/selftest.js +39 -0
- package/dist/luaObfuscator/splitStrings.d.ts +2 -0
- package/dist/luaObfuscator/splitStrings.js +1 -0
- package/dist/luaObfuscator/strings.d.ts +4 -0
- package/dist/luaObfuscator/strings.js +1 -0
- package/dist/luaObfuscator/visit.d.ts +5 -0
- package/dist/luaObfuscator/visit.js +1 -0
- package/dist/luaObfuscator/vmEmit.d.ts +2 -0
- package/dist/luaObfuscator/vmEmit.js +281 -0
- package/dist/luaObfuscator/wrapInFunction.d.ts +2 -0
- package/dist/luaObfuscator/wrapInFunction.js +1 -0
- package/docs/AGENTS.md +1 -1
- package/docs/SKILL.md +1 -1
- package/docs/api/hid.md +21 -0
- package/docs/apicn/hid.md +21 -0
- package/docs/apilua/action.md +2 -27
- package/docs/apilua/appleocr.md +2 -6
- package/docs/apilua/cloud.md +2 -6
- package/docs/apilua/config.md +2 -6
- package/docs/apilua/cryptoUtils.md +2 -7
- package/docs/apilua/device.md +2 -19
- package/docs/apilua/dotocr.md +2 -5
- package/docs/apilua/file.md +2 -17
- package/docs/apilua/global.md +1 -1
- package/docs/apilua/hid.md +25 -44
- package/docs/apilua/hotUpdate.md +2 -3
- package/docs/apilua/http.md +2 -7
- package/docs/apilua/image.md +2 -20
- package/docs/apilua/ime.md +2 -10
- package/docs/apilua/logger.md +3 -9
- package/docs/apilua/media.md +2 -9
- package/docs/apilua/mysql.md +2 -10
- package/docs/apilua/netCard.md +2 -6
- package/docs/apilua/node.md +2 -3
- package/docs/apilua/opencv.md +1 -27
- package/docs/apilua/paddleocr.md +2 -7
- package/docs/apilua/pip.md +2 -12
- package/docs/apilua/system.md +2 -23
- package/docs/apilua/tomatoocr.md +2 -16
- package/docs/apilua/tts.md +2 -9
- package/docs/apilua/ui.md +3 -9
- package/docs/apilua/utils.md +2 -9
- package/docs/apilua/yolo.md +2 -4
- package/docs/apilua/yolocls.md +2 -5
- package/docs/apipython/hid.md +22 -0
- package/docs/mcp-agent-description.md +1 -1
- package/docs/quick/vscode/createProject.md +1 -1
- package/docs/quick/vscode/packProject.md +1 -1
- 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}
|
|
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 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(r){r.vararg=!0,t(r.body.body)}function a(r){switch(r.type){case"FuncExpr":s(r);break;case"UnaryExpr":a(r.arg);break;case"BinaryExpr":a(r.left),a(r.right);break;case"TableExpr":for(const e of r.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(r.object),a(r.index);break;case"MemberExpr":a(r.object);break;case"CallExpr":a(r.callee);for(const e of r.args)a(e);break;case"MethodCallExpr":a(r.object);for(const e of r.args)a(e);break;case"ParenExpr":a(r.exp);break;default:break}}function t(r){for(const e of r)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(e.type==="WhileStat"&&a(e.cond),e.type==="RepeatStat"&&a(e.cond),e.type==="ForNumStat"&&(a(e.start),a(e.end),e.step&&a(e.step)),e.type==="ForInStat")for(const o of e.exps)a(o);t(e.body.body);break;case"IfStat":for(const o of e.clauses)a(o.cond),t(o.body.body);e.elseBody&&t(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(e.func);break;case"LocalStat":if(e.exps)for(const o of e.exps)a(o);break;case"AssignStat":for(const o of e.vars)a(o);for(const o of e.exps)a(o);break;case"CallStat":a(e.exp);break;case"ReturnStat":for(const o of e.exps)a(o);break;default:break}}function c(r){t(r.body)}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=s;const o=require("./parser");function r(n){return(n>>>0)%9e3+100}function s(n,c){const a=c>>>0,l=r(a),e=a%17+3,t=l*e,d=`
|
|
2
|
+
do
|
|
3
|
+
local valid = true
|
|
4
|
+
local acc = ${l}
|
|
5
|
+
if acc * ${e} ~= ${t} then
|
|
6
|
+
valid = false
|
|
7
|
+
end
|
|
8
|
+
local ok = pcall(function()
|
|
9
|
+
return acc * ${e} == ${t}
|
|
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
|
+
`,i=(0,o.parseLua)(d);n.body.unshift(...i.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=q,exports.foldDecrypt=g,exports.emitFoldDecoderLua=b;const d=35184372088832n,i=[3,5,6,7,10,12,14,19,20,24];function m(e){const n=e>>>0||1;return{mul45:n%15*4+1,add45:n%99991*2+1,mul8:i[n%i.length],secret8:n%256}}function f(e,n){e.p=(e.p*BigInt(n.mul45)+BigInt(n.add45))%d;do e.q=e.q*n.mul8%257;while(e.q===1);const l=Number(e.p%256n),o=Number(e.p/256n%256n),t=Number(e.p/65536n%256n);return(l+o*(e.q%13)+t+e.q)%256}function p(e,n){return{p:BigInt(n>>>0)%d,q:(n>>>0)%255+2}}function h(e){const n=[];for(let l=0;l<e.length;l+=1){const o=e.charCodeAt(l);if(o<=255)n.push(o);else{const t=Buffer.from(e[l],"utf8");for(const c of t)n.push(c)}}return Buffer.from(n)}function q(e,n,l){const o=h(e),t=p(n,l);let c=n.secret8,r="";for(let u=0;u<o.length;u+=1){const a=f(t,n),s=o[u];r+=String.fromCharCode((s-a-c+512)%256),c=s}return r}function g(e,n,l){const o=p(n,l);let t=n.secret8;const c=Buffer.alloc(e.length);for(let r=0;r<e.length;r+=1){const u=f(o,n),a=(e.charCodeAt(r)+u+t)%256;c[r]=a,t=a}return c.toString("latin1")}function b(e,n){return`local ${n}
|
|
2
|
+
do
|
|
3
|
+
local mul45=${e.mul45}
|
|
4
|
+
local add45=${e.add45}
|
|
5
|
+
local mul8=${e.mul8}
|
|
6
|
+
local secret8=${e.secret8}
|
|
7
|
+
local cache={}
|
|
8
|
+
${n}=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=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(r,e=0,n=0,s=0){return this.ops.push(r),this.code.push([0,e,n,s]),this.code.length-1}patch(r,e,n,s){const o=this.code[r];e!==void 0&&(o[1]=e),n!==void 0&&(o[2]=n),s!==void 0&&(o[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(r){return this.intern({t:"bool",v:r})}kNum(r,e){return this.intern({t:"num",v:r,raw:e})}kStr(r){return this.intern({t:"str",v:r})}intern(r){for(let e=0;e<this.consts.length;e+=1){const n=this.consts[e];if(n.t===r.t&&(n.t==="nil"||n.t==="bool"&&r.t==="bool"&&n.v===r.v||n.t==="num"&&r.t==="num"&&n.v===r.v||n.t==="str"&&r.t==="str"&&n.v===r.v))return e+1}return this.consts.push(r),this.consts.length}alloc(r=1){const e=this.top;return this.top+=r,this.top-1>this.maxStack&&(this.maxStack=this.top-1),e}freeTo(r){this.top=r}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(r,e=!1){const n=this.alloc(1);return this.currentLocals().push({name:r,reg:n,close:e}),n}findLocal(r){for(let e=this.frames.length-1;e>=0;e-=1){const n=this.frames[e].locals;for(let s=n.length-1;s>=0;s-=1)if(n[s].name===r)return n[s].reg}}findUpval(r){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===r)return s+1;if(!this.parent)return;const e=this.parent.findLocal(r);if(e!==void 0)return this.upvals.push({name:r,inStack:!0,index:e}),this.upvals.length;const n=this.parent.findUpval(r);if(n!==void 0)return this.upvals.push({name:r,inStack:!1,index:n}),this.upvals.length}finish(){for(const r of this.gotos){const e=this.labels.get(r.name);if(e===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${r.name}::`);this.patch(r.pc,0,e-(r.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(t){const r=new O;return r.isVararg=!0,r.pushFrame(),u(r,t.body),r.emit("RETURN",1,0),r.finish()}function d(t,r){const e=new O;e.parent=t,e.numparams=r.params.length,e.isVararg=r.vararg,e.pushFrame();for(const n of r.params)e.bind(n);return u(e,r.body.body),e.emit("RETURN",1,0),t.protos.push(e.finish()),t.protos.length}function u(t,r){for(const e of r)B(t,e)}function p(t,r){for(const e of r.locals)t.emit("CLOSE",e.reg);t.freeTo(r.savedTop)}function B(t,r){switch(r.type){case"EmptyStat":return;case"BreakStat":{if(t.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const e=t.emit("JMP",0,0);t.breaks[t.breaks.length-1].push(e);return}case"GotoStat":{const e=t.emit("JMP",0,0);t.gotos.push({name:r.name,pc:e});return}case"LabelStat":t.labels.set(r.name,t.code.length);return;case"DoStat":{t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop());return}case"WhileStat":{const e=t.code.length,n=i(t,r.cond);t.emit("TEST",n,0,0);const s=t.emit("JMP",0,0);t.freeTo(n),t.breaks.push([]),t.pushFrame(),u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,e-(t.code.length+1)),t.patch(s,0,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length);return}case"RepeatStat":{const e=t.code.length;t.breaks.push([]),t.pushFrame(),u(t,r.body.body);const n=i(t,r.cond);t.emit("TEST",n,0,0),t.emit("JMP",0,e-(t.code.length+1)),p(t,t.frames.pop()),f(t,t.breaks.pop(),t.code.length);return}case"IfStat":{const e=[];for(let n=0;n<r.clauses.length;n+=1){const s=i(t,r.clauses[n].cond);t.emit("TEST",s,0,0);const o=t.emit("JMP",0,0);t.freeTo(s),t.pushFrame(),u(t,r.clauses[n].body.body),p(t,t.frames.pop()),(n<r.clauses.length-1||r.elseBody)&&e.push(t.emit("JMP",0,0)),t.patch(o,0,t.code.length-(o+1))}r.elseBody&&(t.pushFrame(),u(t,r.elseBody.body),p(t,t.frames.pop()));for(const n of e)t.patch(n,0,t.code.length-(n+1));return}case"ForNumStat":{const e=t.alloc(4);i(t,r.start,e),i(t,r.end,e+1),r.step?i(t,r.step,e+2):t.emit("LOADK",e+2,t.kNum(1,"1"));const n=t.emit("FORPREP",e,0);t.breaks.push([]),t.pushFrame();const s=t.bind(r.name);t.emit("MOVE",s,e+3),u(t,r.body.body),p(t,t.frames.pop());const o=t.emit("FORLOOP",e,0);t.patch(n,e,o-(n+1)),t.patch(o,e,n+1-(o+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"ForInStat":{const e=t.alloc(3);h(t,r.exps,e,3);const n=t.emit("TFORCALL",e,r.names.length),s=t.emit("TFORLOOP",e,0);t.breaks.push([]),t.pushFrame();for(let o=0;o<r.names.length;o+=1){const a=t.bind(r.names[o]);t.emit("MOVE",a,e+3+o)}u(t,r.body.body),p(t,t.frames.pop()),t.emit("JMP",0,n-(t.code.length+1)),t.patch(s,e,t.code.length-(s+1)),f(t,t.breaks.pop(),t.code.length),t.freeTo(e);return}case"FuncStat":{const e=d(t,r.func),n=t.alloc(1);t.emit("CLOSURE",n,e),w(t,r.name.base,r.name.fields,r.name.method,n),t.freeTo(n);return}case"LocalFuncStat":{const e=t.bind(r.name),n=d(t,r.func);t.emit("CLOSURE",e,n);return}case"LocalStat":{const e=r.names.length,n=[];if(r.exps&&r.exps.length>0){const s=t.top;h(t,r.exps,s,e);for(let o=0;o<e;o+=1){const a=t.bind(r.names[o].name,r.names[o].attr==="close");t.emit("MOVE",a,s+o),n.push(a)}t.freeTo(n[0]),t.top=n[e-1]+1}else for(const s of r.names){const o=t.bind(s.name,s.attr==="close");t.emit("LOADNIL",o),n.push(o)}return}case"AssignStat":{const e=t.top;h(t,r.exps,e,r.vars.length);for(let n=0;n<r.vars.length;n+=1)F(t,r.vars[n],e+n);t.freeTo(e);return}case"CallStat":{const e=t.top;i(t,r.exp,void 0,0),t.freeTo(e);return}case"ReturnStat":{if(r.exps.length===0){t.emit("RETURN",1,0);return}const e=t.top;h(t,r.exps,e,-1);const n=r.exps[r.exps.length-1],s=n.type==="CallExpr"||n.type==="MethodCallExpr"||n.type==="VarargExpr";t.emit("RETURN",e,s?-1:r.exps.length);return}}}function f(t,r,e){for(const n of r)t.patch(n,0,e-(n+1))}function w(t,r,e,n,s){if(e.length===0&&!n){S(t,r,s);return}let o=T(t,r);const a=n?[...e,n]:e;for(let c=0;c<a.length-1;c+=1){const l=t.alloc(1);t.emit("GETTABLE",l,o,-t.kStr(a[c])),o=l}t.emit("SETTABLE",o,-t.kStr(a[a.length-1]),s)}function S(t,r,e){const n=t.findLocal(r);if(n!==void 0){t.emit("MOVE",n,e);return}const s=t.findUpval(r);if(s!==void 0){t.emit("SETUPVAL",e,s);return}t.emit("SETGLOBAL",e,t.kStr(r))}function T(t,r,e){const n=e??t.alloc(1),s=t.findLocal(r);if(s!==void 0)return n!==s&&t.emit("MOVE",n,s),n;const o=t.findUpval(r);return o!==void 0?(t.emit("GETUPVAL",n,o),n):(t.emit("GETGLOBAL",n,t.kStr(r)),n)}function F(t,r,e){if(r.type==="NameExpr"){S(t,r.name,e);return}if(r.type==="MemberExpr"){const n=i(t,r.object);t.emit("SETTABLE",n,-t.kStr(r.field),e);return}if(r.type==="IndexExpr"){const n=i(t,r.object),s=i(t,r.index);t.emit("SETTABLE",n,s,e);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function i(t,r,e,n=1){const s=e??t.alloc(1);switch(r.type){case"NilLiteral":return t.emit("LOADNIL",s),s;case"BoolLiteral":return t.emit("LOADBOOL",s,r.value?1:0),s;case"NumberLiteral":return t.emit("LOADK",s,t.kNum(r.value,r.raw)),s;case"StringLiteral":return t.emit("LOADK",s,t.kStr(r.value)),s;case"VarargExpr":return t.emit("VARARG",s,n),s;case"NameExpr":return T(t,r.name,s);case"ParenExpr":return i(t,r.exp,s,1);case"UnaryExpr":{const o=i(t,r.arg);return t.emit(A[r.op],s,o),s}case"BinaryExpr":return M(t,r.op,r.left,r.right,s);case"FuncExpr":{const o=d(t,r);return t.emit("CLOSURE",s,o),s}case"TableExpr":return R(t,r.fields,s);case"IndexExpr":{const o=i(t,r.object),a=i(t,r.index);return t.emit("GETTABLE",s,o,a),s}case"MemberExpr":{const o=i(t,r.object);return t.emit("GETTABLE",s,o,-t.kStr(r.field)),s}case"CallExpr":return y(t,r.callee,r.args,s,n,!1);case"MethodCallExpr":return y(t,r.object,r.args,s,n,r.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${r.type}`)}}function M(t,r,e,n,s){if(r==="and"||r==="or"){i(t,e,s),t.emit("TEST",s,0,r==="and"?0:1);const l=t.emit("JMP",0,0);return i(t,n,s),t.patch(l,0,t.code.length-(l+1)),s}if(r==="=="||r==="~="||r==="<"||r===">"||r==="<="||r===">="){const l=i(t,e),b=i(t,n);let m="EQ",g=l,E=b;r==="<"||r===">="?m="LT":r==="<="||r===">"?m="LE":m="EQ",(r===">"||r===">=")&&(g=b,E=l);const x=r==="~=";t.emit(m,g,E,x?1:0);const L=t.emit("JMP",0,0);t.emit("LOADBOOL",s,1);const v=t.emit("JMP",0,0);return t.patch(L,0,t.code.length-(L+1)),t.emit("LOADBOOL",s,0),t.patch(v,0,t.code.length-(v+1)),s}const o=k[r];if(!o)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${r}`);const a=i(t,e),c=i(t,n);return t.emit(o,s,a,c),s}function N(t){return t.type==="CallExpr"||t.type==="MethodCallExpr"||t.type==="VarargExpr"}function y(t,r,e,n,s,o){const a=n,c=e.length>0&&N(e[e.length-1]);if(o){const l=i(t,r,a);return t.emit("SELF",a,l,-t.kStr(o)),h(t,e,a+2,-1),t.emit("CALL",a,c?-1:e.length+1,s),a}return i(t,r,a),h(t,e,a+1,-1),t.emit("CALL",a,c?-1:e.length,s),a}function h(t,r,e,n){const s=n>0?n:Math.max(r.length,1);if(t.top<e+s&&(t.top=e+s,t.top-1>t.maxStack&&(t.maxStack=t.top-1)),r.length===0){if(n>0)for(let o=0;o<n;o+=1)t.emit("LOADNIL",e+o);return}for(let o=0;o<r.length;o+=1){const a=o===r.length-1,c=a&&(n<0||n>r.length)?n===-1?-1:n-o:1;i(t,r[o],e+o,a?c:1)}if(n>r.length)for(let o=r.length;o<n;o+=1)t.emit("LOADNIL",e+o)}function R(t,r,e){t.emit("NEWTABLE",e);const n=[];for(const s of r)if(s.kind==="list")n.push(s.value);else if(s.kind==="name"){const o=i(t,s.value);t.emit("SETTABLE",e,-t.kStr(s.key),o)}else{const o=i(t,s.key),a=i(t,s.value);t.emit("SETTABLE",e,o,a)}if(n.length>0){const s=t.top;h(t,n,s,-1),t.emit("SETLIST",e,s,n.length),t.freeTo(s)}return e}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=h;const i=require("./visit"),o="__C",y="__G";function g(l,s){const a=l.slice();let n=s>>>0||1;for(let r=a.length-1;r>0;r-=1){n=Math.imul(n,1664525)+1013904223>>>0;const t=n%(r+1),p=a[r];a[r]=a[t],a[t]=p}return a}function h(l,s,a){const n=[],r=new Set;if((0,i.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),n.push(e.value)),e)),n.length===0)return;let t=a.shuffle?g(n,s):n.slice();const p=a.rotate?s%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,i.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:o}],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:o},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(d,f)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,s){return{type:"AssignStat",vars:t.map(e=>p(e)),exps:s}}function u(t,s){return f([t.stateName],[typeof s=="number"?m(s):s])}function k(t,s,e){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(t),right:m(s)},right:m(e)}}function E(t,s,e){return{type:"BinaryExpr",op:t,left:s,right:e}}function S(t){const s=`__t${t.nextTemp}`;return t.nextTemp+=1,t.temps.push(s),s}function x(t){const s=t.nextState;return t.nextState+=1,t.states.set(s,[]),s}function r(t,s,e){t.states.get(s).push(e)}function B(t,s){for(const e of t)if(e.type==="LocalStat")for(const n of e.names)s.push(n.name);else if(e.type==="LocalFuncStat")s.push(e.name);else if(e.type==="ForNumStat")s.push(e.name),B(e.body.body,s);else if(e.type==="ForInStat")s.push(...e.names),B(e.body.body,s);else if(e.type==="DoStat"||e.type==="WhileStat"||e.type==="RepeatStat")B(e.body.body,s);else if(e.type==="IfStat"){for(const n of e.clauses)B(n.body.body,s);e.elseBody&&B(e.elseBody.body,s)}}function h(t,s,e,n){if(t.length===0)return s;const y=t.map(()=>x(e));for(let o=0;o<t.length;o+=1){const a=t[o];a.type==="LabelStat"&&e.userLabels.set(a.name,y[o])}for(let o=0;o<t.length;o+=1){const a=o+1<t.length?y[o+1]:s;I(e,y[o],t[o],a,n)}return y[0]}function I(t,s,e,n,y){switch(e.type){case"EmptyStat":case"LabelStat":r(t,s,u(t,n));return;case"AssignStat":case"CallStat":case"FuncStat":r(t,s,e),r(t,s,u(t,n));return;case"LocalStat":e.exps&&e.exps.length>0&&r(t,s,f(e.names.map(o=>o.name),e.exps)),r(t,s,u(t,n));return;case"LocalFuncStat":r(t,s,f([e.name],[e.func])),r(t,s,u(t,n));return;case"ReturnStat":r(t,s,e);return;case"BreakStat":r(t,s,u(t,y));return;case"GotoStat":{const o=t.userLabels.get(e.name);if(o===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${e.name}::`);r(t,s,u(t,o));return}case"DoStat":r(t,s,u(t,h(e.body.body,n,t,y)));return;case"IfStat":{const o=S(t);let a=s;for(let l=0;l<e.clauses.length;l+=1){const b=l===e.clauses.length-1,d=h(e.clauses[l].body.body,n,t,y);let i=n;b?e.elseBody&&(i=h(e.elseBody.body,n,t,y)):i=x(t),r(t,a,f([o],[e.clauses[l].cond])),r(t,a,u(t,k(o,d,i))),b||(a=i)}e.clauses.length===0&&r(t,s,u(t,n));return}case"WhileStat":{const o=S(t),a=h(e.body.body,s,t,n);r(t,s,f([o],[e.cond])),r(t,s,u(t,k(o,a,n)));return}case"RepeatStat":{const o=S(t),a=x(t),l=h(e.body.body,a,t,n);r(t,s,u(t,l)),r(t,a,f([o],[e.cond])),r(t,a,u(t,k(o,n,l)));return}case"ForNumStat":{const o=e.name,a=S(t),l=S(t),b=S(t),d=x(t),i=x(t),L=x(t),g=x(t),N=h(e.body.body,g,t,n);r(t,s,f([o],[e.start])),r(t,s,f([a],[e.end])),r(t,s,f([l],[e.step??m(1)])),r(t,s,u(t,d)),r(t,d,f([b],[E(">=",p(l),m(0))])),r(t,d,u(t,k(b,i,L))),r(t,i,f([b],[E("<=",p(o),p(a))])),r(t,i,u(t,k(b,N,n))),r(t,L,f([b],[E(">=",p(o),p(a))])),r(t,L,u(t,k(b,N,n))),r(t,g,f([o],[E("+",p(o),p(l))])),r(t,g,u(t,d));return}case"ForInStat":{const o=S(t),a=S(t),l=S(t),b=S(t),d=x(t),i=[f([l],[p(e.names[0])]),...e.body.body],L=h(i,d,t,n),g=e.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});r(t,s,f([o,a,l],g.slice(0,3))),r(t,s,u(t,d)),r(t,d,{type:"AssignStat",vars:e.names.map(N=>p(N)),exps:[{type:"CallExpr",callee:p(o),args:[p(a),p(l)]}]}),r(t,d,f([b],[E("~=",p(e.names[0]),{type:"NilLiteral"})])),r(t,d,u(t,k(b,L,n)));return}default:r(t,s,u(t,n))}}function v(t,s){const e=t.slice();let n=s>>>0||1;for(let y=e.length-1;y>0;y-=1){n=Math.imul(n,1664525)+1013904223>>>0;const o=n%(y+1),a=e[y];e[y]=e[o],e[o]=a}return e}function w(t,s){if(t.length===0)return t;const e={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},n=[];B(t,n);const y=h(t,0,e,0),o=[...new Set([...n,...e.temps,e.stateName])],a=v([...e.states.keys()],s).map(l=>({cond:E("==",p(e.stateName),m(l)),body:{type:"Block",body:e.states.get(l)}}));return[{type:"LocalStat",names:o.map(l=>({name:l}))},f([e.stateName],[m(y)]),{type:"WhileStat",cond:E("~=",p(e.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:a}]}}]}function c(t,s){switch(t.type){case"FuncExpr":F(t.body.body,s),t.body.body=w(t.body.body,s);break;case"UnaryExpr":c(t.arg,s);break;case"BinaryExpr":c(t.left,s),c(t.right,s);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&c(e.key,s),c(e.value,s);break;case"IndexExpr":c(t.object,s),c(t.index,s);break;case"MemberExpr":c(t.object,s);break;case"CallExpr":c(t.callee,s);for(const e of t.args)c(e,s);break;case"MethodCallExpr":c(t.object,s);for(const e of t.args)c(e,s);break;case"ParenExpr":c(t.exp,s);break;default:break}}function F(t,s){for(const e of t)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((e.type==="WhileStat"||e.type==="RepeatStat")&&c(e.cond,s),e.type==="ForNumStat"&&(c(e.start,s),c(e.end,s),e.step&&c(e.step,s)),e.type==="ForInStat")for(const n of e.exps)c(n,s);F(e.body.body,s);break;case"IfStat":for(const n of e.clauses)c(n.cond,s),F(n.body.body,s);e.elseBody&&F(e.elseBody.body,s);break;case"FuncStat":case"LocalFuncStat":F(e.func.body.body,s),e.func.body.body=w(e.func.body.body,s);break;case"LocalStat":if(e.exps)for(const n of e.exps)c(n,s);break;case"AssignStat":for(const n of e.vars)c(n,s);for(const n of e.exps)c(n,s);break;case"CallStat":c(e.exp,s);break;case"ReturnStat":for(const n of e.exps)c(n,s);break;default:break}}function C(t,s){F(t.body,s),t.body=w(t.body,s)}
|
|
@@ -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 l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),u=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(n){let t=2166136261;for(let r=0;r<n.length;r+=1)t=Math.imul(t^n.charCodeAt(r),16777619);return t>>>0||1}function o(n){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(n)))}function i(n,t,r){(0,y.applyConstantArray)(n,t,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(n,(t^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(n);return(0,m.renameLocals)(n),(0,c.minifyLua)(n)}function g(n,t){const r=P(n);let e=(0,p.parseLua)(n);return(0,m.renameLocals)(e),t==="Minify"?(0,c.minifyLua)(e):t==="Weak"?((0,u.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):t==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,u.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,u.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var E=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return E.LuaLexError}});var O=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return O.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=L;const D=require("./reserved");class F extends Error{constructor(l,s,c){super(`${l} (${s}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:s}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function L(v){const l=v.replace(/^\uFEFF/,""),s=[];let c=0,m=1,d=1;const r=(u=0)=>l[c+u]??"",h=()=>c>=l.length,e=()=>{const u=l[c++];return u===`
|
|
2
|
+
`?(m+=1,d=1):d+=1,u},a=u=>{throw new F(u,m,d)},b=u=>u>="A"&&u<="Z"||u>="a"&&u<="z"||u==="_",E=u=>u>="0"&&u<="9",p=u=>E(u)||u>="a"&&u<="f"||u>="A"&&u<="F",C=u=>{const i=Buffer.from(u,"utf8");let n="";for(const t of i)n+=String.fromCharCode(t);return n},g=u=>u===" "||u===" "||u==="\r"||u===`
|
|
3
|
+
`||u==="\f"||u==="\v",B=u=>{if(l[u]!=="[")return-1;let i=0,n=u+1;for(;l[n]==="=";)i+=1,n+=1;return l[n]==="["?i:-1},k=u=>{e();for(let n=0;n<u;n+=1)e();e(),r()==="\r"&&e(),r()===`
|
|
4
|
+
`&&e();let i="";for(;!h();){if(r()==="]"){let n=c+1,t=0;for(;l[n]==="=";)t+=1,n+=1;if(t===u&&l[n]==="]"){e();for(let o=0;o<u;o+=1)e();return e(),i}}i+=C(e())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&r()!==`
|
|
5
|
+
`;)e()},y=u=>{e();let i="";for(;!h();){const n=r();if(n===u)return e(),i;if(n===`
|
|
6
|
+
`)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(n!=="\\"){i+=C(e());continue}e();const t=r();if(t==="a")e(),i+="\x07";else if(t==="b")e(),i+="\b";else if(t==="f")e(),i+="\f";else if(t==="n")e(),i+=`
|
|
7
|
+
`;else if(t==="r")e(),i+="\r";else if(t==="t")e(),i+=" ";else if(t==="v")e(),i+="\v";else if(t==="\\"||t==='"'||t==="'"||t===`
|
|
8
|
+
`)i+=e();else if(t==="\r")e(),r()===`
|
|
9
|
+
`&&e(),i+=`
|
|
10
|
+
`;else if(t==="x"){e();const o=r(),f=r(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");e(),e(),i+=String.fromCharCode(parseInt(o+f,16))}else if(t==="u"){if(e(),r()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");e();let o="";for(;p(r());)o+=e();if(r()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");e(),i+=C(String.fromCodePoint(parseInt(o,16)))}else if(t==="z")for(e();g(r());)e();else if(E(t)){let o="";for(;E(r())&&o.length<3;)o+=e();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");i+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${t}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},A=()=>{const u=m,i=d;let n="";if(r()==="0"&&(r(1)==="x"||r(1)==="X")){for(n+=e(),n+=e();p(r())||r()===".";)n+=e();if(r()==="p"||r()==="P")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}else{for(;E(r())||r()===".";)n+=e();if(r()==="e"||r()==="E")for(n+=e(),(r()==="+"||r()==="-")&&(n+=e());E(r());)n+=e()}const t=Number(n);if(!Number.isFinite(t))throw new F(`\u65E0\u6548\u6570\u5B57 ${n}`,u,i);return{kind:"number",value:n,line:u,column:i,parsed:t}};for(;!h();){const u=r();if(g(u)){e();continue}if(u==="-"&&r(1)==="-"){const f=m,$=d;e(),e();const x=B(c);x>=0?k(x):w();continue}const i=m,n=d;if(u==="'"||u==='"'){const f=y(u);s.push({kind:"string",value:f,line:i,column:n,parsed:f});continue}const t=B(c);if(t>=0){const f=k(t);s.push({kind:"string",value:f,line:i,column:n,parsed:f});continue}if(E(u)||u==="."&&E(r(1))){s.push(A());continue}if(b(u)){let f="";for(;b(r())||E(r());)f+=e();s.push({kind:D.luaKeywords.has(f)?"keyword":"name",value:f,line:i,column:n});continue}const o=u+r(1);if(o+r(2)==="..."){e(),e(),e(),s.push({kind:"vararg",value:"...",line:i,column:n});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){e(),e(),s.push({kind:o,value:o,line:i,column:n});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(u)){e(),s.push({kind:u,value:u,line:i,column:n});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(u)}`)}return s.push({kind:"eof",value:"",line:m,column:d}),s}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=p,exports.minifyLua=w;const l=new Set(["and","or"]);function p(e){let n='"';for(let a=0;a<e.length;a+=1){const u=e.charCodeAt(a)&255;n+=`\\${String(u).padStart(3,"0")}`}return n+='"',n}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(n){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(n),this.last="word"}num(n){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(n),this.last="num"}punct(n){n===".."&&this.last==="num"&&this.parts.push(" "),n==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(n),this.last="punct"}toString(){return this.parts.join("")}}function w(e){const n=new i;return d(n,e.body,!0),n.toString()}function r(e,n){d(e,n.body,!1)}function d(e,n,a){for(let u=0;u<n.length;u+=1)h(e,n[u]),u<n.length-1&&e.punct(";")}function h(e,n){switch(n.type){case"EmptyStat":e.punct(";");return;case"BreakStat":e.word("break");return;case"GotoStat":e.word("goto"),e.word(n.name);return;case"LabelStat":e.punct("::"),e.word(n.name),e.punct("::");return;case"DoStat":e.word("do"),r(e,n.body),e.word("end");return;case"WhileStat":e.word("while"),o(e,n.cond),e.word("do"),r(e,n.body),e.word("end");return;case"RepeatStat":e.word("repeat"),r(e,n.body),e.word("until"),o(e,n.cond);return;case"IfStat":for(let a=0;a<n.clauses.length;a+=1)e.word(a===0?"if":"elseif"),o(e,n.clauses[a].cond),e.word("then"),r(e,n.clauses[a].body);n.elseBody&&(e.word("else"),r(e,n.elseBody)),e.word("end");return;case"ForNumStat":e.word("for"),e.word(n.name),e.punct("="),o(e,n.start),e.punct(","),o(e,n.end),n.step&&(e.punct(","),o(e,n.step)),e.word("do"),r(e,n.body),e.word("end");return;case"ForInStat":e.word("for");for(let a=0;a<n.names.length;a+=1)a>0&&e.punct(","),e.word(n.names[a]);e.word("in"),s(e,n.exps),e.word("do"),r(e,n.body),e.word("end");return;case"FuncStat":e.word("function"),e.word(n.name.base);for(const a of n.name.fields)e.punct("."),e.word(a);n.name.method&&(e.punct(":"),e.word(n.name.method)),c(e,n.func,!!n.name.method);return;case"LocalFuncStat":e.word("local"),e.word("function"),e.word(n.name),c(e,n.func,!1);return;case"LocalStat":e.word("local");for(let a=0;a<n.names.length;a+=1)a>0&&e.punct(","),e.word(n.names[a].name),n.names[a].attr&&(e.punct("<"),e.word(n.names[a].attr),e.punct(">"));n.exps&&n.exps.length>0&&(e.punct("="),s(e,n.exps));return;case"AssignStat":s(e,n.vars),e.punct("="),s(e,n.exps);return;case"CallStat":o(e,n.exp);return;case"ReturnStat":e.word("return"),n.exps.length>0&&s(e,n.exps);return}}function c(e,n,a){e.punct("(");const u=a?n.params.filter(t=>t!=="self"):n.params;for(let t=0;t<u.length;t+=1)t>0&&e.punct(","),e.word(u[t]);n.vararg&&(u.length>0&&e.punct(","),e.punct("...")),e.punct(")"),r(e,n.body),e.word("end")}function s(e,n){for(let a=0;a<n.length;a+=1)a>0&&e.punct(","),o(e,n[a])}function o(e,n){switch(n.type){case"NilLiteral":e.word("nil");return;case"BoolLiteral":e.word(n.value?"true":"false");return;case"NumberLiteral":e.num(n.raw);return;case"StringLiteral":e.punct(p(n.value));return;case"VarargExpr":e.punct("...");return;case"NameExpr":e.word(n.name);return;case"UnaryExpr":n.op==="not"?e.word("not"):e.punct(n.op),o(e,n.arg);return;case"BinaryExpr":o(e,n.left),l.has(n.op)?e.word(n.op):e.punct(n.op),o(e,n.right);return;case"FuncExpr":e.word("function"),c(e,n,!1);return;case"TableExpr":e.punct("{");for(let a=0;a<n.fields.length;a+=1)a>0&&e.punct(","),f(e,n.fields[a]);e.punct("}");return;case"IndexExpr":o(e,n.object),e.punct("["),o(e,n.index),e.punct("]");return;case"MemberExpr":o(e,n.object),e.punct("."),e.word(n.field);return;case"CallExpr":o(e,n.callee),e.punct("("),s(e,n.args),e.punct(")");return;case"MethodCallExpr":o(e,n.object),e.punct(":"),e.word(n.method),e.punct("("),s(e,n.args),e.punct(")");return;case"ParenExpr":e.punct("("),o(e,n.exp),e.punct(")");return}}function f(e,n){if(n.kind==="index"){e.punct("["),o(e,n.key),e.punct("]"),e.punct("="),o(e,n.value);return}if(n.kind==="name"){e.word(n.key),e.punct("="),o(e,n.value);return}o(e,n.value)}
|
|
@@ -0,0 +1 @@
|
|
|
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,n=Math.floor(e/p),u=e-p*n,i={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(p),value:p},right:{type:"NumberLiteral",raw:String(n),value:n}};return u===0?{type:"ParenExpr",exp:i}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:i,right:{type:"NumberLiteral",raw:String(u),value:u}}}}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)))}
|
|
@@ -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=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(S){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=S>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),e=E[O];E[O]=E[L],E[L]=e}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(b,p,l){super(`${b} (${p}:${l})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:p}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:l}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let p=0;const l=()=>b[p],u=(e,t)=>{const n=l();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),m=e=>{const t=l();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=l();return n.kind!==e||t!==void 0&&n.value!==t?m(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(p+=1,n)},o=(e,t)=>{if(u(e,t)){const n=l();return p+=1,n}},a=e=>w(e)?(p+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(l().kind==="keyword"&&e.includes(l().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(";")||l().kind==="keyword"&&["end","else","elseif","until"].includes(l().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 h=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:h,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"&&m(`\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}:m("\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=l(),h=d.kind==="keyword"?d.value:d.kind;if(!t.includes(h))break;p+=1;const g=e();n={type:"BinaryExpr",op:h,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("..")?(p+=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("^")?(p+=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()}:m("\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[p+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}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=n,exports.renameLocals=d;const u=require("./reserved"),c=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function n(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 d(r){let e=0;const t=new Set;(0,c.collectAndRename)(r,(o,s)=>{if(o.newName!==o.original)return;let a=n(e);for(e+=1;s.has(a)||t.has(a)||u.luaKeywords.has(a);)a=n(e),e+=1;o.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=i,exports.collectAndRename=b;function i(e,c){let o=e;for(;o;){const s=o.locals.get(c);if(s)return s;o=o.parent}}function r(e){return{parent:e,locals:new Map}}function f(e,c){const o=e.locals.get(c);if(o)return o;const s={original:c,newName:c};return e.locals.set(c,s),s}function b(e,c){const o=new Set,s={locals:new Map};d(e.body,s,o,c)}function l(e,c,o,s){d(e.body,c,o,s)}function d(e,c,o,s){for(const n of e)x(n,c,o,s)}function m(e,c,o,s){const n=r(c),t=e.params.slice();for(let u=0;u<t.length;u+=1){const p=f(n,t[u]);s(p,o),e.params[u]=p.newName}l(e.body,n,o,s)}function x(e,c,o,s){switch(e.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":l(e.body,r(c),o,s);return;case"WhileStat":a(e.cond,c,o,s),l(e.body,r(c),o,s);return;case"RepeatStat":{const n=r(c);l(e.body,n,o,s),a(e.cond,n,o,s);return}case"IfStat":for(const n of e.clauses)a(n.cond,c,o,s),l(n.body,r(c),o,s);e.elseBody&&l(e.elseBody,r(c),o,s);return;case"ForNumStat":{a(e.start,c,o,s),a(e.end,c,o,s),e.step&&a(e.step,c,o,s);const n=r(c),t=f(n,e.name);s(t,o),e.name=t.newName,l(e.body,n,o,s);return}case"ForInStat":{for(const t of e.exps)a(t,c,o,s);const n=r(c);for(let t=0;t<e.names.length;t+=1){const u=f(n,e.names[t]);s(u,o),e.names[t]=u.newName}l(e.body,n,o,s);return}case"FuncStat":{const n=i(c,e.name.base);n&&(e.name.base=n.newName),m(e.func,c,o,s);return}case"LocalFuncStat":{const n=f(c,e.name);s(n,o),e.name=n.newName,m(e.func,c,o,s);return}case"LocalStat":if(e.exps)for(const n of e.exps)a(n,c,o,s);for(let n=0;n<e.names.length;n+=1){const t=f(c,e.names[n].name);s(t,o),e.names[n].name=t.newName}return;case"AssignStat":for(const n of e.vars)a(n,c,o,s);for(const n of e.exps)a(n,c,o,s);return;case"CallStat":a(e.exp,c,o,s);return;case"ReturnStat":for(const n of e.exps)a(n,c,o,s);return}}function a(e,c,o,s){switch(e.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const n=i(c,e.name);n&&(e.name=n.newName);return}case"UnaryExpr":a(e.arg,c,o,s);return;case"BinaryExpr":a(e.left,c,o,s),a(e.right,c,o,s);return;case"FuncExpr":m(e,c,o,s);return;case"TableExpr":for(const n of e.fields)n.kind==="index"&&a(n.key,c,o,s),a(n.value,c,o,s);return;case"IndexExpr":a(e.object,c,o,s),a(e.index,c,o,s);return;case"MemberExpr":a(e.object,c,o,s);return;case"CallExpr":a(e.callee,c,o,s);for(const n of e.args)a(n,c,o,s);return;case"MethodCallExpr":a(e.object,c,o,s);for(const n of e.args)a(n,c,o,s);return;case"ParenExpr":a(e.exp,c,o,s);return}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
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`);
|