Skip to content

Commit f655457

Browse files
authored
Add CLI Support (#8)
* Add simple CLI support * Update eslint * 1.1.5
1 parent bca267a commit f655457

File tree

4 files changed

+88
-43
lines changed

4 files changed

+88
-43
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Detect different types of JS obfuscation by their AST structure.
88
`npm install obfuscation-detector`
99

1010
## Usage
11+
### Module
1112
```javascript
1213
const fs = require('fs');
1314
const detectObfuscation = require('obfuscation-detector');
@@ -18,6 +19,19 @@ const most_likely_obfuscation_type = detectObfuscation(code);
1819
console.log(`Obfuscation type is probably ${most_likely_obfuscation_type}`);
1920
```
2021

22+
### CLI
23+
> obfuscation-detector /path/to/obfuscated.js [stopAfterFirst]
24+
25+
Getting all matching obfuscation types for a file:
26+
> $ obfuscation-detector /path/to/obfuscated.js
27+
> [+] function_to_array_replacements, augmented_proxied_array_function_replacements
28+
29+
Getting just the first match:
30+
> $ obfuscation-detector /path/to/obfuscated.js stop
31+
> [+] function_to_array_replacements
32+
33+
The `stopAfterFirst` arguments doesn't have to be any specific string, it just needs not to be empty.
34+
2135
## Supported Obfuscation Types
2236
You can find descriptions of the different types in the code itself, and more info [here](src/detectors/README.md).
2337
- [Array Replacements](src/detectors/arrayReplacements.js)

bin/obfuscation-detector.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env node
2+
const fs = require('node:fs');
3+
const detectObfuscation = require(__dirname + '/../src');
4+
5+
if (require.main === module) {
6+
try {
7+
const args = process.argv.slice(2);
8+
if (args.length) {
9+
let content = fs.readFileSync(args[0], 'utf-8');
10+
const stopAfterFirst = !!args[1];
11+
const obfuscationType = detectObfuscation(content, stopAfterFirst);
12+
if (obfuscationType.length) console.log('[+] ' + obfuscationType.join(', '));
13+
else console.log('[-] No obfuscation detected / unknown obfuscation');
14+
} else console.log('Usage: obfuscation-detector /path/to/obfuscated.js [stopAfterFirst]');
15+
} catch (e) {
16+
console.error(`[X] Critical Error: ${e.message}`);
17+
}
18+
}

package-lock.json

Lines changed: 51 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obfuscation-detector",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Javascript obfuscation detector",
55
"main": "src/index.js",
66
"directories": {
@@ -10,6 +10,9 @@
1010
"scripts": {
1111
"test": "node tests/testDetectors.js"
1212
},
13+
"bin": {
14+
"obfuscation-detector": "./bin/obfuscation-detector.js"
15+
},
1316
"repository": {
1417
"type": "git",
1518
"url": "git+https://github.com/PerimeterX/obfuscation-detector.git"
@@ -28,7 +31,7 @@
2831
},
2932
"homepage": "https://github.com/PerimeterX/obfuscation-detector#readme",
3033
"devDependencies": {
31-
"eslint": "^8.43.0",
34+
"eslint": "^8.45.0",
3235
"husky": "^8.0.1"
3336
},
3437
"dependencies": {

0 commit comments

Comments
 (0)