Skip to content

Commit

Permalink
test: use individual snapshot files
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Dec 3, 2023
1 parent 0dcbbd8 commit dd0e20d
Show file tree
Hide file tree
Showing 34 changed files with 785 additions and 915 deletions.
134 changes: 0 additions & 134 deletions packages/deobfuscate/test/__snapshots__/deobfuscate.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,139 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`deobfuscate obfuscator.io.js 1`] = `
"// v4.0.0
function hi() {
console.log(\\"Hello World!\\");
console.log( /*webcrack:decode_error*/undefined);
console.log( /*webcrack:decode_error*/undefined);
const p = true;
console.log(p ? \\"log\\" : \\"Hello World!\\");
}
hi();"
`;

exports[`deobfuscate obfuscator.io-calls-transform.js 1`] = `
"function foo() {
var c = \\"string1\\";
var d = \\"string2\\";
var e = \\"string3\\";
var f = \\"string4\\";
var g = \\"string5\\";
var h = \\"string6\\";
}
console.log(foo());"
`;

exports[`deobfuscate obfuscator.io-control-flow.js 1`] = `
"function applyTransforms() {
this.modules.forEach(varInjection_1.inlineVarInjections);
this.modules.forEach(esm_1.convertESM);
(0, getDefaultExport_1.convertDefaultRequire)(this);
this.replaceRequireCalls();
var f = m.capture(m.numericLiteral());
var g = m.callExpression(m.identifier(\\"require\\"), [f]);
return g;
}"
`;

exports[`deobfuscate obfuscator.io-control-flow-keys.js 1`] = `
"function hi() {
const _0x46643e = 1;
const _0x4d295f = 2;
if (_0x46643e < _0x4d295f) {
console.log(\\"Hello World!\\");
}
}
hi();"
`;

exports[`deobfuscate obfuscator.io-control-flow-partial-keys.js 1`] = `
"function hi() {
const _0x46643e = 1;
const _0x4d295f = 2;
if (_0x46643e < _0x4d295f) {
console.log(\\"Hello World!\\");
}
}
hi();"
`;

exports[`deobfuscate obfuscator.io-control-flow-split-strings.js 1`] = `
"function _0x225c6a() {
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
}
_0x225c6a();"
`;

exports[`deobfuscate obfuscator.io-control-flow-spread.js 1`] = `
"function hi() {
return m.functionExpression(undefined, captures.map(m.identifier), m.blockStatement(body(...captures.map(_0x56f63c => m.identifier(m.fromCapture(_0x56f63c))), ...arr)));
}
hi();"
`;

exports[`deobfuscate obfuscator.io-control-flow-switch-return.js 1`] = `
"function hi() {
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
console.log(\\"Hello World!\\");
return {
x: 1
};
}
hi();"
`;

exports[`deobfuscate obfuscator.io-function-wrapper.js 1`] = `
"function hi() {
console.log(\\"Hello World!\\");
console.log(30);
console.log(undefined);
function notAWrapper(c, d) {
return \\"log\\";
}
console.log(notAWrapper(foo(), bar()));
}
hi();"
`;

exports[`deobfuscate obfuscator.io-high.js 1`] = `
"function hi() {
console.log(\\"Hello World!\\");
}
hi();"
`;

exports[`deobfuscate obfuscator.io-multi-encoders.js 1`] = `
"function hi() {
console.log(\\"Hello World!\\");
}
hi();"
`;

exports[`deobfuscate obfuscator.io-rotator-unary.js 1`] = `
"function hi() {
console.log(\\"Hello World!\\");
}
hi();"
`;

exports[`deobfuscate simple-string-array.js 1`] = `
"console.log(\\"Hello, World!\\");
// ignore mutable array
const arr2 = [\\"log\\", \\"Hello, World!\\"];
arr2[0] = \\"warn\\";
console[arr2[0]](arr2[1]);"
`;

exports[`inline decoder > inline function 1`] = `
"function decoder() {}
decoder(1);
Expand Down
159 changes: 0 additions & 159 deletions packages/deobfuscate/test/__snapshots__/deobfuscator.test.ts.snap

This file was deleted.

25 changes: 0 additions & 25 deletions packages/deobfuscate/test/deobfuscate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,7 @@ import {
inlineFunctionAliases,
inlineVariableAliases,
} from '@webcrack/ast-utils';
import { readFile } from 'fs/promises';
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
import { webcrack } from '../../webcrack/src/index';

// Test samples
test.each([
'obfuscator.io.js',
'obfuscator.io-rotator-unary.js',
'obfuscator.io-multi-encoders.js',
'obfuscator.io-function-wrapper.js',
'obfuscator.io-calls-transform.js',
'obfuscator.io-control-flow.js',
'obfuscator.io-control-flow-split-strings.js',
'obfuscator.io-control-flow-keys.js',
'obfuscator.io-control-flow-partial-keys.js',
'obfuscator.io-control-flow-switch-return.js',
'obfuscator.io-control-flow-spread.js',
'obfuscator.io-high.js',
'simple-string-array.js',
])('deobfuscate %s', async (filename) => {
const result = await webcrack(
await readFile(join(__dirname, 'samples', filename), 'utf8'),
);
expect(result.code).toMatchSnapshot();
});

describe('inline decoder', () => {
test('inline variable', () => {
Expand Down
23 changes: 23 additions & 0 deletions packages/deobfuscate/test/samples.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { readFile, readdir } from 'fs/promises';
import { join } from 'node:path';
import { describe, test } from 'vitest';
import { webcrack } from '../../webcrack/src/index';

const SAMPLES_DIR = join(__dirname, 'samples');

describe('samples', async () => {
const fileNames = (await readdir(SAMPLES_DIR)).filter((name) =>
name.endsWith('.js'),
);

fileNames.forEach((fileName) => {
test.concurrent(`deobfuscate ${fileName}`, async ({ expect }) => {
const code = await readFile(join(SAMPLES_DIR, fileName), 'utf8');
const result = await webcrack(code);

await expect(result.code).toMatchFileSnapshot(
join(SAMPLES_DIR, fileName + '.snap'),
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function foo() {
var c = "string1";
var d = "string2";
var e = "string3";
var f = "string4";
var g = "string5";
var h = "string6";
}
console.log(foo());
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function hi() {
const _0x46643e = 1;
const _0x4d295f = 2;
if (_0x46643e < _0x4d295f) {
console.log("Hello World!");
}
}
hi();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function hi() {
const _0x46643e = 1;
const _0x4d295f = 2;
if (_0x46643e < _0x4d295f) {
console.log("Hello World!");
}
}
hi();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function _0x225c6a() {
console.log("Hello World!");
console.log("Hello World!");
console.log("Hello World!");
console.log("Hello World!");
console.log("Hello World!");
}
_0x225c6a();
Loading

0 comments on commit dd0e20d

Please sign in to comment.