1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { JavaScriptObfuscator } from "../src/JavaScriptObfuscator";
- import { DEFAULT_PRESET } from "../src/preset-options/DefaultPreset";
- import { NO_CUSTOM_NODES_PRESET } from "../src/preset-options/NoCustomNodesPreset";
- let assert: any = require('chai').assert;
- describe('JavaScriptObfuscator', () => {
- describe('obfuscate (sourceCode: string, customOptions?: IOptionsPreset): string', () => {
- it('should obfuscate simple code with variable inside global scope', () => {
- assert.match(
- JavaScriptObfuscator.obfuscate(
- `var test = 1;`,
- Object.assign({}, NO_CUSTOM_NODES_PRESET)
- ),
- /^var *test *= *0x\d+;$/
- );
- });
- it('should obfuscate simple code with variable inside block-scope', () => {
- assert.match(
- JavaScriptObfuscator.obfuscate(
- `(function () {var test = 1;})()`,
- Object.assign({}, NO_CUSTOM_NODES_PRESET)
- ),
- /^\(function *\(\) *\{ *var *_0x[\w]+ *= *0x\d+; *\}(\(\)\)|\)\(\));?$/
- );
- });
- it('should obfuscate simple code with literal variable value', () => {
- let pattern = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/;
- assert.match(
- JavaScriptObfuscator.obfuscate(
- `var test = 'abc';`,
- Object.assign({}, NO_CUSTOM_NODES_PRESET, {
- unicodeArray: true,
- unicodeArrayThreshold: 1
- })
- ),
- pattern
- );
- assert.match(
- JavaScriptObfuscator.obfuscate(
- `var test = 'абц';`,
- Object.assign({}, NO_CUSTOM_NODES_PRESET, {
- unicodeArray: true,
- unicodeArrayThreshold: 1
- })
- ),
- pattern
- );
- });
- });
- });
|