mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
rc4 preparation
This commit is contained in:
@@ -102,29 +102,28 @@ describe('JavaScriptObfuscator', () => {
|
||||
});
|
||||
|
||||
it('should obfuscate simple code with literal variable value', () => {
|
||||
let pattern: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/;
|
||||
|
||||
assert.match(
|
||||
JavaScriptObfuscator.obfuscate(
|
||||
let pattern1: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\];/,
|
||||
pattern2: RegExp = /var *test *= *_0x(\w){4}\('0x0'\);$/,
|
||||
obfuscatedCode1: string = JavaScriptObfuscator.obfuscate(
|
||||
`var test = 'abc';`,
|
||||
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
|
||||
unicodeArray: true,
|
||||
unicodeArrayThreshold: 1
|
||||
})
|
||||
).getObfuscatedCode(),
|
||||
pattern
|
||||
);
|
||||
|
||||
assert.match(
|
||||
JavaScriptObfuscator.obfuscate(
|
||||
obfuscatedCode2: string = JavaScriptObfuscator.obfuscate(
|
||||
`var test = 'абц';`,
|
||||
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
|
||||
unicodeArray: true,
|
||||
unicodeArrayThreshold: 1
|
||||
})
|
||||
).getObfuscatedCode(),
|
||||
pattern
|
||||
);
|
||||
).getObfuscatedCode();
|
||||
|
||||
assert.match(obfuscatedCode1, pattern1);
|
||||
assert.match(obfuscatedCode1, pattern2);
|
||||
|
||||
assert.match(obfuscatedCode2, pattern1);
|
||||
assert.match(obfuscatedCode2, pattern2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+4
-12
@@ -5,7 +5,7 @@ import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('UnicodeArrayCallsWrapper', () => {
|
||||
it('should correctly appendNode `UnicodeArrayCallsWrapper` custom node into the obfuscated code if `wrapUnicodeArrayCalls` option is set', () => {
|
||||
it('should correctly appendNode `UnicodeArrayCallsWrapper` custom node into the obfuscated code', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
`var test = 'test';`,
|
||||
{
|
||||
@@ -13,17 +13,9 @@ describe('UnicodeArrayCallsWrapper', () => {
|
||||
}
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /return _0x([a-z0-9]){4}\[parseInt\(_0x([a-z0-9]){4,6}, *0x010\)\];/);
|
||||
});
|
||||
|
||||
it('should\'t appendNode `UnicodeArrayDecodeNode` custom node into the obfuscated code if `wrapUnicodeArrayCalls` option is not set', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
`var test = 'test';`,
|
||||
{
|
||||
wrapUnicodeArrayCalls: false
|
||||
}
|
||||
assert.match(
|
||||
obfuscationResult.getObfuscatedCode(),
|
||||
/var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4}\[parseInt\(_0x([a-z0-9]){4,6}, *0x10\)\];/
|
||||
);
|
||||
|
||||
assert.notMatch(obfuscationResult.getObfuscatedCode(), /return _0x([a-z0-9]){4}\[parseInt\(_0x([a-z0-9]){4,6}, *0x010\)\];/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
|
||||
|
||||
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('UnicodeArrayDecodeNode', () => {
|
||||
it('should correctly appendNode `UnicodeArrayDecodeNode` custom node into the obfuscated code if `encodeUnicodeLiterals` option is set', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
`var test = 'test';`,
|
||||
{
|
||||
encodeUnicodeLiterals: true
|
||||
}
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /decodeURI\(atob\(_0x([a-z0-9]){4}\[_0x([a-z0-9]){4,6}\]\)\)/);
|
||||
});
|
||||
|
||||
it('should\'t appendNode `UnicodeArrayDecodeNode` custom node into the obfuscated code if `encodeUnicodeLiterals` option is not set', () => {
|
||||
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
`var test = 'test';`,
|
||||
{
|
||||
encodeUnicodeLiterals: false
|
||||
}
|
||||
);
|
||||
|
||||
assert.notMatch(obfuscationResult.getObfuscatedCode(), /decodeURI\(atob\(_0x([a-z0-9]){4}\[_0x([a-z0-9]){4,6}\]\)\)/);
|
||||
});
|
||||
});
|
||||
@@ -27,7 +27,7 @@ describe('MemberExpressionObfuscator', () => {
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){4} *= *\['\\x6c\\x6f\\x67'\];/);
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\[0x0\]\];/);
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\('0x0'\)\];/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('MemberExpressionObfuscator', () => {
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){4} *= *\['\\x6c\\x6f\\x67'\];/);
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\[0x0\]\];/);
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\('0x0'\)\];/);
|
||||
});
|
||||
|
||||
it('should ignore square brackets call with identifier value', () => {
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('MethodDefinitionObfuscator', () => {
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){4} *= *\['\\x62\\x61\\x72'\];/);
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /\[_0x([a-z0-9]){4}\[0x0\]\]\(\)\{\}/);
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /\[_0x([a-z0-9]){4}\('0x0'\)\]\(\)\{\}/);
|
||||
});
|
||||
|
||||
it('should not obfuscate method definition node with `constructor` key', () => {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import 'format-unicorn';
|
||||
|
||||
import { AtobTemplate } from '../../../../../src/templates/custom-nodes/AtobTemplate';
|
||||
import { UnicodeArrayDecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/UnicodeArrayDecodeNodeTemplate';
|
||||
import { UnicodeArrayAtobDecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate';
|
||||
|
||||
import { Utils } from '../../../../../src/Utils';
|
||||
|
||||
@@ -13,7 +13,7 @@ const assert: Chai.AssertStatic = require('chai').assert;
|
||||
* @returns {Function}
|
||||
*/
|
||||
function getFunctionFromTemplate (templateData: any, unicodeArrayName: string) {
|
||||
let domainLockTemplate: string = UnicodeArrayDecodeNodeTemplate().formatUnicorn(templateData);
|
||||
let domainLockTemplate: string = UnicodeArrayAtobDecodeNodeTemplate().formatUnicorn(templateData);
|
||||
|
||||
return Function(`
|
||||
var ${unicodeArrayName} = ['${Utils.btoa('test1')}', '${Utils.btoa('test2')}'];
|
||||
@@ -24,7 +24,7 @@ function getFunctionFromTemplate (templateData: any, unicodeArrayName: string) {
|
||||
`)();
|
||||
}
|
||||
|
||||
describe('UnicodeArrayDecodeNodeTemplate (): string', () => {
|
||||
describe('UnicodeArrayAtobDecodeNodeTemplate (): string', () => {
|
||||
let forLoopFunctionName: string = 'forLoop',
|
||||
code: string = `${forLoopFunctionName}();`,
|
||||
unicodeArrayName: string = 'unicodeArray';
|
||||
|
||||
@@ -27,7 +27,6 @@ import './functional-tests/JavaScriptObfuscatorInternal.spec';
|
||||
import './functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec';
|
||||
import './functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec';
|
||||
import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.spec';
|
||||
import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.spec';
|
||||
import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.spec';
|
||||
import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayNode.spec';
|
||||
import './functional-tests/node-obfuscators/FunctionObfuscator.spec';
|
||||
|
||||
Reference in New Issue
Block a user