Commit c6882bcc authored by wang's avatar wang

222

parent 277f824d
const fs = require('fs');
const types = require("@babel/types");
const parser = require("@babel/parser");
const {log} = require('console');
const traverse = require("@babel/traverse").default;
const generator = require("@babel/generator").default;
//js混淆代码读取
process.argv.length > 2 ? encodeFile = process.argv[2] : encodeFile = "./shape.js";
process.argv.length > 3 ? decodeFile = process.argv[3] : decodeFile = "./out.js";
//将源代码解析为AST
let sourceCode = fs.readFileSync(encodeFile, {encoding: "utf-8"});
let ast = parser.parse(sourceCode, {sourceType: 'script'});
traverse(ast, {
BinaryExpression(path){
let {node} = path;
let parent = path.parentPath.node;
let {left, operator, right} = node;
if (['>>>', '>>', '<', '>', '=', '+','-','*','/','^','&','%','<<','<<<','|','==','===','<=','>='].indexOf(operator) > -1){
if(types.isMemberExpression(left) && types.isMemberExpression(right)){
let {object: leftObject, property: leftproperty} = left;
if (types.isMemberExpression(leftObject) && types.isBinaryExpression(leftproperty)){
if(types.isCallExpression(parent))return
debugger
path.parentPath.insertBefore(types.ExpressionStatement(
types.CallExpression(
// types.MemberExpression(types.Identifier('console'), types.Identifier('log')),
types.Identifier('con5'),
[
types.StringLiteral(generator(node).code),
left,
types.StringLiteral(operator),
right,
types.StringLiteral('='),
node
]
)
))
path.skip()
}
}else if (types.isIdentifier(left) && types.isIdentifier(right)){
if(types.isAssignmentExpression(parent)){
let {left:inleft, right:inright, operator:inoperator} = parent;
path.parentPath.insertBefore(types.ExpressionStatement(
types.CallExpression(
// types.MemberExpression(types.Identifier('console'), types.Identifier('log')),
types.Identifier('con5'),
[
types.StringLiteral(generator(inleft).code),
types.Identifier(left.name),
types.StringLiteral(operator),
types.Identifier(right.name),
types.StringLiteral('='),
node
]
)
))
}
}else{
console.log(generator(parent).code)
}
}
}
})
console.time("处理完毕,耗时");
console.timeEnd("处理完毕,耗时");
let {code} = generator(ast, opts = {jsescOption: {"minimal": true}});
fs.writeFile(decodeFile, code, (err) => {
});
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -9,6 +9,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.23.9",
"@babel/types": "^7.23.9",
"abab": "^2.0.5",
"acorn": "^8.4.1",
"acorn-globals": "^6.0.0",
......
......@@ -1436,10 +1436,10 @@
// }
con3(q.w[q.w.length - 2],'get',q.w[q.w.length - 1],'=', res)
// if (q.w[q.w.length - 2].byteOffset !== undefined || typeof res === 'boolean'){
// con5(q.w[q.w.length - 2],'get',q.w[q.w.length - 1],'=', res)
//
// }
if (typeof res === 'boolean'){
con5(q.w[q.w.length - 2],'get',q.w[q.w.length - 1],'=', res)
}
q.w[q.w.length - 2] =res;
q.w.length -= 1
}, function (q) {
......@@ -1449,10 +1449,10 @@
var J = q.w.length - 1;
q.w[J] = L;
if (k === 'slice'){
// debugger;
con5('slice', L)
}
// if (k === 'slice'){
// // debugger;
// con5('slice', L)
// }
q.w[J + 1] = L[k]
}, function (q) {
var J = l[z[q.f] << 8 | z[q.f + 1]];
......@@ -1499,7 +1499,9 @@
q.w.length -= 1
}, function (q) {
"use strict";
q.w[q.w.length - 2] = delete q.w[q.w.length - 2][q.w[q.w.length - 1]];
let res = delete q.w[q.w.length - 2][q.w[q.w.length - 1]];
con5(q.w[q.w.length -2 ],'delete',q.w[q.w.length - 1] ,'=', res);
q.w[q.w.length - 2] = res;
q.w.length -= 1
}, function (J) {
var q = z[J.f] << 8 | z[J.f + 1];
......@@ -2796,18 +2798,18 @@ if (q.w[q.w.length - 2] === 'cpHash'){
let res = Reflect.get(target, p, receiver);
// debugger;
// }
if (p === 'exec') {
return v_saf(function (args) {
_print(`${target} exec1`, args)
// if (args.indexOf('strokeStyle')> -1){
// debugger;
// }
return new RegExp(target).exec(args)
// if (target === /{\s*\[\s*native\s+code\s*]\s*}\s*$/){
// return /{\s*\[\s*native\s+code\s*]\s*}\s*$/.exec(args)
// }
})
}
// if (p === 'exec') {
return v_saf(function (args) {
_print(`${target} ${p}`, args)
// if (args.indexOf('strokeStyle')> -1){
// debugger;
// }
return new RegExp(target).exec(args)
// if (target === /{\s*\[\s*native\s+code\s*]\s*}\s*$/){
// return /{\s*\[\s*native\s+code\s*]\s*}\s*$/.exec(args)
// }
})
// }
return res;
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment