rc4 encoding runtime error fix and performance boost

This commit is contained in:
sanex3339
2017-01-03 18:49:31 +03:00
parent 8e14a3e90a
commit 8c5d323752
8 changed files with 74 additions and 125 deletions
+5 -44
View File
@@ -1,4 +1,5 @@
'use strict';
import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
if (!(<any>global)._babelPolyfill) {
require('babel-polyfill');
@@ -9,53 +10,13 @@ if (!(<any>global)._babelPolyfill) {
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
(function(){
var result = 1,
term1 = 0,
term2 = 1,
i = 1;
while(i < 10)
{
var test = 10;
result = term1 + term2;
console.log(result);
term1 = term2;
term2 = result;
i++;
}
console.log(test);
var test = function (test) {
console.log(test);
if (true) {
var test = 5
}
return test;
}
console.log(test(1));
function test2 (abc) {
function test1 () {
console.log('inside', abc.item);
}
console.log('тест', abc);
var abc = {};
return abc.item = 15, test1();
};
})();
var test = console.log;
`,
{
...NO_CUSTOM_NODES_PRESET,
compact: false,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
disableConsoleOutput: false
stringArray: true,
stringArrayThreshold: 1
}
).getObfuscatedCode();
@@ -38,6 +38,27 @@ describe('LiteralObfuscator', () => {
assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *_0x([a-z0-9]){4}\('0x0'\);/);
});
it('should create only one item in string array for same literal node values', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
`
var test = 'test';
var test = 'test';
object.test();
`,
{
...NO_CUSTOM_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1
}
);
assert.match(
obfuscationResult.getObfuscatedCode(),
/^var *_0x([a-z0-9]){4} *= *\['\\x74\\x65\\x73\\x74'\];/
);
assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *_0x([a-z0-9]){4}\('0x0'\);/);
});
it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` is disabled', () => {
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
`var test = 'test';`,