-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move cli logic to bin/deobfuscate.js * Adjust usage documentation * 2.0.2
- Loading branch information
1 parent
a832a8f
commit 6009a3e
Showing
6 changed files
with
63 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,13 @@ For comments and suggestions feel free to open an issue or find me on Twitter - | |
|
||
## Installation | ||
### npm | ||
```bash | ||
npm install restringer | ||
```shell | ||
npm install -g restringer | ||
``` | ||
|
||
### Clone The Repo | ||
Requires Node 16 or newer. | ||
```bash | ||
```shell | ||
git clone [email protected]:PerimeterX/restringer.git | ||
cd restringer | ||
npm install | ||
|
@@ -44,7 +44,6 @@ there's a need to apply specific deobfuscation methods in order to circumvent an | |
preventing the script from being deobfuscated. | ||
|
||
### Command-Line Usage | ||
|
||
``` | ||
Usage: restringer input_filename [-h] [-c] [-q | -v] [-m M] [-o [output_filename]] | ||
|
@@ -55,16 +54,35 @@ optional arguments: | |
-h, --help Show this help message and exit. | ||
-c, --clean Remove dead nodes from script after deobfuscation is complete (unsafe). | ||
-q, --quiet Suppress output to stdout. Output result only to stdout if the -o option is not set. | ||
Does not go with the -v option. | ||
Does not go with the -v option. | ||
-m, --max-iterations M Run at most M iterations | ||
-v, --verbose Show more debug messages while deobfuscating. Does not go with the -q option. | ||
-o, --output [output_filename] Write deobfuscated script to output_filename. | ||
Use <input_filename>-deob.js if no filename is provided. | ||
<input_filename>-deob.js is used if no filename is provided. | ||
``` | ||
Examples: | ||
- Print the deobfuscated script to stdout. | ||
```shell | ||
restringer [target-file.js] | ||
``` | ||
- Save the deobfuscated script to output.js. | ||
```shell | ||
restringer [target-file.js] -o output.js | ||
``` | ||
- Deobfuscate and print debug info. | ||
```shell | ||
restringer [target-file.js] -v | ||
``` | ||
- Deobfuscate without printing anything but the deobfuscated output. | ||
```shell | ||
restringer [target-file.js] -q | ||
``` | ||
|
||
|
||
### Use as a Module | ||
|
||
```javascript | ||
const {REstringer} = require('restringer'); | ||
import {REstringer} from 'restringer'; | ||
|
||
const restringer = new REstringer('"RE" + "stringer"'); | ||
if (restringer.deobfuscate()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
import {REstringer} from '../src/restringer.js'; | ||
import {argsAreValid, parseArgs} from'../src/utils/parseArgs.js'; | ||
|
||
try { | ||
const args = parseArgs(process.argv.slice(2)); | ||
if (argsAreValid(args)) { | ||
const fs = await import('node:fs'); | ||
let content = fs.readFileSync(args.inputFilename, 'utf-8'); | ||
const startTime = Date.now(); | ||
|
||
const restringer = new REstringer(content); | ||
if (args.quiet) restringer.logger.setLogLevelNone(); | ||
else if (args.verbose) restringer.logger.setLogLevelDebug(); | ||
restringer.logger.log(`[!] REstringer v${REstringer.__version__}`); | ||
restringer.logger.log(`[!] Deobfuscating ${args.inputFilename}...`); | ||
if (args.maxIterations) { | ||
restringer.maxIterations.value = args.maxIterations; | ||
restringer.logger.log(`[!] Running at most ${args.maxIterations} iterations`); | ||
} | ||
if (restringer.deobfuscate()) { | ||
restringer.logger.log(`[+] Saved ${args.outputFilename}`); | ||
restringer.logger.log(`[!] Deobfuscation took ${(Date.now() - startTime) / 1000} seconds.`); | ||
if (args.outputToFile) fs.writeFileSync(args.outputFilename, restringer.script, {encoding: 'utf-8'}); | ||
else console.log(restringer.script); | ||
} else restringer.logger.log(`[-] Nothing was deobfuscated ¯\\_(ツ)_/¯`); | ||
} | ||
} catch (e) { | ||
console.error(`[-] Critical Error: ${e}`); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters