Skip to content

Commit

Permalink
feat: CLI flags for disabling jsx/unpack/deobfuscate/minify
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jan 31, 2024
1 parent 9c84d90 commit e6b584f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
29 changes: 21 additions & 8 deletions apps/docs/src/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Options:
-o, --output <path> output directory for bundled files
-f, --force overwrite output directory
-m, --mangle mangle variable names
--no-jsx do not decompile JSX
--no-unpack do not extract modules from the bundle
--no-deobfuscate do not deobfuscate the code
--no-unminify do not unminify the code
-h, --help display help for command
```

Expand All @@ -35,7 +39,7 @@ To write the code to a file, you can do:
webcrack input.js > output.js
```

## Bundle Unpacking
## Unpack Bundles

Use the `-o` option to unpack a bundle into a directory:

Expand All @@ -50,12 +54,21 @@ The output directory will contain the following files:
- `index.js` - entry point
- all remaining modules (`1.js`, `2.js`, etc.)

::: tip
You can modify the unpacked modules and bundle them again:
## Invoke from other programming languages

```bash
npx webpack-cli ./output/index.js
```
If the the package is installed locally instead of globally, the path of the CLI would look like `node_modules/.bin/webcrack`.

Spawn a new process where the code is piped to stdin.
The logs will be written to stderr and the output code will be written to stdout.

Depending on how the bundle was created, you may need a custom [webpack config](https://webpack.js.org/configuration).
:::
Example in Python:

```py
import subprocess

code = "1+1"
result = subprocess.run(
["webcrack"], input=code, capture_output=True, text=True
)
print(result.stdout)
```
14 changes: 11 additions & 3 deletions packages/webcrack/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ debug.enable('webcrack:*');
interface Options {
force: boolean;
output?: string;
mangle?: boolean;
mangle: boolean;
jsx: boolean;
unpack: boolean;
deobfuscate: boolean;
unminify: boolean;
}

async function readStdin() {
Expand All @@ -34,9 +38,13 @@ program
.option('-o, --output <path>', 'output directory for bundled files')
.option('-f, --force', 'overwrite output directory')
.option('-m, --mangle', 'mangle variable names')
.option('--no-jsx', 'do not decompile JSX')
.option('--no-unpack', 'do not extract modules from the bundle')
.option('--no-deobfuscate', 'do not deobfuscate the code')
.option('--no-unminify', 'do not unminify the code')
.argument('[file]', 'input file, defaults to stdin')
.action(async (input: string | undefined) => {
const { output, force, mangle } = program.opts<Options>();
const { output, force, ...options } = program.opts<Options>();
const code = await (input ? readFile(input, 'utf8') : readStdin());

if (output) {
Expand All @@ -47,7 +55,7 @@ program
}
}

const result = await webcrack(code, { mangle });
const result = await webcrack(code, options);

if (output) {
await result.save(output);
Expand Down

0 comments on commit e6b584f

Please sign in to comment.