ms-vite-plugin 1.4.61 → 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 +2 -2
- package/dist/luaObfuscator/cipher.js +6 -6
- 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/splitStrings.js +1 -1
- package/dist/luaObfuscator/strings.js +1 -1
- package/dist/luaObfuscator/visit.js +1 -1
- package/docs/api/opencv.md +8 -8
- 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/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,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.applyAntiTamper=s;const
|
|
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
4
|
local acc = ${l}
|
|
@@ -23,4 +23,4 @@ do
|
|
|
23
23
|
error("Tamper Detected!")
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
-
`,i=(0,
|
|
26
|
+
`,i=(0,c.parseLua)(d);n.body.unshift(...i.body)}
|
|
@@ -1,11 +1,11 @@
|
|
|
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(
|
|
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
|
-
local mul45=${
|
|
4
|
-
local add45=${
|
|
5
|
-
local mul8=${
|
|
6
|
-
local secret8=${
|
|
3
|
+
local mul45=${t.mul45}
|
|
4
|
+
local add45=${t.add45}
|
|
5
|
+
local mul8=${t.mul8}
|
|
6
|
+
local secret8=${t.secret8}
|
|
7
7
|
local cache={}
|
|
8
|
-
${
|
|
8
|
+
${e}=function(s,seed)
|
|
9
9
|
local hit=cache[seed]
|
|
10
10
|
if hit then return hit end
|
|
11
11
|
local p=seed%35184372088832
|
|
@@ -1 +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}
|
|
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=h;const
|
|
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=C;function m(
|
|
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
|
-
`?(m+=1,d=1):d+=1,
|
|
3
|
-
`||
|
|
4
|
-
`&&
|
|
5
|
-
`;)
|
|
6
|
-
`)return a("\u77ED\u5B57\u7B26\u4E32\u5185\u51FA\u73B0\u672A\u8F6C\u4E49\u6362\u884C");if(
|
|
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=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,
|
|
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=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(
|
|
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(b,p
|
|
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=i,exports.collectAndRename=
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitStrings=
|
|
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 u=require("./parser"),i=require("./visit"),
|
|
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=s,exports.mapFunc=b,exports.mapStats=o,exports.mapChunk=p;function s(
|
|
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)}
|
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/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
|
|