Skip to content

Commit

Permalink
AntiTooling
Browse files Browse the repository at this point in the history
  • Loading branch information
echo094 committed Sep 7, 2024
1 parent b4421f1 commit f3e84b0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs')
const PluginCommon = require('./plugin/common.js')
const PluginJjencode = require('./plugin/jjencode.js')
const PluginJsconfuser = require('./plugin/jsconfuser.js')
const PluginSojson = require('./plugin/sojson.js')
const PluginSojsonV7 = require('./plugin/sojsonv7.js')
const PluginObfuscator = require('./plugin/obfuscator.js')
Expand Down Expand Up @@ -40,6 +41,8 @@ if (type === 'sojson') {
code = PluginAwsc(sourceCode)
} else if (type === 'jjencode') {
code = PluginJjencode(sourceCode)
} else if (type === 'jsconfuser') {
code = PluginJsconfuser(sourceCode)
} else {
code = PluginCommon(sourceCode)
}
Expand Down
78 changes: 78 additions & 0 deletions src/plugin/jsconfuser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const { parse } = require('@babel/parser')
const generator = require('@babel/generator').default
const traverse = require('@babel/traverse').default
const t = require('@babel/types')
const ivm = require('isolated-vm')

const isolate = new ivm.Isolate()
const globalContext = isolate.createContextSync()
function virtualGlobalEval(jsStr) {
return globalContext.evalSync(String(jsStr))
}

function deAntiToolingCheckFunc(path) {
if (path.node.params.length) {
return false
}
const body = path.node.body
if (!t.isBlockStatement(body)) {
return false
}
if (body.body.length) {
return false
}
return true
}

function deAntiToolingExtract(path, func_name) {
let binding = path.scope.getBinding(func_name)
for (let ref of binding.referencePaths) {
if (!ref.parentPath.isCallExpression() || !ref.key === 'callee') {
continue
}
const call = ref.parentPath
if (!call.listKey === 'body') {
continue
}
for (let node of call.node.arguments) {
call.insertBefore(node)
}
call.remove()
}
binding.scope.crawl()
binding = path.scope.getBinding(func_name)
if (binding.references === 0) {
path.remove()
}
}

const deAntiTooling = {
FunctionDeclaration(path) {
const func_name = path.node.id?.name
if (!func_name) {
return
}
if (!deAntiToolingCheckFunc(path)) {
return
}
console.log(`AntiTooling Func Name: ${func_name}`)
deAntiToolingExtract(path, func_name)
},
}

module.exports = function (code) {
let ast
try {
ast = parse(code, { errorRecovery: true })
} catch (e) {
console.error(`Cannot parse code: ${e.reasonCode}`)
return null
}
// AntiTooling
traverse(ast, deAntiTooling)
code = generator(ast, {
comments: false,
jsescOption: { minimal: true },
}).code
return code
}

0 comments on commit f3e84b0

Please sign in to comment.