Skip to content

Commit

Permalink
refactor: switch back to vm2
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jun 4, 2023
1 parent cd5e842 commit d048be1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@ jobs:
node-version: '18.x'
cache: 'npm'

- name: Cache node modules
id: nodemodules-cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
if: steps.nodemodules-cache.outputs.cache-hit != 'true'
run: npm ci

- name: Run tests
Expand Down
48 changes: 27 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@babel/types": "^7.21.4",
"@codemod/matchers": "^1.7.0",
"commander": "^10.0.0",
"isolated-vm": "^4.5.0"
"vm2": "^3.9.19"
},
"devDependencies": {
"@types/babel__generator": "^7.6.4",
Expand Down
18 changes: 8 additions & 10 deletions src/deobfuscator/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ export type Sandbox = (code: string) => Promise<unknown>;

export function createNodeSandbox(): (code: string) => Promise<unknown> {
return async (code: string) => {
const {
default: { Isolate },
} = await import('isolated-vm');
const isolate = new Isolate();
const context = await isolate.createContext();
return (await context.eval(code, {
timeout: 10_000,
copy: true,
filename: 'file:///obfuscated.js',
})) as unknown;
const { VM } = await import('vm2');
const vm = new VM({
timeout: 30_000,
allowAsync: false,
eval: false,
wasm: false,
});
return vm.run(code) as unknown;
};
}

Expand Down
1 change: 0 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export default defineConfig({
test: {
forceRerunTriggers: ['**/samples/**'],
setupFiles: 'test/setup.ts',
threads: false, // https://github.com/laverdet/isolated-vm/issues/138
},
});

0 comments on commit d048be1

Please sign in to comment.