ms-vite-plugin 1.4.66 → 1.4.68
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/build.js +1 -1
- package/dist/luaObfuscator/addVararg.js +1 -1
- package/dist/luaObfuscator/flatten.js +1 -1
- package/dist/luaObfuscator/rename.js +1 -1
- package/dist/luaObfuscator/scope.js +1 -1
- package/dist/scriptProtect.d.ts +1 -0
- package/dist/scriptProtect.js +3 -2
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.create;var
|
|
1
|
+
"use strict";var x=Object.create;var M=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var C=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of N(e))!z.call(t,r)&&r!==o&&M(t,r,{get:()=>e[r],enumerable:!(s=$(e,r))||s.enumerable});return t};var W=(t,e,o)=>(o=t!=null?x(q(t)):{},C(e||!t||!t.__esModule?M(o,"default",{value:t,enumerable:!0}):o,t));var K=exports&&exports.__createBinding||(Object.create?(function(t,e,o,s){s===void 0&&(s=o);var r=Object.getOwnPropertyDescriptor(e,o);(!r||("get"in r?!e.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return e[o]}}),Object.defineProperty(t,s,r)}):(function(t,e,o,s){s===void 0&&(s=o),t[s]=e[o]})),A=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),O=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(o){var s=[];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(s[s.length]=r);return s},t(e)};return function(e){if(e&&e.__esModule)return e;var o={};if(e!=null)for(var s=t(e),r=0;r<s.length;r++)s[r]!=="default"&&K(o,e,s[r]);return A(o,e),o}})(),D=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.buildAll=void 0;const T=D(require("archiver")),E=require("child_process"),i=O(require("fs-extra")),F=O(require("os")),n=O(require("path")),B=require("./stopGuardPlugin"),G=require("./luaBundle"),L=require("./scriptProtect"),H=D(require("vite-plugin-bundle-obfuscator"));async function R(t,e){const o=(0,T.default)("zip",{zlib:{level:9}}),s=i.createWriteStream(e);return new Promise((r,c)=>{o.directory(t,!1).on("error",a=>c(a)).pipe(s),s.on("close",()=>r()),o.finalize()})}async function I(t,e){const o=[];async function s(r){const c=await i.readdir(r,{withFileTypes:!0});for(const a of c){const f=n.resolve(r,a.name);a.isDirectory()?await s(f):a.isFile()&&(/^main\.(js|ts)$/.test(a.name)||/_thread\.(js|ts)$/.test(a.name))&&o.push(n.relative(e,f))}}return await s(t),o}function Q(){const t=[{cmd:n.join(F.homedir(),".KuaiJSDevloper","python","python.exe"),args:["--version"]},{cmd:n.join(F.homedir(),".KuaiJSDevloper","python","bin","python"),args:["--version"]},{cmd:"python",args:["--version"]},{cmd:"python3",args:["--version"]},{cmd:"python3.14",args:["--version"]}];for(const e of t)try{const o=(0,E.spawnSync)(e.cmd,e.args,{encoding:"utf8"}),s=(o.stdout||o.stderr||"").trim();if(s&&/Python\s+3\.14(\.\d+)?/i.test(s))return{ok:!0,path:e.cmd,version:s}}catch{}return{ok:!1}}async function U(t){async function e(o){const s=await i.readdir(o,{withFileTypes:!0});for(const r of s){const c=n.join(o,r.name);if(r.isDirectory())if(r.name==="__pycache__"){const a=await i.readdir(c,{withFileTypes:!0});for(const f of a){const P=n.join(c,f.name);if(f.isFile()&&f.name.endsWith(".cpython-314.pyc")){const S=n.dirname(c),b=f.name.replace(/\.cpython-314\.pyc$/,".pyc"),j=n.join(S,b);await i.move(P,j,{overwrite:!0})}}try{await i.remove(c)}catch{}}else await e(c);else if(r.isFile())if(r.name.endsWith(".cpython-314.pyc")){const a=c.replace(".cpython-314.pyc",".pyc");await i.move(c,a,{overwrite:!0})}else r.name.endsWith(".py")&&await i.remove(c)}}await e(t)}const V=["Minify","Weak","Medium","Strong"];async function X(t){const e=n.join(t,"obfuscator.json");if(!await i.pathExists(e))return{enabled:!0,preset:"Medium",bundle:!0};try{const o=await i.readJSON(e),s=o?.enabled!==!1,r=o?.bundle!==!1,c=Y(o?.preset);return{enabled:s,preset:c,bundle:r}}catch(o){return console.error("\u274C \u65E0\u6CD5\u8BFB\u53D6 obfuscator.json"),console.error(o instanceof Error?o.message:String(o)),process.exit(1),{enabled:!0,preset:"Medium",bundle:!0}}}function Y(t){if(typeof t!="string")return"Medium";const e=V.find(o=>o.toLowerCase()===t.trim().toLowerCase());return e||(console.warn(`\u26A0\uFE0F obfuscator.json \u7684 preset \u65E0\u6548: ${t}\uFF0C\u5DF2\u6539\u7528 Medium`),"Medium")}function Z(t){return[n.join(t,"node_modules/@gamely/prometheus-cli/bin/cli.js"),n.join(t,"node_modules/ms-vite-plugin/node_modules/@gamely/prometheus-cli/bin/cli.js"),n.resolve(process.cwd(),"node_modules/@gamely/prometheus-cli/bin/cli.js")].find(o=>i.pathExistsSync(o))}const k=async(t=!0,e)=>{const o=n.join(e,"scripts"),s=await i.pathExists(n.join(o,"main.js"))||await i.pathExists(n.join(o,"main.ts")),r=await i.pathExists(n.join(o,"main.py")),c=await i.pathExists(n.join(o,"main.lua"));if(s){console.log("\u{1F680} \u5F00\u59CB\u6784\u5EFAJavaScript\u9879\u76EE...");const{build:l}=await import("vite"),u=n.join(e,"obfuscator.json");await i.pathExists(u)||(console.error("\u274C \u9519\u8BEF: \u5F53\u524D\u76EE\u5F55\u4E0D\u662F\u6709\u6548\u7684 \u5FEB\u70B9JS \u9879\u76EE"),console.error("\u8BF7\u786E\u4FDD\u76EE\u5F55\u5305\u542B\u4EE5\u4E0B\u6587\u4EF6:"),console.error(" - obfuscator.json"),process.exit(1));const g=await i.readJSON(u),m=g.scriptProtect===!0,{enabled:_,scriptProtect:y,...p}=g,d=n.join(e,t?"dist":"msbundle"),h=await I(o,o);await i.remove(d);const w=!t&&m?(0,L.createScriptProtectHelpers)():[];!t&&m&&console.log("\u{1F510} \u5DF2\u542F\u7528 JS \u539F\u751F\u4FDD\u62A4\uFF08scriptProtect=true\uFF09");for(const v of h)await l({root:e,build:{lib:{entry:{[n.basename(v,n.extname(v))]:`./scripts/${v}`},fileName:()=>v.replace(/\.ts$/,".js"),formats:["iife"],name:"KuaiJS"},outDir:t?"dist/scripts":"msbundle/scripts",emptyOutDir:!1,sourcemap:t,minify:!t,target:"safari15"},plugins:[(0,B.createStopGuardPlugin)(),...t?[]:[...m?[(0,L.createScriptProtectPlugin)(w)]:[],_?(0,H.default)({autoExcludeNodeModules:!0,threadPool:!0,options:{...p,target:"browser",debugProtection:!1,disableConsoleOutput:!1,domainLock:[],selfDefending:!1,renameGlobals:!1,renameProperties:!1,reservedNames:[...p.reservedNames||[],...w]}}):[],...m?[(0,L.createKjstEmbedPlugin)()]:[]]]})}if(t)return;const a=n.join(e,"msbundle");if(await i.ensureDir(a),(r||c)&&await i.copy(n.join(e,"scripts"),n.join(a,"scripts")),r){const l=Q();if(l.ok){console.log(`\u2705 \u68C0\u6D4B\u5230 ${l.version} (${l.path})`);const u=(0,E.spawnSync)(l.path,["-m","compileall","scripts"],{encoding:"utf8",cwd:a});u.status===0?(console.log("\u2705 \u6210\u529F\u7F16\u8BD1\u6240\u6709 Python \u6587\u4EF6"),await U(n.join(a,"scripts"))):(console.error("\u274C \u7F16\u8BD1 Python \u6587\u4EF6\u5931\u8D25"),console.error(u.stderr),process.exit(1))}else console.warn("\u26A0\uFE0F \u672A\u68C0\u6D4B\u5230 Python 3.14\uFF0C\u8BF7\u786E\u4FDD\u5728\u76EE\u6807\u8FD0\u884C\u73AF\u5883\u5B89\u88C5 Python 3.14")}else if(c){const l=await X(e),u=n.join(a,"scripts");if(l.bundle?await(0,G.bundleLuaScripts)(u):console.log("\u2139\uFE0F \u5DF2\u5173\u95ED Lua \u5355\u6587\u4EF6\u5408\u5E76\uFF08obfuscator.json bundle=false\uFF09"),!l.enabled)console.log("\u2139\uFE0F \u5DF2\u5173\u95ED Lua \u6DF7\u6DC6\uFF08obfuscator.json enabled=false\uFF09");else{const g=[],m=async y=>{const p=await i.readdir(y,{withFileTypes:!0});for(const d of p){const h=n.join(y,d.name);d.isDirectory()?await m(h):d.isFile()&&d.name.endsWith(".lua")&&g.push(h)}};await m(u);const _=Z(e);_||(console.error("\u274C \u672A\u627E\u5230 @gamely/prometheus-cli\uFF0C\u65E0\u6CD5\u6DF7\u6DC6 Lua"),process.exit(1));for(const y of g){const p=n.relative(u,y);console.log(`\u{1F6E0}\uFE0F \u6DF7\u6DC6 Lua: ${p} (preset=${l.preset})`);const d=(0,E.spawnSync)(process.execPath,[_,p,"--preset",l.preset],{cwd:u,encoding:"utf8"});d.status!==0&&(console.error("\u274C \u6DF7\u6DC6 Lua \u5931\u8D25:",p),console.error(d.stderr||d.stdout||""),process.exit(1));const h=p.replace(/\.lua$/,".obfuscated.lua"),w=n.join(u,h);await i.pathExists(w)&&(await i.remove(y),await i.move(w,y,{overwrite:!0}))}console.log("\u2705 Lua \u6DF7\u6DC6\u5B8C\u6210")}}await i.copy(n.join(e,"res"),n.join(a,"res")),await i.copy(n.join(e,"ui"),n.join(a,"ui"));for(const l of["logo.jpg","logo.png"]){const u=n.join(e,l);await i.pathExists(u)&&await i.copy(u,n.join(a,l))}const f=n.join(e,"dist"),P=n.join(e,"package.json"),S=n.join(a,"package.json"),b=await i.readJSON(P);delete b.scripts,delete b.devDependencies,delete b.dependencies,await i.writeJSON(S,b,{spaces:2}),await i.emptyDir(f);const j=n.join(f,"ms.zip"),J=n.join(f,"ms.msbundle");await R(a,j),await i.rename(j,J),await i.remove(a)};exports.buildAll=k;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.addVararg=c;function s(r){r.vararg=!0,t(r.body.body)}function a(r){switch(r.type){case"FuncExpr":s(r);break;case"UnaryExpr":a(r.arg);break;case"BinaryExpr":a(r.left),a(r.right);break;case"TableExpr":for(const e of r.fields)e.kind==="index"&&a(e.key),a(e.value);break;case"IndexExpr":a(r.object),a(r.index);break;case"MemberExpr":a(r.object);break;case"CallExpr":a(r.callee);for(const e of r.args)a(e);break;case"MethodCallExpr":a(r.object);for(const e of r.args)a(e);break;case"ParenExpr":a(r.exp);break;default:break}}function t(r){for(const e of r)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if(e.type==="WhileStat"&&a(e.cond),e.type==="RepeatStat"&&a(e.cond),e.type==="ForNumStat"&&(a(e.start),a(e.end),e.step&&a(e.step)),e.type==="ForInStat")for(const o of e.exps)a(o);t(e.body.body);break;case"IfStat":for(const o of e.clauses)a(o.cond),t(o.body.body);e.elseBody&&t(e.elseBody.body);break;case"FuncStat":case"LocalFuncStat":s(e.func);break;case"LocalStat":if(e.exps)for(const o of e.exps)a(o);break;case"AssignStat":for(const o of e.vars)a(o);for(const o of e.exps)a(o);break;case"CallStat":a(e.exp);break;case"ReturnStat":for(const o of e.exps)a(o);break;default:break}}function c(r){t(r.body)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flattenControlFlow=C;function m(t){return{type:"NumberLiteral",raw:String(t),value:t}}function p(t){return{type:"NameExpr",name:t}}function f(t,n){return{type:"AssignStat",vars:t.map(e=>p(e)),exps:n}}function u(t,n){return f([t.stateName],[typeof n=="number"?m(n):n])}function k(t,n,e){return{type:"BinaryExpr",op:"or",left:{type:"BinaryExpr",op:"and",left:p(t),right:m(n)},right:m(e)}}function E(t,n,e){return{type:"BinaryExpr",op:t,left:n,right:e}}function S(t){const n=`__t${t.nextTemp}`;return t.nextTemp+=1,t.temps.push(n),n}function x(t){const n=t.nextState;return t.nextState+=1,t.states.set(n,[]),n}function o(t,n,e){t.states.get(n).push(e)}function F(t,n){for(const e of t)if(e.type==="LocalStat")for(const a of e.names)n.push(a.name);else if(e.type==="LocalFuncStat")n.push(e.name);else if(e.type==="ForNumStat")n.push(e.name),F(e.body.body,n);else if(e.type==="ForInStat")n.push(...e.names),F(e.body.body,n);else if(e.type==="DoStat"||e.type==="WhileStat"||e.type==="RepeatStat")F(e.body.body,n);else if(e.type==="IfStat"){for(const a of e.clauses)F(a.body.body,n);e.elseBody&&F(e.elseBody.body,n)}}function h(t,n,e,a){if(t.length===0)return n;const y=t.map(()=>x(e));for(let s=0;s<t.length;s+=1){const r=t[s];r.type==="LabelStat"&&e.userLabels.set(r.name,y[s])}for(let s=0;s<t.length;s+=1){const r=s+1<t.length?y[s+1]:n;I(e,y[s],t[s],r,a)}return y[0]}function I(t,n,e,a,y){switch(e.type){case"EmptyStat":case"LabelStat":o(t,n,u(t,a));return;case"AssignStat":case"CallStat":case"FuncStat":o(t,n,e),o(t,n,u(t,a));return;case"LocalStat":e.exps&&e.exps.length>0&&o(t,n,f(e.names.map(s=>s.name),e.exps)),o(t,n,u(t,a));return;case"LocalFuncStat":o(t,n,f([e.name],[e.func])),o(t,n,u(t,a));return;case"ReturnStat":o(t,n,e);return;case"BreakStat":o(t,n,u(t,y));return;case"GotoStat":{const s=t.userLabels.get(e.name);if(s===void 0)throw new Error(`goto \u672A\u5B9A\u4E49\u6807\u7B7E ::${e.name}::`);o(t,n,u(t,s));return}case"DoStat":o(t,n,u(t,h(e.body.body,a,t,y)));return;case"IfStat":{const s=S(t);let r=n;for(let l=0;l<e.clauses.length;l+=1){const b=l===e.clauses.length-1,d=h(e.clauses[l].body.body,a,t,y);let i=a;b?e.elseBody&&(i=h(e.elseBody.body,a,t,y)):i=x(t),o(t,r,f([s],[e.clauses[l].cond])),o(t,r,u(t,k(s,d,i))),b||(r=i)}e.clauses.length===0&&o(t,n,u(t,a));return}case"WhileStat":{const s=S(t),r=h(e.body.body,n,t,a);o(t,n,f([s],[e.cond])),o(t,n,u(t,k(s,r,a)));return}case"RepeatStat":{const s=S(t),r=x(t),l=h(e.body.body,r,t,a);o(t,n,u(t,l)),o(t,r,f([s],[e.cond])),o(t,r,u(t,k(s,a,l)));return}case"ForNumStat":{const s=e.name,r=S(t),l=S(t),b=S(t),d=x(t),i=x(t),L=x(t),g=x(t),N=h(e.body.body,g,t,a);o(t,n,f([s],[e.start])),o(t,n,f([r],[e.end])),o(t,n,f([l],[e.step??m(1)])),o(t,n,u(t,d)),o(t,d,f([b],[E(">=",p(l),m(0))])),o(t,d,u(t,k(b,i,L))),o(t,i,f([b],[E("<=",p(s),p(r))])),o(t,i,u(t,k(b,N,a))),o(t,L,f([b],[E(">=",p(s),p(r))])),o(t,L,u(t,k(b,N,a))),o(t,g,f([s],[E("+",p(s),p(l))])),o(t,g,u(t,d));return}case"ForInStat":{const s=S(t),r=S(t),l=S(t),b=S(t),d=x(t),i=[f([l],[p(e.names[0])]),...e.body.body],L=h(i,d,t,a),g=e.exps.slice();for(;g.length<3;)g.push({type:"NilLiteral"});o(t,n,f([s,r,l],g.slice(0,3))),o(t,n,u(t,d)),o(t,d,{type:"AssignStat",vars:e.names.map(N=>p(N)),exps:[{type:"CallExpr",callee:p(s),args:[p(r),p(l)]}]}),o(t,d,f([b],[E("~=",p(e.names[0]),{type:"NilLiteral"})])),o(t,d,u(t,k(b,L,a)));return}default:o(t,n,u(t,a))}}function v(t,n){const e=t.slice();let a=n>>>0||1;for(let y=e.length-1;y>0;y-=1){a=Math.imul(a,1664525)+1013904223>>>0;const s=a%(y+1),r=e[y];e[y]=e[s],e[s]=r}return e}function w(t,n){if(t.length===0)return t;const e={states:new Map,temps:[],nextState:1,nextTemp:1,stateName:"__s",userLabels:new Map},a=[];F(t,a);const y=h(t,0,e,0),s=[...new Set([...a,...e.temps,e.stateName])],r=v([...e.states.keys()],n).map(l=>({cond:E("==",p(e.stateName),m(l)),body:{type:"Block",body:e.states.get(l)}}));return[{type:"LocalStat",names:s.map(l=>({name:l}))},f([e.stateName],[m(y)]),{type:"WhileStat",cond:E("~=",p(e.stateName),m(0)),body:{type:"Block",body:[{type:"IfStat",clauses:r}]}}]}function c(t,n){switch(t.type){case"FuncExpr":B(t.body.body,n),t.body.body=w(t.body.body,n);break;case"UnaryExpr":c(t.arg,n);break;case"BinaryExpr":c(t.left,n),c(t.right,n);break;case"TableExpr":for(const e of t.fields)e.kind==="index"&&c(e.key,n),c(e.value,n);break;case"IndexExpr":c(t.object,n),c(t.index,n);break;case"MemberExpr":c(t.object,n);break;case"CallExpr":c(t.callee,n);for(const e of t.args)c(e,n);break;case"MethodCallExpr":c(t.object,n);for(const e of t.args)c(e,n);break;case"ParenExpr":c(t.exp,n);break;default:break}}function B(t,n){for(const e of t)switch(e.type){case"DoStat":case"WhileStat":case"RepeatStat":case"ForNumStat":case"ForInStat":if((e.type==="WhileStat"||e.type==="RepeatStat")&&c(e.cond,n),e.type==="ForNumStat"&&(c(e.start,n),c(e.end,n),e.step&&c(e.step,n)),e.type==="ForInStat")for(const a of e.exps)c(a,n);B(e.body.body,n);break;case"IfStat":for(const a of e.clauses)c(a.cond,n),B(a.body.body,n);e.elseBody&&B(e.elseBody.body,n);break;case"FuncStat":case"LocalFuncStat":B(e.func.body.body,n),e.func.body.body=w(e.func.body.body,n);break;case"LocalStat":if(e.exps)for(const a of e.exps)c(a,n);break;case"AssignStat":for(const a of e.vars)c(a,n);for(const a of e.exps)c(a,n);break;case"CallStat":c(e.exp,n);break;case"ReturnStat":for(const a of e.exps)c(a,n);break;default:break}}function C(t,n){B(t.body,n),t.body=w(t.body,n)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shortName=a,exports.renameLocals=c;const u=require("./reserved"),d=require("./scope"),l="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function a(r){let e=r,t="";do t=l[e%l.length]+t,e=Math.floor(e/l.length)-1;while(e>=0);return u.luaKeywords.has(t)?`_${t}`:t}function c(r){let e=0;const t=new Set;(0,d.collectAndRename)(r,(o,s)=>{if(o.newName!==o.original)return;let n=a(e);for(e+=1;s.has(n)||t.has(n)||u.luaKeywords.has(n);)n=a(e),e+=1;o.newName=n,t.add(n),s.add(n)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveLocal=i,exports.collectAndRename=x;function i(t,c){let r=t;for(;r;){const e=r.locals.get(c);if(e)return e;r=r.parent}}function o(t){return{parent:t,locals:new Map}}function f(t,c){const r=t.locals.get(c);if(r)return r;const e={original:c,newName:c};return t.locals.set(c,e),e}function x(t,c){const r=new Set,e={locals:new Map};d(t.body,e,r,c)}function l(t,c,r,e){d(t.body,c,r,e)}function d(t,c,r,e){for(const s of t)b(s,c,r,e)}function m(t,c,r,e){const s=o(c),a=t.params.slice();for(let u=0;u<a.length;u+=1){const p=f(s,a[u]);e(p,r),t.params[u]=p.newName}l(t.body,s,r,e)}function b(t,c,r,e){switch(t.type){case"EmptyStat":case"BreakStat":case"GotoStat":case"LabelStat":return;case"DoStat":l(t.body,o(c),r,e);return;case"WhileStat":n(t.cond,c,r,e),l(t.body,o(c),r,e);return;case"RepeatStat":{const s=o(c);l(t.body,s,r,e),n(t.cond,s,r,e);return}case"IfStat":for(const s of t.clauses)n(s.cond,c,r,e),l(s.body,o(c),r,e);t.elseBody&&l(t.elseBody,o(c),r,e);return;case"ForNumStat":{n(t.start,c,r,e),n(t.end,c,r,e),t.step&&n(t.step,c,r,e);const s=o(c),a=f(s,t.name);e(a,r),t.name=a.newName,l(t.body,s,r,e);return}case"ForInStat":{for(const a of t.exps)n(a,c,r,e);const s=o(c);for(let a=0;a<t.names.length;a+=1){const u=f(s,t.names[a]);e(u,r),t.names[a]=u.newName}l(t.body,s,r,e);return}case"FuncStat":{const s=i(c,t.name.base);s&&(t.name.base=s.newName),m(t.func,c,r,e);return}case"LocalFuncStat":{const s=f(c,t.name);e(s,r),t.name=s.newName,m(t.func,c,r,e);return}case"LocalStat":if(t.exps)for(const s of t.exps)n(s,c,r,e);for(let s=0;s<t.names.length;s+=1){const a=f(c,t.names[s].name);e(a,r),t.names[s].name=a.newName}return;case"AssignStat":for(const s of t.vars)n(s,c,r,e);for(const s of t.exps)n(s,c,r,e);return;case"CallStat":n(t.exp,c,r,e);return;case"ReturnStat":for(const s of t.exps)n(s,c,r,e);return}}function n(t,c,r,e){switch(t.type){case"NilLiteral":case"BoolLiteral":case"NumberLiteral":case"StringLiteral":case"VarargExpr":return;case"NameExpr":{const s=i(c,t.name);s&&(t.name=s.newName);return}case"UnaryExpr":n(t.arg,c,r,e);return;case"BinaryExpr":n(t.left,c,r,e),n(t.right,c,r,e);return;case"FuncExpr":m(t,c,r,e);return;case"TableExpr":for(const s of t.fields)s.kind==="index"&&n(s.key,c,r,e),n(s.value,c,r,e);return;case"IndexExpr":n(t.object,c,r,e),n(t.index,c,r,e);return;case"MemberExpr":n(t.object,c,r,e);return;case"CallExpr":n(t.callee,c,r,e);for(const s of t.args)n(s,c,r,e);return;case"MethodCallExpr":n(t.object,c,r,e);for(const s of t.args)n(s,c,r,e);return;case"ParenExpr":n(t.exp,c,r,e);return}}
|
package/dist/scriptProtect.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export type ScriptProtectResult = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function protectScript(code: string): ScriptProtectResult;
|
|
8
8
|
export declare function createScriptProtectPlugin(reservedNames: string[]): Plugin;
|
|
9
|
+
export declare function createKjstEmbedPlugin(): Plugin;
|
|
9
10
|
export declare function createScriptProtectHelpers(): string[];
|
package/dist/scriptProtect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=exports&&exports.__createBinding||(Object.create?(function(t,e,r,a){a===void 0&&(a=r);var i=Object.getOwnPropertyDescriptor(e,r);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,a,i)}):(function(t,e,r,a){a===void 0&&(a=r),t[a]=e[r]})),_=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),E=exports&&exports.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var a=[];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(a[a.length]=i);return a},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var a=t(e),i=0;i<a.length;i++)a[i]!=="default"&&I(r,e,a[i]);return _(r,e),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.protectScript=k,exports.createScriptProtectPlugin=F,exports.createKjstEmbedPlugin=R,exports.createScriptProtectHelpers=C;const A=E(require("acorn")),h=E(require("crypto")),w=require("magic-string"),x="KJST",T=1,v="/*KJST",D="*/",U=`-----BEGIN PUBLIC KEY-----
|
|
2
2
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArzeAhUUEi4p0AxLYIVJK
|
|
3
3
|
UcXyySzlh8G4TfH/quDXiKVlYlho9v2R1cQKQgFpVuDW8SDyc2iWUTNa8D/NX9LN
|
|
4
4
|
IqcgQP0lyTxuFvevfGOlPt6NDl0nYNqaToK5AvN/F7AcchU9JrNSB4BNEeFRechm
|
|
@@ -6,4 +6,5 @@ GL9m5iUY0HCbiOIcbo+rx1GQaqTYCUuZIJttuARYCq0ggoOHjBqMHUKWwdNtJVoe
|
|
|
6
6
|
PrdRaKzL3CB2gXazQzKUVrlK2vEDEaTvSLJoCym7SkSf/XmxjfEADlcwrqTb01ar
|
|
7
7
|
U8mm9/g5R9q43B8NqlTpGOcs1OpAY5DZW1DDjXhyHBfrPCt82hhmeO/yI0N8vE2m
|
|
8
8
|
MwIDAQAB
|
|
9
|
-
-----END PUBLIC KEY-----`,
|
|
9
|
+
-----END PUBLIC KEY-----`,O=new Set(["action","$\u52A8\u4F5C","appleOcr","$\u82F9\u679COCR","cloud","$\u4E91\u63A7","config","$\u914D\u7F6E","cryptoUtils","cv","device","$\u8BBE\u5907","dotOcr","$\u70B9\u9635OCR","file","$\u6587\u4EF6","hid","$HID","hotUpdate","$\u70ED\u66F4\u65B0","http","$HTTP","image","$\u56FE\u7247","ime","$\u8F93\u5165\u6CD5","logger","$\u65E5\u5FD7","media","$\u5A92\u4F53","mysql","$MySQL\u6570\u636E\u5E93","netCard","$\u5361\u5BC6","paddleOcr","$PaddleOCR","pip","$\u60AC\u6D6E\u7A97","sharedState","$\u5171\u4EAB\u72B6\u6001","system","$\u7CFB\u7EDF","thread","$\u7EBF\u7A0B","tomatoOcr","tts","$\u6587\u5B57\u8F6C\u8BED\u97F3","ui","$\u89C6\u56FE","utils","$\u5DE5\u5177","yolo","$YOLO","yoloCls","$YOLO\u5206\u7C7B"]),M=new Set(["createNodeSelector","$\u521B\u5EFA\u8282\u70B9\u9009\u62E9\u5668","exit","$\u9000\u51FA\u811A\u672C","getAgentFastMode","$\u83B7\u53D6Agent\u5FEB\u901F\u6A21\u5F0F","getAgentTouchMode","$\u83B7\u53D6Agent\u89E6\u63A7\u6A21\u5F0F","getContext","$\u83B7\u53D6\u4E0A\u4E0B\u6587","getCpuAutoThrottle","$\u83B7\u53D6CPU\u81EA\u52A8\u9650\u6D41","getCpuThrottleDelay","$\u83B7\u53D6CPU\u9650\u6D41\u5EF6\u8FDF","importClass","$\u5BFC\u5165\u7C7B","loadDex","$\u52A0\u8F7DDex","logd","$\u6253\u5370\u8C03\u8BD5\u65E5\u5FD7","loge","$\u6253\u5370\u9519\u8BEF\u65E5\u5FD7","logi","$\u6253\u5370\u4FE1\u606F\u65E5\u5FD7","logw","$\u6253\u5370\u8B66\u544A\u65E5\u5FD7","println","$\u6253\u5370","restartScript","$\u91CD\u542F\u811A\u672C","setAgentFastMode","$\u8BBE\u7F6EAgent\u5FEB\u901F\u6A21\u5F0F","setAgentTouchMode","$\u8BBE\u7F6EAgent\u89E6\u63A7\u6A21\u5F0F","setCpuAutoThrottle","$\u8BBE\u7F6ECPU\u81EA\u52A8\u9650\u6D41","setCpuThrottleDelay","$\u8BBE\u7F6ECPU\u9650\u6D41\u5EF6\u8FDF","setExceptionCallback","$\u8BBE\u7F6E\u5F02\u5E38\u505C\u6B62\u56DE\u8C03","setStopCallback","$\u8BBE\u7F6E\u505C\u6B62\u56DE\u8C03","sleep","$\u5EF6\u65F6","takeMeToFront","$APP\u5207\u5165\u524D\u53F0","time","$\u83B7\u53D6\u5F53\u524D\u65F6\u95F4\u6233"]);function m(t){for(;;){const e=`_0x${h.randomBytes(3).toString("hex")}`;if(!t.has(e))return t.add(e),e}}function y(t,e){const r=t.indexOf(e);return r>=0?r:(t.push(e),t.length-1)}function S(t,e){for(let r=e.length-1;r>=0;r-=1)if(e[r].has(t))return!0;return!1}function p(t,e){if(!(!t||typeof t!="object")){if(t.type==="Identifier"){e.add(t.name);return}if(t.type==="AssignmentPattern"){p(t.left,e);return}if(t.type==="RestElement"){p(t.argument,e);return}if(t.type==="ArrayPattern"){for(const r of t.elements||[])p(r,e);return}if(t.type==="ObjectPattern")for(const r of t.properties||[])r.type==="RestElement"?p(r.argument,e):p(r.value,e)}}function N(t){try{return A.parse(t,{allowHashBang:!0,ecmaVersion:"latest",sourceType:"script"})}catch{return A.parse(t,{allowHashBang:!0,ecmaVersion:"latest",sourceType:"module"})}}function P(t,e,r,a){if(!t||typeof t!="object"||typeof t.type!="string")return;let i=0;if(t.type==="FunctionDeclaration"||t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"){const c=new Set;t.id&&t.id.type==="Identifier"&&c.add(t.id.name);for(const s of t.params||[])p(s,c);r.push(c),i+=1}if(t.type==="CatchClause"&&t.param){const c=new Set;p(t.param,c),r.push(c),i+=1}if(t.type==="VariableDeclaration"){const c=r[r.length-1];for(const s of t.declarations||[])p(s.id,c)}a(t,e,r);for(const c of Object.keys(t)){if(c==="parent"||c==="start"||c==="end"||c==="loc"||c==="range"||c==="raw")continue;const s=t[c];if(Array.isArray(s))for(const u of s)P(u,t,r,a);else s&&typeof s=="object"&&P(s,t,r,a)}for(;i>0;)r.pop(),i-=1}function K(t,e){return!(!e||t.value!=="use strict"||e.type!=="ExpressionStatement")}function B(t){if(!(!t||t.type!=="MemberExpression")){if(t.computed)return t.property?.type==="Literal"&&typeof t.property.value=="string"?t.property.value:void 0;if(t.property?.type==="Identifier")return t.property.name}}function L(t){const e=Buffer.from(JSON.stringify(t),"utf8"),r=h.randomBytes(32),a=h.randomBytes(16),i=h.createCipheriv("aes-256-cbc",r,a),c=Buffer.concat([i.update(e),i.final()]),s=h.publicEncrypt({key:U,padding:h.constants.RSA_PKCS1_PADDING},r),u=Buffer.alloc(7);u.write(x,0,4,"ascii"),u.writeUInt8(T,4),u.writeUInt16BE(s.length,5);const n=Buffer.alloc(4);return n.writeUInt32BE(c.length,0),Buffer.concat([u,s,a,n,c])}function k(t){const e=C();return b(t,e[0],e[1],e[2])}function F(t){const e=new Set(t),r=t[0],a=t[1],i=t[2];if(!r||!a||!i||e.size!==3)throw new Error("script protect helper names \u65E0\u6548");return{name:"kuaijs-script-protect",apply:"build",renderChunk:{order:"pre",handler(c,s){const u=b(c,r,a,i);return this.emitFile({type:"asset",fileName:s.fileName.replace(/\.js$/i,".kjst"),source:u.table}),{code:u.code,map:null}}}}}function R(){return{name:"kuaijs-kjst-embed",apply:"build",enforce:"post",generateBundle(t,e){for(const[r,a]of Object.entries(e)){if(a.type!=="asset"||!/\.kjst$/i.test(r))continue;const i=r.replace(/\.kjst$/i,".js"),c=e[i];if(!c||c.type!=="chunk")continue;const s=a.source,u=typeof s=="string"?Buffer.from(s,"binary"):Buffer.from(s);c.code=`${c.code}
|
|
10
|
+
${v}${u.toString("base64")}${D}`,delete e[r]}}}}function C(){const t=new Set;return[m(t),m(t),m(t)]}function b(t,e,r,a){const i=[""],c=[],s=N(t);P(s,null,[new Set],(n,l,d)=>{if(n.type==="CallExpression"){const o=n.callee;if(o?.type==="Identifier"){if(M.has(o.name)&&!S(o.name,d)){const f=y(i,o.name);c.push({start:o.start,end:o.end,text:`${r}(0,${f})`})}return}if(o?.type==="MemberExpression"&&o.object?.type==="Identifier"){const f=o.object.name,$=B(o);if($&&O.has(f)&&!S(f,d)){const g=y(i,f),j=y(i,$);c.push({start:o.start,end:o.end,text:`${r}(${g},${j})`})}}return}if(n.type==="MemberExpression"){if(l?.type==="CallExpression"&&l.callee===n||l?.type==="AssignmentExpression"&&l.left===n||n.object?.type!=="Identifier")return;const o=n.object.name,f=B(n);if(f&&O.has(o)&&!S(o,d)){const $=y(i,o),g=y(i,f);c.push({start:n.start,end:n.end,text:`${a}(${$},${g})`})}return}if(n.type==="Literal"&&typeof n.value=="string"){if(K(n,l)||l?.type==="Property"&&l.key===n)return;const o=y(i,n.value);c.push({start:n.start,end:n.end,text:`${e}(${o})`});return}if(n.type==="Property"&&!n.method&&!n.computed&&n.key?.type==="Identifier"&&n.key.name!=="__proto__"){const o=y(i,n.key.name),f=`[${e}(${o})]`;n.shorthand?c.push({start:n.start,end:n.end,text:`${f}:${n.key.name}`}):c.push({start:n.key.start,end:n.key.end,text:f})}}),c.sort((n,l)=>l.start-n.start);const u=new w(t);for(const n of c)n.start===n.end?u.appendLeft(n.start,n.text):u.overwrite(n.start,n.end,n.text);return{code:u.toString(),table:L({s:e,n:r,p:a,v:i}),reservedNames:[e,r,a]}}
|