1 line
8.7 KiB
JavaScript
1 line
8.7 KiB
JavaScript
|
script_functionTable1=["nop","jump","set","print","dialog","getitem","substr","indexof","split","join","length","jsonparse","jsonstr","add","substract","parseint","wsbatchenum","wsput","wscreate","wsdelete","wsexec","scriptspeed","wssubscribe","wsunsubscribe","readchar","signwithdummyca"];script_functionTable2=["encodeuri","decodeuri","passwordcheck","atob","btoa","hex2str","str2hex","random","md5","maketoarray","readshort","readshortx","readint","readsint","readintx","shorttostr","shorttostrx","inttostr","inttostrx"];script_functionTableX2=[encodeURI,decodeURI,passwordcheck,atob,btoa,hex2rstr,rstr2hex,random,rstr_md5,MakeToArray,ReadShort,ReadShortX,ReadInt,ReadSInt,ReadIntX,ShortToStr,ShortToStrX,IntToStr,IntToStrX];function MakeToArray(a){if(!a||a==null||typeof a=="object"){return a}return[a]}function ReadShort(b,a){return(b[a]<<8)+b[a+1]}function ReadShortX(b,a){return(b[a+1]<<8)+b[a]}function ReadInt(b,a){return(b[a]*16777216)+(b[a+1]<<16)+(b[a+2]<<8)+b[a+3]}function ReadSInt(b,a){return(b[a]<<24)+(b[a+1]<<16)+(b[a+2]<<8)+b[a+3]}function ReadIntX(b,a){return(b[a+3]*16777216)+(b[a+2]<<16)+(b[a+1]<<8)+b[a]}function ShortToStr(a){return String.fromCharCode((a>>8)&255,a&255)}function ShortToStrX(a){return String.fromCharCode(a&255,(a>>8)&255)}function IntToStr(a){return String.fromCharCode((a>>24)&255,(a>>16)&255,(a>>8)&255,a&255)}function IntToStrX(a){return String.fromCharCode(a&255,(a>>8)&255,(a>>16)&255,(a>>24)&255)}function btoa(a){return Buffer.from(a).toString("base64")}function atob(b){var c=null;try{c=Buffer.from(b,"base64").toString()}catch(a){console.log(a)}return c}function passwordcheck(g){if(g.length<8){return false}var h=0,d=0,f=0,e=0;for(var b in g){var a=g.charCodeAt(b);if((a>64)&&(a<91)){h=1}else{if((a>96)&&(a<123)){d=1}else{if((a>47)&&(a<58)){f=1}else{e=1}}}}return((h+d+f+e)==4)}function hex2rstr(a){Buffer.from(a,"hex").toString()}function rstr2hex(a){Buffer.from(a).toString("hex")}function random(){return Math.floor(Math.random()*max)}function rstr_md5(a){return hex2rstr(hex_md5(a))}function getItem(b,c,d){for(var a in b){if(b[a][c]==d){return b[a]}}return null}var httpErrorTable={200:"OK",401:"Authentication Error",408:"Timeout Error",601:"WSMAN Parsing Error",602:"Unable to parse HTTP response header",603:"Unexpected HTTP enum response",604:"Unexpected HTTP pull response",998:"Invalid TLS certificate"};module.exports.setup=function(a,c){var b={startvars:c,onCompleted:null};if(a.length<6){console.error("Invalid script length");return null}if(ReadInt(a,0)!=612182341){console.error("Invalid binary script");return null}if(ReadShort(a,4)>1){console.error("Unsupported script version");return null}b.script=a.slice(6);b.reset=function(d){b.stop();b.ip=0;b.variables=c;b.state=1};b.start=function(d){b.stop();if(d==null){b.stepspeed=10}else{b.stepspeed=d}if(b.stepspeed>0){b.timer=setInterval(function(){b.step()},b.stepspeed)}};b.stop=function(){if(b.timer!=null){clearInterval(b.timer)}b.timer=null;b.stepspeed=0};b.getVar=function(d){if(d==undefined){return undefined}return b.getVarEx(d.split("."),b.variables)};b.getVarEx=function(f,g){try{if(f==undefined){return undefined}if(f.length==0){return g}return b.getVarEx(f.slice(1),g[f[0]])}catch(d){return null}};b.setVar=function(d,e){b.setVarEx(d.split("."),b.variables,e)};b.setVarEx=function(d,f,e){if(d.length==1){f[d[0]]=e}else{b.setVarEx(d.slice(1),f[d[0]],e)}};b.step=function(){if(b.state!=1){return}if(b.ip<b.script.length){var m=ReadShort(b.script,b.ip);var n=ReadShort(b.script,b.ip+2);var d=ReadShort(b.script,b.ip+4);var g=b.ip+6;var h=[];for(var p in b.variables){if(p.startsWith("__")){delete b.variables[p]}}for(var p=0;p<d;p++){var f=ReadShort(b.script,g);var l=b.script.slice(g+2,g+2+f);var k=l[0];l=l.slice(1);if(k<2){l=l.toString();if(l!=null){while(l.split("{").length>1){var r=l.split("{").pop().split("}").shift();l=l.replace("{"+r+"}",b.getVar(r))}}if(k==1){b.variables["__"+p]=decodeURI(l);l="__"+p}h.push(l)}if(k==2||k==3){b.variables["__"+p]=ReadSInt(l,0);h.push("__"+p)}g+=(2+f)}b.ip+=n;var j=[];for(var p=0;p<10;p++){j.push(b.getVar(h[p]))}var q;try{i
|