Skip to content

Commit 0ec75ad

Browse files
committed
AntiTooling
1 parent 66a32b6 commit 0ec75ad

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs')
22
const PluginCommon = require('./plugin/common.js')
33
const PluginJjencode = require('./plugin/jjencode.js')
4+
const PluginJsconfuser = require('./plugin/jsconfuser.js')
45
const PluginSojson = require('./plugin/sojson.js')
56
const PluginSojsonV7 = require('./plugin/sojsonv7.js')
67
const PluginObfuscator = require('./plugin/obfuscator.js')
@@ -40,6 +41,8 @@ if (type === 'sojson') {
4041
code = PluginAwsc(sourceCode)
4142
} else if (type === 'jjencode') {
4243
code = PluginJjencode(sourceCode)
44+
} else if (type === 'jsconfuser') {
45+
code = PluginJsconfuser(sourceCode)
4346
} else {
4447
code = PluginCommon(sourceCode)
4548
}

src/plugin/jsconfuser.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const { parse } = require('@babel/parser')
2+
const generator = require('@babel/generator').default
3+
const traverse = require('@babel/traverse').default
4+
const t = require('@babel/types')
5+
const ivm = require('isolated-vm')
6+
7+
const isolate = new ivm.Isolate()
8+
const globalContext = isolate.createContextSync()
9+
function virtualGlobalEval(jsStr) {
10+
return globalContext.evalSync(String(jsStr))
11+
}
12+
13+
function deAntiToolingCheckFunc(path) {
14+
if (path.node.params.length) {
15+
return false
16+
}
17+
const body = path.node.body
18+
if (!t.isBlockStatement(body)) {
19+
return false
20+
}
21+
if (body.body.length) {
22+
return false
23+
}
24+
return true
25+
}
26+
27+
function deAntiToolingExtract(path, func_name) {
28+
let binding = path.scope.getBinding(func_name)
29+
for (let ref of binding.referencePaths) {
30+
if (!ref.parentPath.isCallExpression() || !ref.key === 'callee') {
31+
continue
32+
}
33+
const call = ref.parentPath
34+
if (!call.listKey === 'body') {
35+
continue
36+
}
37+
for (let node of call.node.arguments) {
38+
call.insertBefore(node)
39+
}
40+
call.remove()
41+
}
42+
binding.scope.crawl()
43+
binding = path.scope.getBinding(func_name)
44+
if (binding.references === 0) {
45+
path.remove()
46+
}
47+
}
48+
49+
const deAntiTooling = {
50+
FunctionDeclaration(path) {
51+
const func_name = path.node.id?.name
52+
if (!func_name) {
53+
return
54+
}
55+
if (!deAntiToolingCheckFunc(path)) {
56+
return
57+
}
58+
console.log(`AntiTooling Func Name: ${func_name}`)
59+
deAntiToolingExtract(path, func_name)
60+
},
61+
}
62+
63+
module.exports = function (code) {
64+
let ast
65+
try {
66+
ast = parse(code, { errorRecovery: true })
67+
} catch (e) {
68+
console.error(`Cannot parse code: ${e.reasonCode}`)
69+
return null
70+
}
71+
// AntiTooling
72+
traverse(ast, deAntiTooling)
73+
code = generator(ast, {
74+
comments: false,
75+
jsescOption: { minimal: true },
76+
}).code
77+
return code
78+
}

0 commit comments

Comments
 (0)