ms-vite-plugin 1.4.60 → 1.4.62
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/luaObfuscator/addVararg.js +1 -1
- package/dist/luaObfuscator/antiTamper.js +5 -5
- package/dist/luaObfuscator/cipher.js +1 -1
- package/dist/luaObfuscator/compiler.js +1 -1
- package/dist/luaObfuscator/constantArray.js +1 -1
- package/dist/luaObfuscator/flatten.js +1 -1
- package/dist/luaObfuscator/index.js +1 -1
- package/dist/luaObfuscator/lexer.js +10 -10
- package/dist/luaObfuscator/minify.js +1 -1
- package/dist/luaObfuscator/numbers.js +1 -1
- package/dist/luaObfuscator/opcodes.js +1 -1
- package/dist/luaObfuscator/parser.js +1 -1
- package/dist/luaObfuscator/rename.js +1 -1
- package/dist/luaObfuscator/scope.js +1 -1
- package/dist/luaObfuscator/selftest.js +8 -8
- package/dist/luaObfuscator/splitStrings.js +1 -1
- package/dist/luaObfuscator/strings.js +1 -1
- package/dist/luaObfuscator/visit.js +1 -1
- package/dist/luaObfuscator/vmEmit.js +3 -3
- package/docs/api/hid.md +21 -0
- package/docs/api/opencv.md +8 -8
- package/docs/apicn/hid.md +21 -0
- package/docs/apilua/hid.md +23 -0
- package/docs/apilua/image.md +29 -14
- package/docs/apilua/opencv.md +12 -11
- package/docs/apilua/system.md +1 -1
- package/docs/apilua/yolocls.md +17 -12
- package/docs/apipython/hid.md +22 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=r;function c(t){t.vararg=!0,s(t.body.body)}function a(t){switch(t.type){case"FuncExpr":c(t);break;case"UnaryExpr":a(t.arg);break;case"BinaryExpr":a(t.left),a(t.right);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(t.object),a(t.index);break;case"MemberExpr":a(t.object);break;case"CallExpr":a(t.callee);for(const e of t.args)a(e);break;case"MethodCallExpr":a(t.object);for(const e of t.args)a(e);break;case"ParenExpr":a(t.exp);break;default:break}}function s(t){for(const e of t)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);s(e.body.body);break;case"IfStat":for(const o of e.clauses)a(o.cond),s(o.body.body);e.elseBody&&s(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":c(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 r(t){s(t.body)}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=s;const c=require("./parser");function r(n){return(n>>>0)%9e3+100}function s(n,o){const a=o>>>0,l=r(a),e=a%17+3,t=l*e,d=`
|
|
2
2
|
do
|
|
3
3
|
local valid = true
|
|
4
|
-
local acc = ${
|
|
5
|
-
if acc * ${e} ~= ${
|
|
4
|
+
local acc = ${l}
|
|
5
|
+
if acc * ${e} ~= ${t} then
|
|
6
6
|
valid = false
|
|
7
7
|
end
|
|
8
8
|
local ok = pcall(function()
|
|
9
|
-
return acc * ${e} == ${
|
|
9
|
+
return acc * ${e} == ${t}
|
|
10
10
|
end)
|
|
11
11
|
if not ok then
|
|
12
12
|
valid = false
|
|
@@ -23,4 +23,4 @@ do
|
|
|
23
23
|
error("Tamper Detected!")
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
-
`,
|
|
26
|
+
`,i=(0,c.parseLua)(d);n.body.unshift(...i.body)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=m,exports.foldEncrypt=
|
|
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(t){const e=t>>>0||1;return{mul45:e%15*4+1,add45:e%99991*2+1,mul8:i[e%i.length],secret8:e%256}}function f(t,e){t.p=(t.p*BigInt(e.mul45)+BigInt(e.add45))%d;do t.q=t.q*e.mul8%257;while(t.q===1);const o=Number(t.p%256n),l=Number(t.p/256n%256n),c=Number(t.p/65536n%256n);return(o+l*(t.q%13)+c+t.q)%256}function p(t,e){return{p:BigInt(e>>>0)%d,q:(e>>>0)%255+2}}function h(t){const e=[];for(let o=0;o<t.length;o+=1){const l=t.charCodeAt(o);if(l<=255)e.push(l);else{const c=Buffer.from(t[o],"utf8");for(const n of c)e.push(n)}}return Buffer.from(e)}function q(t,e,o){const l=h(t),c=p(e,o);let n=e.secret8,r="";for(let u=0;u<l.length;u+=1){const a=f(c,e),s=l[u];r+=String.fromCharCode((s-a-n+512)%256),n=s}return r}function g(t,e,o){const l=p(e,o);let c=e.secret8;const n=Buffer.alloc(t.length);for(let r=0;r<t.length;r+=1){const u=f(l,e),a=(t.charCodeAt(r)+u+c)%256;n[r]=a,c=a}return n.toString("latin1")}function b(t,e){return`local ${e}
|
|
2
2
|
do
|
|
3
3
|
local mul45=${t.mul45}
|
|
4
4
|
local add45=${t.add45}
|
|
@@ -1 +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}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileChunk=P;class O{constructor(){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"ops",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"consts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"protos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"upvals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"numparams",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"isVararg",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxStack",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"top",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"frames",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"labels",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"gotos",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"breaks",{enumerable:!0,configurable:!0,writable:!0,value:[]})}emit(n,t=0,o=0,s=0){return this.ops.push(n),this.code.push([0,t,o,s]),this.code.length-1}patch(n,t,o,s){const a=this.code[n];t!==void 0&&(a[1]=t),o!==void 0&&(a[2]=o),s!==void 0&&(a[3]=s)}kNil(){return this.intern({t:"nil"})}kBool(n){return this.intern({t:"bool",v:n})}kNum(n,t){return this.intern({t:"num",v:n,raw:t})}kStr(n){return this.intern({t:"str",v:n})}intern(n){for(let t=0;t<this.consts.length;t+=1){const o=this.consts[t];if(o.t===n.t&&(o.t==="nil"||o.t==="bool"&&n.t==="bool"&&o.v===n.v||o.t==="num"&&n.t==="num"&&o.v===n.v||o.t==="str"&&n.t==="str"&&o.v===n.v))return t+1}return this.consts.push(n),this.consts.length}alloc(n=1){const t=this.top;return this.top+=n,this.top-1>this.maxStack&&(this.maxStack=this.top-1),t}freeTo(n){this.top=n}pushFrame(){this.frames.push({locals:[],savedTop:this.top})}currentLocals(){return this.frames[this.frames.length-1]?.locals??[]}bind(n,t=!1){const o=this.alloc(1);return this.currentLocals().push({name:n,reg:o,close:t}),o}findLocal(n){for(let t=this.frames.length-1;t>=0;t-=1){const o=this.frames[t].locals;for(let s=o.length-1;s>=0;s-=1)if(o[s].name===n)return o[s].reg}}findUpval(n){for(let s=0;s<this.upvals.length;s+=1)if(this.upvals[s].name===n)return s+1;if(!this.parent)return;const t=this.parent.findLocal(n);if(t!==void 0)return this.upvals.push({name:n,inStack:!0,index:t}),this.upvals.length;const o=this.parent.findUpval(n);if(o!==void 0)return this.upvals.push({name:n,inStack:!1,index:o}),this.upvals.length}finish(){for(const n of this.gotos){const t=this.labels.get(n.name);if(t===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${n.name}::`);this.patch(n.pc,0,t-(n.pc+1))}return{code:this.code,ops:this.ops,consts:this.consts,protos:this.protos,upvals:this.upvals,numparams:this.numparams,isVararg:this.isVararg,maxStack:Math.max(this.maxStack,this.numparams,1)}}}const k={"+":"ADD","-":"SUB","*":"MUL","/":"DIV","//":"IDIV","%":"MOD","^":"POW","&":"BAND","|":"BOR","~":"BXOR","<<":"SHL",">>":"SHR","..":"CONCAT"},A={"-":"UNM","~":"BNOT",not:"NOT","#":"LEN"};function P(e){const n=new O;return n.isVararg=!0,n.pushFrame(),u(n,e.body),n.emit("RETURN",1,0),n.finish()}function d(e,n){const t=new O;t.parent=e,t.numparams=n.params.length,t.isVararg=n.vararg,t.pushFrame();for(const o of n.params)t.bind(o);return u(t,n.body.body),t.emit("RETURN",1,0),e.protos.push(t.finish()),e.protos.length}function u(e,n){for(const t of n)B(e,t)}function p(e,n){for(const t of n.locals)e.emit("CLOSE",t.reg);e.freeTo(n.savedTop)}function B(e,n){switch(n.type){case"EmptyStat":return;case"BreakStat":{if(e.breaks.length===0)throw new Error("break \u51FA\u73B0\u5728\u5FAA\u73AF\u5916");const t=e.emit("JMP",0,0);e.breaks[e.breaks.length-1].push(t);return}case"GotoStat":{const t=e.emit("JMP",0,0);e.gotos.push({name:n.name,pc:t});return}case"LabelStat":e.labels.set(n.name,e.code.length);return;case"DoStat":{e.pushFrame(),u(e,n.body.body),p(e,e.frames.pop());return}case"WhileStat":{const t=e.code.length,o=r(e,n.cond);e.emit("TEST",o,0,0);const s=e.emit("JMP",0,0);e.freeTo(o),e.breaks.push([]),e.pushFrame(),u(e,n.body.body),p(e,e.frames.pop()),e.emit("JMP",0,t-(e.code.length+1)),e.patch(s,0,e.code.length-(s+1)),f(e,e.breaks.pop(),e.code.length);return}case"RepeatStat":{const t=e.code.length;e.breaks.push([]),e.pushFrame(),u(e,n.body.body);const o=r(e,n.cond);e.emit("TEST",o,0,0),e.emit("JMP",0,t-(e.code.length+1)),p(e,e.frames.pop()),f(e,e.breaks.pop(),e.code.length);return}case"IfStat":{const t=[];for(let o=0;o<n.clauses.length;o+=1){const s=r(e,n.clauses[o].cond);e.emit("TEST",s,0,0);const a=e.emit("JMP",0,0);e.freeTo(s),e.pushFrame(),u(e,n.clauses[o].body.body),p(e,e.frames.pop()),(o<n.clauses.length-1||n.elseBody)&&t.push(e.emit("JMP",0,0)),e.patch(a,0,e.code.length-(a+1))}n.elseBody&&(e.pushFrame(),u(e,n.elseBody.body),p(e,e.frames.pop()));for(const o of t)e.patch(o,0,e.code.length-(o+1));return}case"ForNumStat":{const t=e.alloc(4);r(e,n.start,t),r(e,n.end,t+1),n.step?r(e,n.step,t+2):e.emit("LOADK",t+2,e.kNum(1,"1"));const o=e.emit("FORPREP",t,0);e.breaks.push([]),e.pushFrame();const s=e.bind(n.name);e.emit("MOVE",s,t+3),u(e,n.body.body),p(e,e.frames.pop());const a=e.emit("FORLOOP",t,0);e.patch(o,t,a-(o+1)),e.patch(a,t,o+1-(a+1)),f(e,e.breaks.pop(),e.code.length),e.freeTo(t);return}case"ForInStat":{const t=e.alloc(3);h(e,n.exps,t,3);const o=e.emit("TFORCALL",t,n.names.length),s=e.emit("TFORLOOP",t,0);e.breaks.push([]),e.pushFrame();for(let a=0;a<n.names.length;a+=1){const i=e.bind(n.names[a]);e.emit("MOVE",i,t+3+a)}u(e,n.body.body),p(e,e.frames.pop()),e.emit("JMP",0,o-(e.code.length+1)),e.patch(s,t,e.code.length-(s+1)),f(e,e.breaks.pop(),e.code.length),e.freeTo(t);return}case"FuncStat":{const t=d(e,n.func),o=e.alloc(1);e.emit("CLOSURE",o,t),w(e,n.name.base,n.name.fields,n.name.method,o),e.freeTo(o);return}case"LocalFuncStat":{const t=e.bind(n.name),o=d(e,n.func);e.emit("CLOSURE",t,o);return}case"LocalStat":{const t=n.names.length,o=[];if(n.exps&&n.exps.length>0){const s=e.top;h(e,n.exps,s,t);for(let a=0;a<t;a+=1){const i=e.bind(n.names[a].name,n.names[a].attr==="close");e.emit("MOVE",i,s+a),o.push(i)}e.freeTo(o[0]),e.top=o[t-1]+1}else for(const s of n.names){const a=e.bind(s.name,s.attr==="close");e.emit("LOADNIL",a),o.push(a)}return}case"AssignStat":{const t=e.top;h(e,n.exps,t,n.vars.length);for(let o=0;o<n.vars.length;o+=1)F(e,n.vars[o],t+o);e.freeTo(t);return}case"CallStat":{const t=e.top;r(e,n.exp,void 0,0),e.freeTo(t);return}case"ReturnStat":{if(n.exps.length===0){e.emit("RETURN",1,0);return}const t=e.top;h(e,n.exps,t,-1);const o=n.exps[n.exps.length-1],s=o.type==="CallExpr"||o.type==="MethodCallExpr"||o.type==="VarargExpr";e.emit("RETURN",t,s?-1:n.exps.length);return}}}function f(e,n,t){for(const o of n)e.patch(o,0,t-(o+1))}function w(e,n,t,o,s){if(t.length===0&&!o){S(e,n,s);return}let a=T(e,n);const i=o?[...t,o]:t;for(let c=0;c<i.length-1;c+=1){const l=e.alloc(1);e.emit("GETTABLE",l,a,-e.kStr(i[c])),a=l}e.emit("SETTABLE",a,-e.kStr(i[i.length-1]),s)}function S(e,n,t){const o=e.findLocal(n);if(o!==void 0){e.emit("MOVE",o,t);return}const s=e.findUpval(n);if(s!==void 0){e.emit("SETUPVAL",t,s);return}e.emit("SETGLOBAL",t,e.kStr(n))}function T(e,n,t){const o=t??e.alloc(1),s=e.findLocal(n);if(s!==void 0)return o!==s&&e.emit("MOVE",o,s),o;const a=e.findUpval(n);return a!==void 0?(e.emit("GETUPVAL",o,a),o):(e.emit("GETGLOBAL",o,e.kStr(n)),o)}function F(e,n,t){if(n.type==="NameExpr"){S(e,n.name,t);return}if(n.type==="MemberExpr"){const o=r(e,n.object);e.emit("SETTABLE",o,-e.kStr(n.field),t);return}if(n.type==="IndexExpr"){const o=r(e,n.object),s=r(e,n.index);e.emit("SETTABLE",o,s,t);return}throw new Error("\u975E\u6CD5\u8D4B\u503C\u5DE6\u503C")}function r(e,n,t,o=1){const s=t??e.alloc(1);switch(n.type){case"NilLiteral":return e.emit("LOADNIL",s),s;case"BoolLiteral":return e.emit("LOADBOOL",s,n.value?1:0),s;case"NumberLiteral":return e.emit("LOADK",s,e.kNum(n.value,n.raw)),s;case"StringLiteral":return e.emit("LOADK",s,e.kStr(n.value)),s;case"VarargExpr":return e.emit("VARARG",s,o),s;case"NameExpr":return T(e,n.name,s);case"ParenExpr":return r(e,n.exp,s,1);case"UnaryExpr":{const a=r(e,n.arg);return e.emit(A[n.op],s,a),s}case"BinaryExpr":return M(e,n.op,n.left,n.right,s);case"FuncExpr":{const a=d(e,n);return e.emit("CLOSURE",s,a),s}case"TableExpr":return R(e,n.fields,s);case"IndexExpr":{const a=r(e,n.object),i=r(e,n.index);return e.emit("GETTABLE",s,a,i),s}case"MemberExpr":{const a=r(e,n.object);return e.emit("GETTABLE",s,a,-e.kStr(n.field)),s}case"CallExpr":return y(e,n.callee,n.args,s,o,!1);case"MethodCallExpr":return y(e,n.object,n.args,s,o,n.method);default:throw new Error(`\u4E0D\u652F\u6301\u7684\u8868\u8FBE\u5F0F ${n.type}`)}}function M(e,n,t,o,s){if(n==="and"||n==="or"){r(e,t,s),e.emit("TEST",s,0,n==="and"?0:1);const l=e.emit("JMP",0,0);return r(e,o,s),e.patch(l,0,e.code.length-(l+1)),s}if(n==="=="||n==="~="||n==="<"||n===">"||n==="<="||n===">="){const l=r(e,t),b=r(e,o);let m="EQ",g=l,E=b;n==="<"||n===">="?m="LT":n==="<="||n===">"?m="LE":m="EQ",(n===">"||n===">=")&&(g=b,E=l);const x=n==="~=";e.emit(m,g,E,x?1:0);const L=e.emit("JMP",0,0);e.emit("LOADBOOL",s,1);const v=e.emit("JMP",0,0);return e.patch(L,0,e.code.length-(L+1)),e.emit("LOADBOOL",s,0),e.patch(v,0,e.code.length-(v+1)),s}const a=k[n];if(!a)throw new Error(`\u4E0D\u652F\u6301\u7684\u8FD0\u7B97\u7B26 ${n}`);const i=r(e,t),c=r(e,o);return e.emit(a,s,i,c),s}function N(e){return e.type==="CallExpr"||e.type==="MethodCallExpr"||e.type==="VarargExpr"}function y(e,n,t,o,s,a){const i=o,c=t.length>0&&N(t[t.length-1]);if(a){const l=r(e,n,i);return e.emit("SELF",i,l,-e.kStr(a)),h(e,t,i+2,-1),e.emit("CALL",i,c?-1:t.length+1,s),i}return r(e,n,i),h(e,t,i+1,-1),e.emit("CALL",i,c?-1:t.length,s),i}function h(e,n,t,o){const s=o>0?o:Math.max(n.length,1);if(e.top<t+s&&(e.top=t+s,e.top-1>e.maxStack&&(e.maxStack=e.top-1)),n.length===0){if(o>0)for(let a=0;a<o;a+=1)e.emit("LOADNIL",t+a);return}for(let a=0;a<n.length;a+=1){const i=a===n.length-1,c=i&&(o<0||o>n.length)?o===-1?-1:o-a:1;r(e,n[a],t+a,i?c:1)}if(o>n.length)for(let a=n.length;a<o;a+=1)e.emit("LOADNIL",t+a)}function R(e,n,t){e.emit("NEWTABLE",t);const o=[];for(const s of n)if(s.kind==="list")o.push(s.value);else if(s.kind==="name"){const a=r(e,s.value);e.emit("SETTABLE",t,-e.kStr(s.key),a)}else{const a=r(e,s.key),i=r(e,s.value);e.emit("SETTABLE",t,a,i)}if(o.length>0){const s=e.top;h(e,o,s,-1),e.emit("SETLIST",t,s,o.length),e.freeTo(s)}return t}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyConstantArray=h;const o=require("./visit"),s="__C",y="__G";function g(l,i){const n=l.slice();let a=i>>>0||1;for(let r=n.length-1;r>0;r-=1){a=Math.imul(a,1664525)+1013904223>>>0;const t=a%(r+1),p=n[r];n[r]=n[t],n[t]=p}return n}function h(l,i,n){const a=[],r=new Set;if((0,o.mapChunk)(l,e=>(e.type==="StringLiteral"&&!r.has(e.value)&&(r.add(e.value),a.push(e.value)),e)),a.length===0)return;let t=n.shuffle?g(a,i):a.slice();const p=n.rotate?i%t.length:0;p>0&&(t=t.slice(p).concat(t.slice(0,p)));const c=new Map;for(let e=0;e<t.length;e+=1)c.set(t[e],e+1);(0,o.mapChunk)(l,e=>{if(e.type!=="StringLiteral")return e;const u=c.get(e.value);return u===void 0?e:{type:"CallExpr",callee:{type:"NameExpr",name:y},args:[{type:"NumberLiteral",raw:String(u),value:u}]}});const m=t.map(e=>({kind:"list",value:{type:"StringLiteral",value:e,encoded:!0}})),d={type:"LocalStat",names:[{name:s}],exps:[{type:"TableExpr",fields:m}]},f={type:"LocalFuncStat",name:y,func:{type:"FuncExpr",params:["i"],vararg:!1,body:{type:"Block",body:[{type:"ReturnStat",exps:[{type:"IndexExpr",object:{type:"NameExpr",name:s},index:{type:"NameExpr",name:"i"}}]}]}}};l.body.unshift(d,f)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(e){return{type:"NumberLiteral",raw:String(e),value:e}}function y(e){return{type:"NameExpr",name:e}}function b(e,t){return{type:"AssignStat",vars:e.map(a=>y(a)),exps:t}}function u(e,t){return b([e.stateName],[typeof t=="number"?m(t):t])}function k(e,t,a){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:y(e),right:m(t)},right:m(a)}}function E(e,t,a){return{type:"BinaryExpr",op:e,left:t,right:a}}function S(e){const t=`__t${e.nextTemp}`;return e.nextTemp+=1,e.temps.push(t),t}function x(e){const t=e.nextState;return e.nextState+=1,e.states.set(t,[]),t}function r(e,t,a){e.states.get(t).push(a)}function L(e,t){for(const a of e)if(a.type==="LocalStat")for(const o of a.names)t.push(o.name);else if(a.type==="LocalFuncStat")t.push(a.name);else if(a.type==="ForNumStat")t.push(a.name),L(a.body.body,t);else if(a.type==="ForInStat")t.push(...a.names),L(a.body.body,t);else if(a.type==="DoStat"||a.type==="WhileStat"||a.type==="RepeatStat")L(a.body.body,t);else if(a.type==="IfStat"){for(const o of a.clauses)L(o.body.body,t);a.elseBody&&L(a.elseBody.body,t)}}function h(e,t,a,o){if(e.length===0)return t;const p=e.map(()=>x(a));for(let n=0;n<e.length;n+=1){const c=e[n];c.type==="LabelStat"&&a.userLabels.set(c.name,p[n])}for(let n=0;n<e.length;n+=1){const c=n+1<e.length?p[n+1]:t;I(a,p[n],e[n],c,o)}return p[0]}function I(e,t,a,o,p){switch(a.type){case"EmptyStat":case"LabelStat":r(e,t,u(e,o));return;case"AssignStat":case"CallStat":case"FuncStat":r(e,t,a),r(e,t,u(e,o));return;case"LocalStat":a.exps&&a.exps.length>0&&r(e,t,b(a.names.map(n=>n.name),a.exps)),r(e,t,u(e,o));return;case"LocalFuncStat":r(e,t,b([a.name],[a.func])),r(e,t,u(e,o));return;case"ReturnStat":r(e,t,a);return;case"BreakStat":r(e,t,u(e,p));return;case"GotoStat":{const n=e.userLabels.get(a.name);if(n===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${a.name}::`);r(e,t,u(e,n));return}case"DoStat":r(e,t,u(e,h(a.body.body,o,e,p)));return;case"IfStat":{const n=S(e);let c=t;for(let l=0;l<a.clauses.length;l+=1){const f=l===a.clauses.length-1,d=h(a.clauses[l].body.body,o,e,p);let i=o;f?a.elseBody&&(i=h(a.elseBody.body,o,e,p)):i=x(e),r(e,c,b([n],[a.clauses[l].cond])),r(e,c,u(e,k(n,d,i))),f||(c=i)}a.clauses.length===0&&r(e,t,u(e,o));return}case"WhileStat":{const n=S(e),c=h(a.body.body,t,e,o);r(e,t,b([n],[a.cond])),r(e,t,u(e,k(n,c,o)));return}case"RepeatStat":{const n=S(e),c=x(e),l=h(a.body.body,c,e,o);r(e,t,u(e,l)),r(e,c,b([n],[a.cond])),r(e,c,u(e,k(n,o,l)));return}case"ForNumStat":{const n=a.name,c=S(e),l=S(e),f=S(e),d=x(e),i=x(e),F=x(e),g=x(e),N=h(a.body.body,g,e,o);r(e,t,b([n],[a.start])),r(e,t,b([c],[a.end])),r(e,t,b([l],[a.step??m(1)])),r(e,t,u(e,d)),r(e,d,b([f],[E(">=",y(l),m(0))])),r(e,d,u(e,k(f,i,F))),r(e,i,b([f],[E("<=",y(n),y(c))])),r(e,i,u(e,k(f,N,o))),r(e,F,b([f],[E(">=",y(n),y(c))])),r(e,F,u(e,k(f,N,o))),r(e,g,b([n],[E("+",y(n),y(l))])),r(e,g,u(e,d));return}case"ForInStat":{const n=S(e),c=S(e),l=S(e),f=S(e),d=x(e),i=[b([l],[y(a.names[0])]),...a.body.body],F=h(i,d,e,o),g=a.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});r(e,t,b([n,c,l],g.slice(0,3))),r(e,t,u(e,d)),r(e,d,{type:"AssignStat",vars:a.names.map(N=>y(N)),exps:[{type:"CallExpr",callee:y(n),args:[y(c),y(l)]}]}),r(e,d,b([f],[E("~=",y(a.names[0]),{type:"NilLiteral"})])),r(e,d,u(e,k(f,F,o)));return}default:r(e,t,u(e,o))}}function v(e,t){const a=e.slice();let o=t>>>0||1;for(let p=a.length-1;p>0;p-=1){o=Math.imul(o,1664525)+1013904223>>>0;const n=o%(p+1),c=a[p];a[p]=a[n],a[n]=c}return a}function w(e,t){if(e.length===0)return e;const a={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},o=[];L(e,o);const p=h(e,0,a,0),n=[...new Set([...o,...a.temps,a.stateName])],c=v([...a.states.keys()],t).map(l=>({cond:E("==",y(a.stateName),m(l)),body:{type:"Block",body:a.states.get(l)}}));return[{type:"LocalStat",names:n.map(l=>({name:l}))},b([a.stateName],[m(p)]),{type:"WhileStat",cond:E("~=",y(a.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:c}]}}]}function s(e,t){switch(e.type){case"FuncExpr":B(e.body.body,t),e.body.body=w(e.body.body,t);break;case"UnaryExpr":s(e.arg,t);break;case"BinaryExpr":s(e.left,t),s(e.right,t);break;case"TableExpr":for(const a of e.fields)a.kind==="index"&&s(a.key,t),s(a.value,t);break;case"IndexExpr":s(e.object,t),s(e.index,t);break;case"MemberExpr":s(e.object,t);break;case"CallExpr":s(e.callee,t);for(const a of e.args)s(a,t);break;case"MethodCallExpr":s(e.object,t);for(const a of e.args)s(a,t);break;case"ParenExpr":s(e.exp,t);break;default:break}}function B(e,t){for(const a of e)switch(a.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((a.type==="WhileStat"||a.type==="RepeatStat")&&s(a.cond,t),a.type==="ForNumStat"&&(s(a.start,t),s(a.end,t),a.step&&s(a.step,t)),a.type==="ForInStat")for(const o of a.exps)s(o,t);B(a.body.body,t);break;case"IfStat":for(const o of a.clauses)s(o.cond,t),B(o.body.body,t);a.elseBody&&B(a.elseBody.body,t);break;case"FuncStat":case"LocalFuncStat":B(a.func.body.body,t),a.func.body.body=w(a.func.body.body,t);break;case"LocalStat":if(a.exps)for(const o of a.exps)s(o,t);break;case"AssignStat":for(const o of a.vars)s(o,t);for(const o of a.exps)s(o,t);break;case"CallStat":s(a.exp,t);break;case"ReturnStat":for(const o of a.exps)s(o,t);break;default:break}}function C(e,t){B(e.body,t),e.body=w(e.body,t)}
|
|
@@ -1 +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=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFoldMixParams=exports.foldEncrypt=exports.foldDecrypt=exports.LuaParseError=exports.LuaLexError=exports.luaObfuscatorPresets=void 0,exports.obfuscateLua=E;const l=require("./addVararg"),f=require("./antiTamper"),b=require("./compiler"),y=require("./constantArray"),n=require("./flatten"),c=require("./minify"),a=require("./numbers"),p=require("./parser"),m=require("./rename"),d=require("./splitStrings"),L=require("./vmEmit"),q=require("./wrapInFunction");exports.luaObfuscatorPresets=["Minify","Weak","Medium","Strong"];function P(t){let u=2166136261;for(let r=0;r<t.length;r+=1)u=Math.imul(u^t.charCodeAt(r),16777619);return u>>>0||1}function o(t){return(0,p.parseLua)((0,L.emitVm)((0,b.compileChunk)(t)))}function i(t,u,r){(0,y.applyConstantArray)(t,u,{shuffle:r.shuffle,rotate:r.shuffle}),r.numbersOnVm&&(0,a.numbersToExpressions)(t,(u^2654435769)>>>0);for(let e=0;e<r.wraps;e+=1)(0,q.wrapInFunction)(t);return(0,m.renameLocals)(t),(0,c.minifyLua)(t)}function E(t,u){const r=P(t);let e=(0,p.parseLua)(t);return(0,m.renameLocals)(e),u==="Minify"?(0,c.minifyLua)(e):u==="Weak"?((0,n.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!1,wraps:1,numbersOnVm:!1})):u==="Medium"?((0,l.addVararg)(e),(0,d.splitStrings)(e,r),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,r),(0,n.flattenControlFlow)(e,r),e=o(e),i(e,r,{shuffle:!0,wraps:1,numbersOnVm:!0})):((0,l.addVararg)(e),(0,d.splitStrings)(e,(r^2135587861)>>>0),(0,a.numbersToExpressions)(e,r),(0,f.applyAntiTamper)(e,(r^2246822507)>>>0),(0,n.flattenControlFlow)(e,(r^2246822507)>>>0),e=o(e),i(e,r,{shuffle:!0,wraps:2,numbersOnVm:!0}))}var O=require("./lexer");Object.defineProperty(exports,"LuaLexError",{enumerable:!0,get:function(){return O.LuaLexError}});var g=require("./parser");Object.defineProperty(exports,"LuaParseError",{enumerable:!0,get:function(){return g.LuaParseError}});var s=require("./strings");Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return s.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return s.foldEncrypt}}),Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return s.createFoldMixParams}});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=
|
|
2
|
-
`?(
|
|
3
|
-
`||e==="\f"||e==="\v",
|
|
4
|
-
`&&
|
|
5
|
-
`;)
|
|
6
|
-
`)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(r!=="\\"){
|
|
7
|
-
`;else if(
|
|
8
|
-
`)
|
|
9
|
-
`&&
|
|
10
|
-
`;else if(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaLexError=void 0,exports.lexLua=y;const L=require("./reserved");class F extends Error{constructor(s,l,c){super(`${s} (${l}:${c})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:c}),this.name="LuaLexError"}}exports.LuaLexError=F;function y(v){const s=v.replace(/^\uFEFF/,""),l=[];let c=0,m=1,d=1;const n=(e=0)=>s[c+e]??"",h=()=>c>=s.length,u=()=>{const e=s[c++];return e===`
|
|
2
|
+
`?(m+=1,d=1):d+=1,e},a=e=>{throw new F(e,m,d)},b=e=>e>="A"&&e<="Z"||e>="a"&&e<="z"||e==="_",E=e=>e>="0"&&e<="9",p=e=>E(e)||e>="a"&&e<="f"||e>="A"&&e<="F",C=e=>{const t=Buffer.from(e,"utf8");let r="";for(const i of t)r+=String.fromCharCode(i);return r},g=e=>e===" "||e===" "||e==="\r"||e===`
|
|
3
|
+
`||e==="\f"||e==="\v",B=e=>{if(s[e]!=="[")return-1;let t=0,r=e+1;for(;s[r]==="=";)t+=1,r+=1;return s[r]==="["?t:-1},k=e=>{u();for(let r=0;r<e;r+=1)u();u(),n()==="\r"&&u(),n()===`
|
|
4
|
+
`&&u();let t="";for(;!h();){if(n()==="]"){let r=c+1,i=0;for(;s[r]==="=";)i+=1,r+=1;if(i===e&&s[r]==="]"){u();for(let o=0;o<e;o+=1)u();return u(),t}}t+=C(u())}return a("\u672A\u95ED\u5408\u7684\u957F\u62EC\u53F7\u5B57\u7B26\u4E32\u6216\u6CE8\u91CA")},w=()=>{for(;!h()&&n()!==`
|
|
5
|
+
`;)u()},A=e=>{u();let t="";for(;!h();){const r=n();if(r===e)return u(),t;if(r===`
|
|
6
|
+
`)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(r!=="\\"){t+=C(u());continue}u();const i=n();if(i==="a")u(),t+="\x07";else if(i==="b")u(),t+="\b";else if(i==="f")u(),t+="\f";else if(i==="n")u(),t+=`
|
|
7
|
+
`;else if(i==="r")u(),t+="\r";else if(i==="t")u(),t+=" ";else if(i==="v")u(),t+="\v";else if(i==="\\"||i==='"'||i==="'"||i===`
|
|
8
|
+
`)t+=u();else if(i==="\r")u(),n()===`
|
|
9
|
+
`&&u(),t+=`
|
|
10
|
+
`;else if(i==="x"){u();const o=n(),f=n(1);if(!p(o)||!p(f))return a("\u65E0\u6548\u7684 \\x \u8F6C\u4E49");u(),u(),t+=String.fromCharCode(parseInt(o+f,16))}else if(i==="u"){if(u(),n()!=="{")return a("\u65E0\u6548\u7684 \\u \u8F6C\u4E49");u();let o="";for(;p(n());)o+=u();if(n()!=="}"||o.length===0)return a("\u65E0\u6548\u7684 \\u{...} \u8F6C\u4E49");u(),t+=C(String.fromCodePoint(parseInt(o,16)))}else if(i==="z")for(u();g(n());)u();else if(E(i)){let o="";for(;E(n())&&o.length<3;)o+=u();const f=parseInt(o,10);if(f>255)return a("\u5341\u8FDB\u5236\u8F6C\u4E49\u8D85\u8FC7 255");t+=String.fromCharCode(f)}else return a(`\u65E0\u6548\u7684\u8F6C\u4E49\u5E8F\u5217 \\${i}`)}return a("\u672A\u95ED\u5408\u7684\u77ED\u5B57\u7B26\u4E32")},D=()=>{const e=m,t=d;let r="";if(n()==="0"&&(n(1)==="x"||n(1)==="X")){for(r+=u(),r+=u();p(n())||n()===".";)r+=u();if(n()==="p"||n()==="P")for(r+=u(),(n()==="+"||n()==="-")&&(r+=u());E(n());)r+=u()}else{for(;E(n())||n()===".";)r+=u();if(n()==="e"||n()==="E")for(r+=u(),(n()==="+"||n()==="-")&&(r+=u());E(n());)r+=u()}const i=Number(r);if(!Number.isFinite(i))throw new F(`\u65E0\u6548\u6570\u5B57 ${r}`,e,t);return{kind:"number",value:r,line:e,column:t,parsed:i}};for(;!h();){const e=n();if(g(e)){u();continue}if(e==="-"&&n(1)==="-"){const f=m,$=d;u(),u();const x=B(c);x>=0?k(x):w();continue}const t=m,r=d;if(e==="'"||e==='"'){const f=A(e);l.push({kind:"string",value:f,line:t,column:r,parsed:f});continue}const i=B(c);if(i>=0){const f=k(i);l.push({kind:"string",value:f,line:t,column:r,parsed:f});continue}if(E(e)||e==="."&&E(n(1))){l.push(D());continue}if(b(e)){let f="";for(;b(n())||E(n());)f+=u();l.push({kind:L.luaKeywords.has(f)?"keyword":"name",value:f,line:t,column:r});continue}const o=e+n(1);if(o+n(2)==="..."){u(),u(),u(),l.push({kind:"vararg",value:"...",line:t,column:r});continue}if(["//","<<",">>","==","~=","<=",">=","..","::"].includes(o)){u(),u(),l.push({kind:o,value:o,line:t,column:r});continue}if(["+","-","*","/","%","^","#","&","|","~","<",">","=","(",")","{","}","[","]",";",":",",","."].includes(e)){u(),l.push({kind:e,value:e,line:t,column:r});continue}a(`\u975E\u6CD5\u5B57\u7B26 ${JSON.stringify(e)}`)}return l.push({kind:"eof",value:"",line:m,column:d}),l}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeLuaString=e,exports.minifyLua=w;const l=new Set(["and","or"]);function e(t){let r='"';for(let a=0;a<t.length;a+=1){const u=t.charCodeAt(a)&255;r+=`\\${String(u).padStart(3,"0")}`}return r+='"',r}class i{constructor(){Object.defineProperty(this,"parts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"last",{enumerable:!0,configurable:!0,writable:!0,value:"none"})}word(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="word"}num(r){(this.last==="word"||this.last==="num")&&this.parts.push(" "),this.parts.push(r),this.last="num"}punct(r){r===".."&&this.last==="num"&&this.parts.push(" "),r==="="&&this.parts[this.parts.length-1]===">"&&this.parts.push(" "),this.parts.push(r),this.last="punct"}toString(){return this.parts.join("")}}function w(t){const r=new i;return d(r,t.body,!0),r.toString()}function s(t,r){d(t,r.body,!1)}function d(t,r,a){for(let u=0;u<r.length;u+=1)h(t,r[u]),u<r.length-1&&t.punct(";")}function h(t,r){switch(r.type){case"EmptyStat":t.punct(";");return;case"BreakStat":t.word("break");return;case"GotoStat":t.word("goto"),t.word(r.name);return;case"LabelStat":t.punct("::"),t.word(r.name),t.punct("::");return;case"DoStat":t.word("do"),s(t,r.body),t.word("end");return;case"WhileStat":t.word("while"),o(t,r.cond),t.word("do"),s(t,r.body),t.word("end");return;case"RepeatStat":t.word("repeat"),s(t,r.body),t.word("until"),o(t,r.cond);return;case"IfStat":for(let a=0;a<r.clauses.length;a+=1)t.word(a===0?"if":"elseif"),o(t,r.clauses[a].cond),t.word("then"),s(t,r.clauses[a].body);r.elseBody&&(t.word("else"),s(t,r.elseBody)),t.word("end");return;case"ForNumStat":t.word("for"),t.word(r.name),t.punct("="),o(t,r.start),t.punct(","),o(t,r.end),r.step&&(t.punct(","),o(t,r.step)),t.word("do"),s(t,r.body),t.word("end");return;case"ForInStat":t.word("for");for(let a=0;a<r.names.length;a+=1)a>0&&t.punct(","),t.word(r.names[a]);t.word("in"),c(t,r.exps),t.word("do"),s(t,r.body),t.word("end");return;case"FuncStat":t.word("function"),t.word(r.name.base);for(const a of r.name.fields)t.punct("."),t.word(a);r.name.method&&(t.punct(":"),t.word(r.name.method)),p(t,r.func,!!r.name.method);return;case"LocalFuncStat":t.word("local"),t.word("function"),t.word(r.name),p(t,r.func,!1);return;case"LocalStat":t.word("local");for(let a=0;a<r.names.length;a+=1)a>0&&t.punct(","),t.word(r.names[a].name),r.names[a].attr&&(t.punct("<"),t.word(r.names[a].attr),t.punct(">"));r.exps&&r.exps.length>0&&(t.punct("="),c(t,r.exps));return;case"AssignStat":c(t,r.vars),t.punct("="),c(t,r.exps);return;case"CallStat":o(t,r.exp);return;case"ReturnStat":t.word("return"),r.exps.length>0&&c(t,r.exps);return}}function p(t,r,a){t.punct("(");const u=a?r.params.filter(n=>n!=="self"):r.params;for(let n=0;n<u.length;n+=1)n>0&&t.punct(","),t.word(u[n]);r.vararg&&(u.length>0&&t.punct(","),t.punct("...")),t.punct(")"),s(t,r.body),t.word("end")}function c(t,r){for(let a=0;a<r.length;a+=1)a>0&&t.punct(","),o(t,r[a])}function o(t,r){switch(r.type){case"NilLiteral":t.word("nil");return;case"BoolLiteral":t.word(r.value?"true":"false");return;case"NumberLiteral":t.num(r.raw);return;case"StringLiteral":t.punct(e(r.value));return;case"VarargExpr":t.punct("...");return;case"NameExpr":t.word(r.name);return;case"UnaryExpr":r.op==="not"?t.word("not"):t.punct(r.op),o(t,r.arg);return;case"BinaryExpr":o(t,r.left),l.has(r.op)?t.word(r.op):t.punct(r.op),o(t,r.right);return;case"FuncExpr":t.word("function"),p(t,r,!1);return;case"TableExpr":t.punct("{");for(let a=0;a<r.fields.length;a+=1)a>0&&t.punct(","),f(t,r.fields[a]);t.punct("}");return;case"IndexExpr":o(t,r.object),t.punct("["),o(t,r.index),t.punct("]");return;case"MemberExpr":o(t,r.object),t.punct("."),t.word(r.field);return;case"CallExpr":o(t,r.callee),t.punct("("),c(t,r.args),t.punct(")");return;case"MethodCallExpr":o(t,r.object),t.punct(":"),t.word(r.method),t.punct("("),c(t,r.args),t.punct(")");return;case"ParenExpr":t.punct("("),o(t,r.exp),t.punct(")");return}}function f(t,r){if(r.kind==="index"){t.punct("["),o(t,r.key),t.punct("]"),t.punct("="),o(t,r.value);return}if(r.kind==="name"){t.word(r.key),t.punct("="),o(t,r.value);return}o(t,r.value)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.numbersToExpressions=o;const y=require("./visit");function l(e,a){const t=Math.abs(a)%9+2,r=e-t;if(e<0)return{type:"UnaryExpr",op:"-",arg:l(-e,a+3)};if(e<=2)return{type:"NumberLiteral",raw:String(e),value:e};if(a%3===0){const p=e%7+2,i=Math.floor(e/p),n=e-p*i,u={type:"BinaryExpr",op:"*",left:{type:"NumberLiteral",raw:String(p),value:p},right:{type:"NumberLiteral",raw:String(i),value:i}};return n===0?{type:"ParenExpr",exp:u}:{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:u,right:{type:"NumberLiteral",raw:String(n),value:n}}}}return{type:"ParenExpr",exp:{type:"BinaryExpr",op:"+",left:{type:"NumberLiteral",raw:String(t),value:t},right:{type:"NumberLiteral",raw:String(r),value:r}}}}function o(e,a){let t=0;(0,y.mapChunk)(e,r=>r.type!=="NumberLiteral"||!Number.isInteger(r.value)||!Number.isSafeInteger(r.value)?r:(t+=1,l(r.value,a+t*17)))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OPCODE_NAMES=void 0,exports.shuffleOpcodes=t,exports.OPCODE_NAMES=["MOVE","LOADK","LOADBOOL","LOADNIL","GETGLOBAL","SETGLOBAL","GETTABLE","SETTABLE","NEWTABLE","SELF","ADD","SUB","MUL","DIV","IDIV","MOD","POW","BAND","BOR","BXOR","SHL","SHR","UNM","BNOT","NOT","LEN","CONCAT","JMP","EQ","LT","LE","TEST","CALL","RETURN","FORPREP","FORLOOP","TFORCALL","TFORLOOP","CLOSURE","VARARG","SETLIST","GETUPVAL","SETUPVAL","CLOSE"];function t(e){const E=exports.OPCODE_NAMES.map((O,L)=>L+1);let A=e>>>0||1;for(let O=E.length-1;O>0;O-=1){A=Math.imul(A,1664525)+1013904223>>>0;const L=A%(O+1),S=E[O];E[O]=E[L],E[L]=S}const T={};for(let O=0;O<exports.OPCODE_NAMES.length;O+=1)T[exports.OPCODE_NAMES[O]]=E[O];return T}
|
|
@@ -1 +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(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LuaParseError=void 0,exports.parseLua=te;const Z=require("./ast"),ee=require("./lexer");class j extends Error{constructor(b,l,p){super(`${b} (${l}:${p})`),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:p}),this.name="LuaParseError"}}exports.LuaParseError=j;function te(E){const b=(0,ee.lexLua)(E);let l=0;const p=()=>b[l],u=(e,t)=>{const n=p();return!(n.kind!==e||t!==void 0&&n.value!==t)},w=e=>u("keyword",e),h=e=>{const t=p();throw new j(e,t.line,t.column)},r=(e,t)=>{const n=p();return n.kind!==e||t!==void 0&&n.value!==t?h(`\u671F\u671B ${t??e}\uFF0C\u5B9E\u9645 ${n.value||n.kind}`):(l+=1,n)},o=(e,t)=>{if(u(e,t)){const n=p();return l+=1,n}},a=e=>w(e)?(l+=1,!0):!1,s=()=>r("name").value,c=e=>{const t=[];for(;!u("eof")&&!(p().kind==="keyword"&&e.includes(p().value));){if(w("return")){t.push($()),o(";");break}const n=D();n&&t.push(n)}return{type:"Block",body:t}},$=()=>(r("keyword","return"),u("eof")||u(";")||p().kind==="keyword"&&["end","else","elseif","until"].includes(p().value)?{type:"ReturnStat",exps:[]}:{type:"ReturnStat",exps:k()}),D=()=>{if(o(";"))return{type:"EmptyStat"};if(a("break"))return{type:"BreakStat"};if(a("goto"))return{type:"GotoStat",name:s()};if(a("do")){const e=c(["end"]);return r("keyword","end"),{type:"DoStat",body:e}}if(a("while")){const e=i();r("keyword","do");const t=c(["end"]);return r("keyword","end"),{type:"WhileStat",cond:e,body:t}}if(a("repeat")){const e=c(["until"]);r("keyword","until");const t=i();return{type:"RepeatStat",body:e,cond:t}}if(a("if"))return N();if(a("for"))return U();if(a("function")){const e=I(),t=v(!!e.method);return{type:"FuncStat",name:e,func:t}}if(a("local")){if(a("function")){const e=s(),t=v(!1);return{type:"LocalFuncStat",name:e,func:t}}return M()}if(u("::")){r("::");const e=s();return r("::"),{type:"LabelStat",name:e}}return O()},N=()=>{const e=[],t=i();for(r("keyword","then"),e.push({cond:t,body:c(["elseif","else","end"])});a("elseif");){const d=i();r("keyword","then"),e.push({cond:d,body:c(["elseif","else","end"])})}let n;return a("else")&&(n=c(["end"])),r("keyword","end"),{type:"IfStat",clauses:e,elseBody:n}},U=()=>{const e=s();if(o("=")){const m=i();r(",");const g=i();let P;o(",")&&(P=i()),r("keyword","do");const Y=c(["end"]);return r("keyword","end"),{type:"ForNumStat",name:e,start:m,end:g,step:P,body:Y}}const t=[e];for(;o(",");)t.push(s());r("keyword","in");const n=k();r("keyword","do");const d=c(["end"]);return r("keyword","end"),{type:"ForInStat",names:t,exps:n,body:d}},I=()=>{const e=s(),t=[];for(;o(".");)t.push(s());let n;return o(":")&&(n=s()),{base:e,fields:t,method:n}},v=e=>{r("(");const t=[];e&&t.push("self");let n=!1;if(!u(")"))if(u("vararg"))r("vararg"),n=!0;else for(t.push(s());o(",");){if(u("vararg")){r("vararg"),n=!0;break}t.push(s())}r(")");const d=c(["end"]);return r("keyword","end"),{type:"FuncExpr",params:t,vararg:n,body:d}},M=()=>{const e=[S()];for(;o(",");)e.push(S());let t;return o("=")&&(t=k()),{type:"LocalStat",names:e,exps:t}},S=()=>{const e=s();if(o("<")){const t=s();return r(">"),t!=="const"&&t!=="close"&&h(`\u672A\u77E5\u5C5E\u6027 <${t}>`),{name:e,attr:t}}return{name:e}},O=()=>{const e=x();if(u("=")||u(",")){const t=[e];for(;o(",");)t.push(x());r("=");const n=k();return{type:"AssignStat",vars:t,exps:n}}return(0,Z.isCallExpression)(e)?{type:"CallStat",exp:e}:h("\u8BED\u53E5\u5FC5\u987B\u662F\u8D4B\u503C\u6216\u51FD\u6570\u8C03\u7528")},k=()=>{const e=[i()];for(;o(",");)e.push(i());return e},i=()=>R(),y=(e,t)=>{let n=e();for(;;){const d=p(),m=d.kind==="keyword"?d.value:d.kind;if(!t.includes(m))break;l+=1;const g=e();n={type:"BinaryExpr",op:m,left:n,right:g}}return n},R=()=>y(q,["or"]),q=()=>y(A,["and"]),A=()=>y(_,["<",">","<=",">=","~=","=="]),_=()=>y(G,["|"]),G=()=>y(T,["~"]),T=()=>y(V,["&"]),V=()=>y(B,["<<",">>"]),B=()=>{const e=W();return u("..")?(l+=1,{type:"BinaryExpr",op:"..",left:e,right:B()}):e},W=()=>y(z,["+","-"]),z=()=>y(f,["*","/","//","%"]),f=()=>a("not")?{type:"UnaryExpr",op:"not",arg:f()}:o("#")?{type:"UnaryExpr",op:"#",arg:f()}:o("-")?{type:"UnaryExpr",op:"-",arg:f()}:o("~")?{type:"UnaryExpr",op:"~",arg:f()}:H(),H=()=>{const e=J();return u("^")?(l+=1,{type:"BinaryExpr",op:"^",left:e,right:f()}):e},J=()=>{if(a("nil"))return{type:"NilLiteral"};if(a("true"))return{type:"BoolLiteral",value:!0};if(a("false"))return{type:"BoolLiteral",value:!1};if(u("number")){const e=r("number");return{type:"NumberLiteral",raw:e.value,value:e.parsed}}if(u("string"))return{type:"StringLiteral",value:r("string").parsed};if(o("vararg"))return{type:"VarargExpr"};if(a("function"))return v(!1);if(u("{")){let e=C();return e=F(e),e}return x()},F=e=>{let t=e;for(;;){if(o(".")){t={type:"MemberExpr",object:t,field:s()};continue}if(o("[")){const n=i();r("]"),t={type:"IndexExpr",object:t,index:n};continue}if(o(":")){const n=s(),d=L();t={type:"MethodCallExpr",object:t,method:n,args:d};continue}if(u("(")||u("{")||u("string")){t={type:"CallExpr",callee:t,args:L()};continue}break}return t},x=()=>F(K()),K=()=>{if(o("(")){const e=i();return r(")"),{type:"ParenExpr",exp:e}}return u("name")?{type:"NameExpr",name:s()}:h("\u671F\u671B\u8868\u8FBE\u5F0F")},L=()=>{if(u("string"))return[{type:"StringLiteral",value:r("string").parsed}];if(u("{"))return[C()];if(r("("),o(")"))return[];const e=k();return r(")"),e},C=()=>{r("{");const e=[];for(;!u("}")&&(e.push(Q()),!(!o(",")&&!o(";"))););return r("}"),{type:"TableExpr",fields:e}},Q=()=>{if(o("[")){const e=i();return r("]"),r("="),{kind:"index",key:e,value:i()}}if(u("name")&&b[l+1]?.kind==="="){const e=s();return r("="),{kind:"name",key:e,value:i()}}return{kind:"list",value:i()}},X=c([]);return r("eof"),{type:"Chunk",body:X.body}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=o,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function o(a){let e=a,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function c(a){let e=0;const t=new Set;(0,d.collectAndRename)(a,(r,s)=>{if(r.newName!==r.original)return;let n=o(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=o(e),e+=1;r.newName=n,t.add(n),s.add(n)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(n,e){let t=n;for(;t;){const a=t.locals.get(e);if(a)return a;t=t.parent}}function c(n){return{parent:n,locals:new Map}}function f(n,e){const t=n.locals.get(e);if(t)return t;const a={original:e,newName:e};return n.locals.set(e,a),a}function x(n,e){const t=new Set,a={locals:new Map};d(n.body,a,t,e)}function u(n,e,t,a){d(n.body,e,t,a)}function d(n,e,t,a){for(const r of n)b(r,e,t,a)}function m(n,e,t,a){const r=c(e),o=n.params.slice();for(let l=0;l<o.length;l+=1){const p=f(r,o[l]);a(p,t),n.params[l]=p.newName}u(n.body,r,t,a)}function b(n,e,t,a){switch(n.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":u(n.body,c(e),t,a);return;case"WhileStat":s(n.cond,e,t,a),u(n.body,c(e),t,a);return;case"RepeatStat":{const r=c(e);u(n.body,r,t,a),s(n.cond,r,t,a);return}case"IfStat":for(const r of n.clauses)s(r.cond,e,t,a),u(r.body,c(e),t,a);n.elseBody&&u(n.elseBody,c(e),t,a);return;case"ForNumStat":{s(n.start,e,t,a),s(n.end,e,t,a),n.step&&s(n.step,e,t,a);const r=c(e),o=f(r,n.name);a(o,t),n.name=o.newName,u(n.body,r,t,a);return}case"ForInStat":{for(const o of n.exps)s(o,e,t,a);const r=c(e);for(let o=0;o<n.names.length;o+=1){const l=f(r,n.names[o]);a(l,t),n.names[o]=l.newName}u(n.body,r,t,a);return}case"FuncStat":{const r=i(e,n.name.base);r&&(n.name.base=r.newName),m(n.func,e,t,a);return}case"LocalFuncStat":{const r=f(e,n.name);a(r,t),n.name=r.newName,m(n.func,e,t,a);return}case"LocalStat":if(n.exps)for(const r of n.exps)s(r,e,t,a);for(let r=0;r<n.names.length;r+=1){const o=f(e,n.names[r].name);a(o,t),n.names[r].name=o.newName}return;case"AssignStat":for(const r of n.vars)s(r,e,t,a);for(const r of n.exps)s(r,e,t,a);return;case"CallStat":s(n.exp,e,t,a);return;case"ReturnStat":for(const r of n.exps)s(r,e,t,a);return}}function s(n,e,t,a){switch(n.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const r=i(e,n.name);r&&(n.name=r.newName);return}case"UnaryExpr":s(n.arg,e,t,a);return;case"BinaryExpr":s(n.left,e,t,a),s(n.right,e,t,a);return;case"FuncExpr":m(n,e,t,a);return;case"TableExpr":for(const r of n.fields)r.kind==="index"&&s(r.key,e,t,a),s(r.value,e,t,a);return;case"IndexExpr":s(n.object,e,t,a),s(n.index,e,t,a);return;case"MemberExpr":s(n.object,e,t,a);return;case"CallExpr":s(n.callee,e,t,a);for(const r of n.args)s(r,e,t,a);return;case"MethodCallExpr":s(n.object,e,t,a);for(const r of n.args)s(r,e,t,a);return;case"ParenExpr":s(n.exp,e,t,a);return}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const
|
|
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
2
|
local helper = require("device")
|
|
3
3
|
local wait = 10
|
|
4
4
|
Sleep(wait)
|
|
@@ -9,9 +9,9 @@ end
|
|
|
9
9
|
if add(1, 2) == 3 then
|
|
10
10
|
logi("ok")
|
|
11
11
|
end
|
|
12
|
-
`;function
|
|
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
13
|
for i=1,3 do n=n+i end
|
|
14
|
-
if n==6 then Sleep(n) else Sleep(0) end`);(0,
|
|
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
15
|
local x <const> = 1
|
|
16
16
|
local y = 10 // 3
|
|
17
17
|
local z = y & 1 | 2
|
|
@@ -20,7 +20,7 @@ goto skip
|
|
|
20
20
|
for i = 1, 2 do
|
|
21
21
|
break
|
|
22
22
|
end
|
|
23
|
-
`,"Minify");(0,
|
|
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
24
|
local env = setmetatable({
|
|
25
25
|
require = function(n) _G.__req = n; return {} end,
|
|
26
26
|
Sleep = function(ms) _G.__slept = ms end,
|
|
@@ -28,12 +28,12 @@ local env = setmetatable({
|
|
|
28
28
|
getmetatable = getmetatable, pcall = pcall, error = error,
|
|
29
29
|
}, {__index = _G})
|
|
30
30
|
env._ENV = env
|
|
31
|
-
local fn, err = load(${JSON.stringify(
|
|
31
|
+
local fn, err = load(${JSON.stringify(n)}, "obf", "t", env)
|
|
32
32
|
if not fn then error(err) end
|
|
33
33
|
fn()
|
|
34
34
|
if _G.__req ~= "device" then error("require name "..tostring(_G.__req)) end
|
|
35
35
|
if _G.__slept ~= 3 then error("Sleep "..tostring(_G.__slept)) end
|
|
36
|
-
print("${
|
|
37
|
-
`,
|
|
38
|
-
\u81EA\u68C0\u5931\u8D25 ${
|
|
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
39
|
\u81EA\u68C0\u901A\u8FC7`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=o;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=o;const u=require("./visit");function a(e){let r={type:"StringLiteral",value:e[0]};for(let n=1;n<e.length;n+=1)r={type:"BinaryExpr",op:"..",left:r,right:{type:"StringLiteral",value:e[n]}};return{type:"ParenExpr",exp:r}}function p(e,r){if(e.length<4)return[e];const n=r%2+2,t=Math.max(1,Math.ceil(e.length/n)),l=[];for(let i=0;i<e.length;i+=t)l.push(e.slice(i,i+t));return l}function o(e,r){let n=0;(0,u.mapChunk)(e,t=>{if(t.type!=="StringLiteral"||t.encoded||t.value.length<4)return t;n+=1;const l=p(t.value,r+n);return l.length<2?t:a(l)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.foldEncrypt=exports.foldDecrypt=exports.createFoldMixParams=void 0,exports.encryptStrings=y;const a=require("./cipher");Object.defineProperty(exports,"createFoldMixParams",{enumerable:!0,get:function(){return a.createFoldMixParams}}),Object.defineProperty(exports,"foldDecrypt",{enumerable:!0,get:function(){return a.foldDecrypt}}),Object.defineProperty(exports,"foldEncrypt",{enumerable:!0,get:function(){return a.foldEncrypt}});const u=require("./parser"),i=require("./visit"),l="__d";function d(t,o){let e=2166136261^o;for(let r=0;r<t.length;r+=1)e=Math.imul(e^t.charCodeAt(r),16777619);return e>>>0||1}function p(t,o,e){const r=(0,a.foldEncrypt)(t,o,e);return{type:"CallExpr",callee:{type:"NameExpr",name:l},args:[{type:"StringLiteral",value:r,encoded:!0},{type:"NumberLiteral",raw:String(e),value:e}]}}function y(t,o){const e=(0,a.createFoldMixParams)(o);let r=0;(0,i.mapChunk)(t,n=>n.type!=="StringLiteral"||n.encoded||n.value.length===0?n:(r+=1,p(n.value,e,d(n.value,r))));const c=(0,u.parseLua)((0,a.emitFoldDecoderLua)(e,l));t.body.unshift(...c.body)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mapExp=s,exports.mapFunc=b,exports.mapStats=o,exports.mapChunk=p;function s(t,e){switch(t.type){case"UnaryExpr":t.arg=s(t.arg,e);break;case"BinaryExpr":t.left=s(t.left,e),t.right=s(t.right,e);break;case"FuncExpr":b(t,e);break;case"TableExpr":for(const a of t.fields)a.kind==="index"&&(a.key=s(a.key,e)),a.value=s(a.value,e);break;case"IndexExpr":t.object=s(t.object,e),t.index=s(t.index,e);break;case"MemberExpr":t.object=s(t.object,e);break;case"CallExpr":t.callee=s(t.callee,e),t.args=t.args.map(a=>s(a,e));break;case"MethodCallExpr":t.object=s(t.object,e),t.args=t.args.map(a=>s(a,e));break;case"ParenExpr":t.exp=s(t.exp,e);break;default:break}return e(t)}function b(t,e){o(t.body.body,e)}function o(t,e){for(const a of t)switch(a.type){case"DoStat":o(a.body.body,e);break;case"WhileStat":a.cond=s(a.cond,e),o(a.body.body,e);break;case"RepeatStat":o(a.body.body,e),a.cond=s(a.cond,e);break;case"IfStat":for(const c of a.clauses)c.cond=s(c.cond,e),o(c.body.body,e);a.elseBody&&o(a.elseBody.body,e);break;case"ForNumStat":a.start=s(a.start,e),a.end=s(a.end,e),a.step&&(a.step=s(a.step,e)),o(a.body.body,e);break;case"ForInStat":a.exps=a.exps.map(c=>s(c,e)),o(a.body.body,e);break;case"FuncStat":b(a.func,e);break;case"LocalFuncStat":b(a.func,e);break;case"LocalStat":a.exps&&(a.exps=a.exps.map(c=>s(c,e)));break;case"AssignStat":a.vars=a.vars.map(c=>s(c,e)),a.exps=a.exps.map(c=>s(c,e));break;case"CallStat":a.exp=s(a.exp,e);break;case"ReturnStat":a.exps=a.exps.map(c=>s(c,e));break;default:break}}function p(t,e){o(t.body,e)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.emitVm=j;const
|
|
2
|
-
${(0,
|
|
3
|
-
local ${
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.emitVm=j;const p=require("./cipher"),d=require("./minify"),s=require("./opcodes");function h(e){let n=2166136261^e.code.length;return n=Math.imul(n,16777619)^e.consts.length,n>>>0}function b(e,n,l){if(e.t==="nil")return"nil";if(e.t==="bool")return e.v?"true":"false";if(e.t==="num")return e.raw;const a=(0,p.foldEncrypt)(e.v,n,l);return`D(${(0,d.escapeLuaString)(a)},${l})`}function u(e,n,l,a){const i=e.code.map((t,o)=>{const r=e.ops[o];return`{${n[r]},${t[1]},${t[2]},${t[3]}}`}).join(","),c=e.consts.map((t,o)=>b(t,l,a+o*131>>>0||1)).join(","),R=e.protos.map((t,o)=>u(t,n,l,a+(o+1)*4099>>>0)).join(","),f=e.upvals.map(t=>`{${t.inStack?1:0},${t.index}}`).join(",");return`{p={${i}},k={${c}},t={${R}},u={${f}},n=${e.numparams},v=${e.isVararg?"true":"false"}}`}function j(e){const n=h(e)||1,l=(0,s.shuffleOpcodes)(n),a=(0,p.createFoldMixParams)(n),i=s.OPCODE_NAMES.join(","),c=s.OPCODE_NAMES.map(f=>String(l[f])).join(","),R=u(e,l,a,n);return`(function()
|
|
2
|
+
${(0,p.emitFoldDecoderLua)(a,"D")}
|
|
3
|
+
local ${i}=${c}
|
|
4
4
|
local function G(u)
|
|
5
5
|
if u.R then
|
|
6
6
|
return u.R[u.i]
|
package/docs/api/hid.md
CHANGED
|
@@ -289,6 +289,27 @@ function setJitterValue(value: number): void;
|
|
|
289
289
|
hid.setJitterValue(5);
|
|
290
290
|
```
|
|
291
291
|
|
|
292
|
+
### setActionDelay - 设置动作延迟
|
|
293
|
+
|
|
294
|
+
设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
function setActionDelay(milliseconds: number): boolean;
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**参数:**
|
|
301
|
+
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|
|
302
|
+
| ---- | ---- | ---- | ------ | ---- |
|
|
303
|
+
| `milliseconds` | number | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
|
|
304
|
+
|
|
305
|
+
**示例:**
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
hid.setActionDelay(0);
|
|
309
|
+
hid.click(100, 200);
|
|
310
|
+
hid.click(300, 400);
|
|
311
|
+
```
|
|
312
|
+
|
|
292
313
|
## 基础触摸操作
|
|
293
314
|
|
|
294
315
|
### click - 点击操作
|
package/docs/api/opencv.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
```javascript
|
|
36
36
|
const src = cv.capture();
|
|
37
|
-
const gray = cv.cvtColor(src,
|
|
37
|
+
const gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
|
|
38
38
|
const edges = cv.Canny(gray, { threshold1: 100, threshold2: 200 });
|
|
39
39
|
const feat = cv.SIFT(gray, { nfeatures: 500 });
|
|
40
40
|
logi(`keypoints=${feat.keypoints.length}`);
|
|
@@ -51,7 +51,7 @@ cv.release(feat.descriptors);
|
|
|
51
51
|
const imageId = image.captureScreen();
|
|
52
52
|
const mat = cv.imread(imageId); // 或 cv.fromImageId(imageId)
|
|
53
53
|
image.release(imageId);
|
|
54
|
-
const gray = cv.cvtColor(mat,
|
|
54
|
+
const gray = cv.cvtColor(mat, cv.COLOR_BGR2GRAY);
|
|
55
55
|
const outId = cv.toImageId(gray);
|
|
56
56
|
cv.release(mat);
|
|
57
57
|
cv.release(gray);
|
|
@@ -316,7 +316,7 @@ cv.release(copy);
|
|
|
316
316
|
|
|
317
317
|
```typescript
|
|
318
318
|
function cvtColor(mat: Mat, code: number): Mat | null;
|
|
319
|
-
const hsv = cv.cvtColor(src,
|
|
319
|
+
const hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV);
|
|
320
320
|
```
|
|
321
321
|
|
|
322
322
|
### threshold - 固定阈值
|
|
@@ -385,8 +385,8 @@ function inRange(mat: Mat, options: { lowerb: number[]; upperb: number[] }): Mat
|
|
|
385
385
|
**示例:**
|
|
386
386
|
|
|
387
387
|
```javascript
|
|
388
|
-
const hsv = cv.cvtColor(src,
|
|
389
|
-
const mask = cv.inRange(hsv, {
|
|
388
|
+
const hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV);
|
|
389
|
+
const mask = cv.inRange(hsv, { lowerb: [0, 80, 80], upperb: [20, 255, 255] });
|
|
390
390
|
```
|
|
391
391
|
|
|
392
392
|
### bitwise_and / bitwise_or / bitwise_xor / bitwise_not
|
|
@@ -994,7 +994,7 @@ function SIFT(mat: Mat, options?: {
|
|
|
994
994
|
**示例:**
|
|
995
995
|
|
|
996
996
|
```javascript
|
|
997
|
-
const gray = cv.cvtColor(src,
|
|
997
|
+
const gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
|
|
998
998
|
const feat = cv.SIFT(gray, { nfeatures: 500 });
|
|
999
999
|
if (feat) {
|
|
1000
1000
|
logi(`SIFT keypoints=${feat.keypoints.length}`);
|
|
@@ -1113,8 +1113,8 @@ function findHomography(options: {
|
|
|
1113
1113
|
|
|
1114
1114
|
function perspectiveTransform(points: Point[], options: { M: Mat }): Point[] | null;
|
|
1115
1115
|
const templ = cv.imread("logo.png");
|
|
1116
|
-
const g1 = cv.cvtColor(src,
|
|
1117
|
-
const g2 = cv.cvtColor(templ,
|
|
1116
|
+
const g1 = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
|
|
1117
|
+
const g2 = cv.cvtColor(templ, cv.COLOR_BGR2GRAY);
|
|
1118
1118
|
|
|
1119
1119
|
const f1 = cv.SIFT(g1, { nfeatures: 800 });
|
|
1120
1120
|
const f2 = cv.SIFT(g2, { nfeatures: 800 });
|
package/docs/apicn/hid.md
CHANGED
|
@@ -289,6 +289,27 @@ function 设置抖动值(抖动值: 数字): 无返回值;
|
|
|
289
289
|
$HID.设置抖动值(5);
|
|
290
290
|
```
|
|
291
291
|
|
|
292
|
+
### 设置动作延迟
|
|
293
|
+
|
|
294
|
+
设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
function 设置动作延迟(毫秒: 数字): 布尔值;
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**参数:**
|
|
301
|
+
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|
|
302
|
+
| ---- | ---- | ---- | ------ | ---- |
|
|
303
|
+
| `毫秒` | 数字 | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
|
|
304
|
+
|
|
305
|
+
**示例:**
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
$HID.设置动作延迟(0);
|
|
309
|
+
$HID.点击(100, 200);
|
|
310
|
+
$HID.点击(300, 400);
|
|
311
|
+
```
|
|
312
|
+
|
|
292
313
|
## 基础触摸操作
|
|
293
314
|
|
|
294
315
|
### 点击
|
package/docs/apilua/hid.md
CHANGED
|
@@ -258,6 +258,29 @@ function setJitterValue(value) end
|
|
|
258
258
|
hid.setJitterValue(5)
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
+
### setActionDelay - 设置动作延迟
|
|
262
|
+
|
|
263
|
+
设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
|
|
264
|
+
|
|
265
|
+
```lua
|
|
266
|
+
---@param milliseconds number
|
|
267
|
+
---@return boolean
|
|
268
|
+
function setActionDelay(milliseconds) end
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**参数:**
|
|
272
|
+
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|
|
273
|
+
| ---- | ---- | ---- | ------ | ---- |
|
|
274
|
+
| `milliseconds` | number | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
|
|
275
|
+
|
|
276
|
+
**示例:**
|
|
277
|
+
|
|
278
|
+
```lua
|
|
279
|
+
hid.setActionDelay(0)
|
|
280
|
+
hid.click(100, 200)
|
|
281
|
+
hid.click(300, 400)
|
|
282
|
+
```
|
|
283
|
+
|
|
261
284
|
## 基础触摸操作
|
|
262
285
|
|
|
263
286
|
### click - 点击操作
|
package/docs/apilua/image.md
CHANGED
|
@@ -650,19 +650,26 @@ local templateDeviceWidth = 750
|
|
|
650
650
|
local currentWidth = device.getScreenRealSize().width
|
|
651
651
|
local baseScale = currentWidth / templateDeviceWidth
|
|
652
652
|
-- 围绕 baseScale,步进 0.05,左右各扩 2 档 → 共 5 个
|
|
653
|
-
local function buildScaleFactors(base, step
|
|
654
|
-
|
|
653
|
+
local function buildScaleFactors(base, step, halfRange)
|
|
654
|
+
step = step or 0.05
|
|
655
|
+
halfRange = halfRange or 2
|
|
656
|
+
local list = { tonumber(string.format("%.4f", base)) }
|
|
655
657
|
for i = 1, halfRange do
|
|
656
|
-
list.
|
|
657
|
-
list.
|
|
658
|
+
list[#list + 1] = tonumber(string.format("%.4f", base - step * i))
|
|
659
|
+
list[#list + 1] = tonumber(string.format("%.4f", base + step * i))
|
|
658
660
|
end
|
|
659
|
-
|
|
660
|
-
|
|
661
|
+
local out = {}
|
|
662
|
+
for _, s in ipairs(list) do
|
|
663
|
+
if s > 0.05 and s < 8 then
|
|
664
|
+
out[#out + 1] = s
|
|
665
|
+
end
|
|
666
|
+
end
|
|
667
|
+
return out
|
|
661
668
|
end
|
|
662
669
|
|
|
663
670
|
local scaleFactors = buildScaleFactors(baseScale)
|
|
664
671
|
-- 例如 baseScale=1.56, step=0.05, halfRange=2
|
|
665
|
-
-- →
|
|
672
|
+
-- → { 1.56, 1.51, 1.61, 1.46, 1.66 }
|
|
666
673
|
```
|
|
667
674
|
|
|
668
675
|
##### 3. 按场景怎么选
|
|
@@ -766,18 +773,26 @@ local templateDeviceWidth = 750
|
|
|
766
773
|
local currentWidth = device.getScreenRealSize().width
|
|
767
774
|
local baseScale = currentWidth / templateDeviceWidth
|
|
768
775
|
|
|
769
|
-
local function buildScaleFactors(base, step
|
|
770
|
-
|
|
776
|
+
local function buildScaleFactors(base, step, halfRange)
|
|
777
|
+
step = step or 0.05
|
|
778
|
+
halfRange = halfRange or 2
|
|
779
|
+
local list = { tonumber(string.format("%.4f", base)) }
|
|
771
780
|
for i = 1, halfRange do
|
|
772
|
-
list.
|
|
773
|
-
list.
|
|
781
|
+
list[#list + 1] = tonumber(string.format("%.4f", base - step * i))
|
|
782
|
+
list[#list + 1] = tonumber(string.format("%.4f", base + step * i))
|
|
783
|
+
end
|
|
784
|
+
local out = {}
|
|
785
|
+
for _, s in ipairs(list) do
|
|
786
|
+
if s > 0.05 and s < 8 then
|
|
787
|
+
out[#out + 1] = s
|
|
788
|
+
end
|
|
774
789
|
end
|
|
775
|
-
return
|
|
790
|
+
return out
|
|
776
791
|
end
|
|
777
792
|
|
|
778
793
|
local scaleFactors = buildScaleFactors(baseScale)
|
|
779
|
-
-- 750 → 1170 时约等于
|
|
780
|
-
print(
|
|
794
|
+
-- 750 → 1170 时约等于 { 1.56, 1.51, 1.61, 1.46, 1.66 }
|
|
795
|
+
print(string.format("baseScale=%.3f scaleFactors=%s", baseScale, ToJsonString(scaleFactors)))
|
|
781
796
|
|
|
782
797
|
local scaled = image.findImage(
|
|
783
798
|
"screen",
|
package/docs/apilua/opencv.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- 路径 / msbundle / imageId / `screen` 等读图只用 `imread`;其它 API 只接受 Mat 句柄;`imdecode` 只解 base64。
|
|
12
12
|
- 用完请 `release` / `releaseAll`。
|
|
13
13
|
- 颜色参数为 **BGR**;也可用 `#RRGGBB`。
|
|
14
|
-
- options 用 Lua 表:`{
|
|
14
|
+
- options 用 Lua 表:`{ threshold1 = 100, threshold2 = 200 }`;`cvtColor` 第二参是数字:`cv.cvtColor(src, cv.COLOR_BGR2GRAY)`;点集用 `{ { x = 1, y = 2 }, ... }`。
|
|
15
15
|
|
|
16
16
|
## 功能一览
|
|
17
17
|
|
|
@@ -53,7 +53,7 @@ Mat:`Mat` · `zeros` · `ones` · `clone` · `empty` · `isRelease` · `releas
|
|
|
53
53
|
```lua
|
|
54
54
|
|
|
55
55
|
local src = cv.capture()
|
|
56
|
-
local gray = cv.cvtColor(src,
|
|
56
|
+
local gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
|
|
57
57
|
local edges = cv.Canny(gray, { threshold1 = 100, threshold2 = 200 })
|
|
58
58
|
local feat = cv.SIFT(gray, { nfeatures = 500 })
|
|
59
59
|
if feat then
|
|
@@ -227,7 +227,7 @@ function imencode(ext, mat, quality) end
|
|
|
227
227
|
**示例:**
|
|
228
228
|
|
|
229
229
|
```lua
|
|
230
|
-
local b64 = cv.imencode(".jpg", mat,
|
|
230
|
+
local b64 = cv.imencode(".jpg", mat, 85)
|
|
231
231
|
```
|
|
232
232
|
|
|
233
233
|
### fromImageId / toImageId - 与 image 互通
|
|
@@ -278,7 +278,7 @@ function Mat(options) end
|
|
|
278
278
|
|
|
279
279
|
```lua
|
|
280
280
|
local z = cv.zeros({ rows = 100, cols = 100, type = cv.CV_8UC3 })
|
|
281
|
-
local filled = cv.Mat({ rows = 10, cols = 10, type = cv.CV_8UC1, scalar =
|
|
281
|
+
local filled = cv.Mat({ rows = 10, cols = 10, type = cv.CV_8UC1, scalar = { 255 } })
|
|
282
282
|
cv.release(z)
|
|
283
283
|
cv.release(filled)
|
|
284
284
|
```
|
|
@@ -396,8 +396,8 @@ function inRange(mat, options) end
|
|
|
396
396
|
**示例:**
|
|
397
397
|
|
|
398
398
|
```lua
|
|
399
|
-
local hsv = cv.cvtColor(src,
|
|
400
|
-
local mask = cv.inRange(hsv, {
|
|
399
|
+
local hsv = cv.cvtColor(src, cv.COLOR_BGR2HSV)
|
|
400
|
+
local mask = cv.inRange(hsv, { lowerb = { 0, 80, 80 }, upperb = { 20, 255, 255 } })
|
|
401
401
|
```
|
|
402
402
|
|
|
403
403
|
### countNonZero / minMaxLoc / mean / split / merge
|
|
@@ -648,11 +648,12 @@ function boundingRect(matOrPoints) end
|
|
|
648
648
|
```lua
|
|
649
649
|
for _, c in ipairs(contours) do
|
|
650
650
|
local area = cv.contourArea(c)
|
|
651
|
-
if
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
651
|
+
if area >= 100 then
|
|
652
|
+
local rect = cv.boundingRect(c)
|
|
653
|
+
local hull = cv.convexHull(c)
|
|
654
|
+
local approx = cv.approxPolyDP(c, { epsilon = 0.02 * cv.arcLength(c, true), closed = true })
|
|
655
|
+
cv.rectangle(src, { pt1 = { x = rect.x, y = rect.y }, pt2 = { x = rect.x + rect.width, y = rect.y + rect.height }, color = { 0, 255, 0 }, thickness = 1 })
|
|
656
|
+
end
|
|
656
657
|
end
|
|
657
658
|
```
|
|
658
659
|
|
package/docs/apilua/system.md
CHANGED
|
@@ -524,7 +524,7 @@ print("系统总内存: " .. tostring(totalMemory) .. "MB")
|
|
|
524
524
|
-- 计算内存使用率
|
|
525
525
|
local usedMemory = system.getUsedMemory()
|
|
526
526
|
local usagePercentage = (usedMemory / totalMemory) * 100
|
|
527
|
-
print("内存使用率: "
|
|
527
|
+
print(string.format("内存使用率: %.1f%%", usagePercentage))
|
|
528
528
|
-- 获取完整的内存信息
|
|
529
529
|
local memoryInfo = system.getMemoryInfo()
|
|
530
530
|
print("内存信息: 已使用 " .. tostring(memoryInfo.used) .. "MB / 总计 " .. tostring(memoryInfo.total) .. "MB")
|
package/docs/apilua/yolocls.md
CHANGED
|
@@ -26,7 +26,7 @@ YOLO 分类概率结果,字段命名与 Ultralytics `Probs` 保持一致。
|
|
|
26
26
|
|
|
27
27
|
```lua
|
|
28
28
|
---@class YoloClsProbs
|
|
29
|
-
---@field data number[]
|
|
29
|
+
---@field data number[] -- Lua 下标从 1 起,类别 0 对应 data[1]
|
|
30
30
|
---@field top1 number | nil
|
|
31
31
|
---@field top5 number[]
|
|
32
32
|
---@field top1conf number | nil
|
|
@@ -37,7 +37,7 @@ YOLO 分类概率结果,字段命名与 Ultralytics `Probs` 保持一致。
|
|
|
37
37
|
|
|
38
38
|
| 字段名 | 类型 | 描述 |
|
|
39
39
|
| ---------- | ---------------- | ---------------------------------------------------------- |
|
|
40
|
-
| `data` | `number[]` |
|
|
40
|
+
| `data` | `number[]` | 所有类别概率;Lua 下标从 1 起,类别 0 对应 `data[1]` |
|
|
41
41
|
| `top1` | `number \| nil` | 概率最高的类别 ID;分类失败时为 `nil` |
|
|
42
42
|
| `top5` | `number[]` | 概率最高的 5 个类别 ID,按概率从高到低排序 |
|
|
43
43
|
| `top1conf` | `number \| nil` | `top1` 对应的概率;分类失败时为 `nil` |
|
|
@@ -45,7 +45,7 @@ YOLO 分类概率结果,字段命名与 Ultralytics `Probs` 保持一致。
|
|
|
45
45
|
|
|
46
46
|
**结果说明:**
|
|
47
47
|
|
|
48
|
-
- `top1` 等于 `top5[
|
|
48
|
+
- `top1` 等于 `top5[1]`,`top1conf` 等于 `data[top1 + 1]`。
|
|
49
49
|
- 当模型类别数少于 5 时,`top5` 和 `top5conf` 的长度会小于 5。
|
|
50
50
|
- 分类失败时返回空结果:`data`、`top5`、`top5conf` 为空数组,`top1` 和 `top1conf` 为 `nil`。
|
|
51
51
|
|
|
@@ -150,20 +150,23 @@ local probs = yolocls.classify(
|
|
|
150
150
|
|
|
151
151
|
if probs.top1 ~= nil then
|
|
152
152
|
print("top1 类别ID = " .. tostring(probs.top1))
|
|
153
|
-
print("top1 置信度: "
|
|
153
|
+
print(string.format("top1 置信度: %.2f%%", probs.top1conf * 100))
|
|
154
154
|
else
|
|
155
155
|
print("分类失败或无有效结果")
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
for i = 1, #probs.top5 do
|
|
159
|
-
print(
|
|
160
|
-
"top[
|
|
161
|
-
|
|
159
|
+
print(string.format(
|
|
160
|
+
"top[%d] = 类别ID=%s, 置信度=%.4f",
|
|
161
|
+
i,
|
|
162
|
+
tostring(probs.top5[i]),
|
|
163
|
+
probs.top5conf[i]
|
|
164
|
+
))
|
|
162
165
|
end
|
|
163
|
-
--
|
|
166
|
+
-- Lua 数组从 1 起,类别 ID 0 对应 data[1]
|
|
164
167
|
local classId = 0
|
|
165
168
|
if #probs.data > classId then
|
|
166
|
-
print("类别
|
|
169
|
+
print(string.format("类别 %d 概率: %.4f", classId, probs.data[classId + 1]))
|
|
167
170
|
end
|
|
168
171
|
|
|
169
172
|
yolocls.free(modelId)
|
|
@@ -217,9 +220,11 @@ local regionProbs = yolocls.classifyRegion(
|
|
|
217
220
|
)
|
|
218
221
|
|
|
219
222
|
if regionProbs.top1 ~= nil then
|
|
220
|
-
print(
|
|
221
|
-
"区域分类 top1
|
|
222
|
-
|
|
223
|
+
print(string.format(
|
|
224
|
+
"区域分类 top1=%s, 置信度=%.4f",
|
|
225
|
+
tostring(regionProbs.top1),
|
|
226
|
+
regionProbs.top1conf
|
|
227
|
+
))
|
|
223
228
|
end
|
|
224
229
|
```
|
|
225
230
|
|
package/docs/apipython/hid.md
CHANGED
|
@@ -298,6 +298,28 @@ from kuaijs import hid
|
|
|
298
298
|
hid.setJitterValue(5)
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
+
### setActionDelay - 设置动作延迟
|
|
302
|
+
|
|
303
|
+
设置连续点击/滑动之间的等待毫秒。不调用时用固件默认(相对 200ms / 绝对 100ms)。
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
def setActionDelay(milliseconds: int) -> bool
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**参数:**
|
|
310
|
+
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|
|
311
|
+
| ---- | ---- | ---- | ------ | ---- |
|
|
312
|
+
| `milliseconds` | int | 是 | `-1` | `0` 关闭,`>0` 覆盖毫秒,`-1` 恢复默认 |
|
|
313
|
+
|
|
314
|
+
**示例:**
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
from kuaijs import hid
|
|
318
|
+
hid.setActionDelay(0)
|
|
319
|
+
hid.click(100, 200)
|
|
320
|
+
hid.click(300, 400)
|
|
321
|
+
```
|
|
322
|
+
|
|
301
323
|
## 基础触摸操作
|
|
302
324
|
|
|
303
325
|
### click - 点击操作
|