Skip to content

Commit

Permalink
docs: add browser usage and sandbox explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Dec 2, 2024
1 parent 6d8c7f7 commit 3e2e416
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apps/docs/src/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ await webcrack(code, {
unminify: true, // Unminify the code
deobfuscate: true, // Deobfuscate the code
mangle: false, // Mangle variable names
sandbox, // Explained below
});
```

Expand All @@ -65,6 +66,43 @@ await webcrack(code, {
});
```

## Browser Usage & Sandbox

The `sandbox` option has to be passed when trying to deobfuscate string arrays in a browser.
In future versions, this should hopefully not be necessary anymore.

It is an (optionally async) function that takes a `code` parameter and returns the evaluated value.

::: danger Security warning
Simplest possible implementation, avoid using due to potentially executing malicious code
:::

```js
const result = await webcrack('function _0x317a(){....', { sandbox: eval });
```

More secure version with [sandybox](https://github.com/trentmwillis/sandybox) and CSP:

```js
const sandbox = await Sandybox.create();
const iframe = document.querySelector('.sandybox');
iframe?.contentDocument?.head.insertAdjacentHTML(
'afterbegin',
`<meta http-equiv="Content-Security-Policy" content="default-src 'none';">`,
);
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function evalCode(code) {
const fn = await sandbox.addFunction(`() => ${code}`);
return Promise.race([
fn(),
sleep(10_000).then(() => Promise.reject(new Error('Sandbox timeout'))),
]).finally(() => sandbox.removeFunction(fn));
}

const result = await webcrack('function _0x317a(){....', { sandbox: evalCode });
```
## Customize Paths
Useful for reverse-engineering and tracking changes across multiple versions of a bundle.
Expand Down

0 comments on commit 3e2e416

Please sign in to comment.