Skip to content

Commit 6e20430

Browse files
committedSep 18, 2022
Add files
1 parent 0da4994 commit 6e20430

8 files changed

+4176
-1
lines changed
 

‎.eslintrc.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"node": true
5+
},
6+
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
7+
"parserOptions": {
8+
"ecmaVersion": 2020,
9+
"sourceType": "module"
10+
}
11+
}

‎.prettierrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 2,
3+
"semi": false,
4+
"singleQuote": true
5+
}

‎README.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
1-
# ASTBabel
1+
# decode-js
2+
3+
使用AST方式(依赖Babel插件)实现的JS代码净化工具,包括常见的几种类型:
4+
5+
* 字面量还原(全局、代码块)
6+
* 死代码清理、扁平化还原
7+
* 条件、循环语句规范化
8+
* 特殊函数清理
9+
10+
处理全局加密内容时使用VM2提供的环境。
11+
12+
## 使用
13+
14+
需要`node.js`环境,并安装依赖:`npm i`
15+
16+
调用方法:
17+
18+
```shell
19+
npm run xxx [input.js] [output.js]
20+
```
21+
22+
`xxx`为预定义的插件,见[package.json](package.json)中的`scripts`字段。
23+
24+
默认输入文件为`input.js`,默认输出文件为`output.js`
25+
26+
程序入口文件为:[src/main.js](src/main.js),插件目录为[src/plugin](src/plugin)
27+
28+
## 启发
29+
30+
参考了下面的项目:
31+
32+
* [cilame/v_jstools](https://github.com/cilame/v_jstools)
33+
* [Cqxstevexw/decodeObfuscator](https://github.com/Cqxstevexw/decodeObfuscator)
34+
* [NXY666/Jsjiemi](https://github.com/NXY666/Jsjiemi)
35+
36+

‎package-lock.json

+2,605
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "decode-js",
3+
"type": "module",
4+
"scripts": {
5+
"deob": "node src/main.js obfuscator",
6+
"deso": "node src/main.js sojson",
7+
"lint": "eslint --ext .js --ignore-path .gitignore --fix src"
8+
},
9+
"dependencies": {
10+
"@babel/generator": "^7.17.10",
11+
"@babel/parser": "^7.17.10",
12+
"@babel/traverse": "^7.17.10",
13+
"@babel/types": "^7.17.10",
14+
"eslint": "^8.23.0",
15+
"eslint-config-prettier": "^8.5.0",
16+
"eslint-plugin-prettier": "^4.2.1",
17+
"prettier": "^2.7.1",
18+
"vm2": "^3.9.11"
19+
}
20+
}

‎src/main.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from 'fs'
2+
import PluginSojson from './plugin/sojson.js'
3+
import PluginObfuscator from './plugin/obfuscator.js'
4+
5+
// 读取参数
6+
let type = 'obfuscator'
7+
if (process.argv.length > 2) {
8+
type = process.argv[2]
9+
}
10+
console.log(`类型: ${type}`)
11+
let encodeFile = 'input.js'
12+
if (process.argv.length > 3) {
13+
encodeFile = process.argv[3]
14+
}
15+
console.log(`输入: ${encodeFile}`)
16+
let decodeFile = 'output.js'
17+
if (process.argv.length > 4) {
18+
decodeFile = process.argv[4]
19+
}
20+
console.log(`输出: ${decodeFile}`)
21+
22+
// 读取源代码
23+
const sourceCode = fs.readFileSync(encodeFile, { encoding: 'utf-8' })
24+
25+
// 净化源代码
26+
let code
27+
if (type === 'sojson') {
28+
code = PluginSojson(sourceCode)
29+
} else if (type === 'obfuscator') {
30+
code = PluginObfuscator(sourceCode)
31+
}
32+
33+
// 输出代码
34+
fs.writeFile(decodeFile, code, () => {})

‎src/plugin/obfuscator.js

+874
Large diffs are not rendered by default.

‎src/plugin/sojson.js

+591
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.