mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
compile preformance fix
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
||||
if (!(<any>global)._babelPolyfill) {
|
||||
require('babel-polyfill');
|
||||
}
|
||||
|
||||
(function () {
|
||||
const JavaScriptObfuscator: any = require("../../index");
|
||||
|
||||
let start: any = new Date();
|
||||
|
||||
JavaScriptObfuscator.obfuscate(
|
||||
fs.readFileSync('test/fixtures/compile-performance.js', 'utf8')
|
||||
).getObfuscatedCode();
|
||||
|
||||
console.log(`Total time: ${<any>new Date() - start}`);
|
||||
})();
|
||||
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
if (!(<any>global)._babelPolyfill) {
|
||||
require('babel-polyfill');
|
||||
}
|
||||
|
||||
(function () {
|
||||
const JavaScriptObfuscator: any = require("../../index");
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
var start = new Date();
|
||||
var log = console.log;
|
||||
console.log = function () {};
|
||||
|
||||
${String(`
|
||||
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 regexptest = /version\\/(\\d+)/i;
|
||||
console.log(regexptest);
|
||||
|
||||
test2(22);
|
||||
console.log(105.4);
|
||||
console.log(true, false);
|
||||
|
||||
var sA = 'shorthand1';
|
||||
var sB = 'shorthand2';
|
||||
|
||||
console.log({sA, sB});
|
||||
|
||||
try {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
`).repeat(200)}
|
||||
|
||||
console.log = log;
|
||||
console.log(new Date() - start);
|
||||
`,
|
||||
{
|
||||
disableConsoleOutput: false,
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
console.log(eval(obfuscatedCode));
|
||||
})();
|
||||
@@ -4,10 +4,11 @@ if (!(<any>global)._babelPolyfill) {
|
||||
require('babel-polyfill');
|
||||
}
|
||||
|
||||
const JavaScriptObfuscator: any = require("../../index");
|
||||
(function () {
|
||||
const JavaScriptObfuscator: any = require("../../index");
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
(function(){
|
||||
var result = 1,
|
||||
term1 = 0,
|
||||
@@ -67,11 +68,12 @@ let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
}
|
||||
})();
|
||||
`,
|
||||
{
|
||||
disableConsoleOutput: false,
|
||||
unicodeArrayEncoding: 'rc4'
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
{
|
||||
disableConsoleOutput: false,
|
||||
unicodeArrayEncoding: 'rc4'
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
console.log(obfuscatedCode);
|
||||
console.log(eval(obfuscatedCode));
|
||||
console.log(obfuscatedCode);
|
||||
console.log(eval(obfuscatedCode));
|
||||
})();
|
||||
@@ -1,87 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
if (!(<any>global)._babelPolyfill) {
|
||||
require('babel-polyfill');
|
||||
}
|
||||
|
||||
const JavaScriptObfuscator: any = require("../../index");
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
(function (){
|
||||
var start = new Date();
|
||||
var log = console.log;
|
||||
console.log = function () {};
|
||||
|
||||
(function(){
|
||||
${String(`
|
||||
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 regexptest = /version\\/(\\d+)/i;
|
||||
console.log(regexptest);
|
||||
|
||||
test2(22);
|
||||
console.log(105.4);
|
||||
console.log(true, false);
|
||||
|
||||
var sA = 'shorthand1';
|
||||
var sB = 'shorthand2';
|
||||
|
||||
console.log({sA, sB});
|
||||
|
||||
try {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
`).repeat(1000)}
|
||||
})();
|
||||
|
||||
console.log = log;
|
||||
console.log(new Date() - start);
|
||||
})();
|
||||
`,
|
||||
{
|
||||
disableConsoleOutput: false,
|
||||
unicodeArrayEncoding: 'rc4'
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
console.log(eval(obfuscatedCode));
|
||||
Vendored
+76382
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@ import './unit-tests/custom-nodes/CustomNodeAppender.spec';
|
||||
import './unit-tests/node-obfuscators/CatchClauseObfuscator.spec';
|
||||
import './unit-tests/node-obfuscators/FunctionDeclarationObfuscator.spec';
|
||||
import './unit-tests/node-obfuscators/FunctionObfuscator.spec';
|
||||
import './unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec';
|
||||
|
||||
/**
|
||||
* Functional tests
|
||||
|
||||
@@ -278,31 +278,91 @@ describe('CustomNodeAppender', () => {
|
||||
|
||||
assert.deepEqual(astTree, expectedAstTree);
|
||||
});
|
||||
|
||||
it('should append node into deepest function call by specified index in calls trace - variant #3', () => {
|
||||
astTree = <ESTree.Program>NodeUtils.convertCodeToStructure(`
|
||||
var start = new Date();
|
||||
var log = console.log;
|
||||
|
||||
console.log = function () {};
|
||||
|
||||
(function () {
|
||||
function bar () {
|
||||
function inner1 () {
|
||||
|
||||
}
|
||||
|
||||
function inner2 () {
|
||||
var inner3 = function () {
|
||||
|
||||
}
|
||||
|
||||
inner3();
|
||||
}
|
||||
|
||||
inner2();
|
||||
inner1();
|
||||
}
|
||||
|
||||
bar();
|
||||
})();
|
||||
console.log = log;
|
||||
console.log(new Date() - start);
|
||||
`, false);
|
||||
expectedAstTree = <ESTree.Program>NodeUtils.convertCodeToStructure(`
|
||||
var start = new Date();
|
||||
var log = console.log;
|
||||
|
||||
console.log = function () {};
|
||||
|
||||
(function () {
|
||||
function bar () {
|
||||
function inner1 () {
|
||||
|
||||
}
|
||||
|
||||
function inner2 () {
|
||||
var inner3 = function () {
|
||||
var test = 1;
|
||||
}
|
||||
|
||||
inner3();
|
||||
}
|
||||
|
||||
inner2();
|
||||
inner1();
|
||||
}
|
||||
|
||||
bar();
|
||||
})();
|
||||
console.log = log;
|
||||
console.log(new Date() - start);
|
||||
`, false);
|
||||
|
||||
stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
|
||||
CustomNodeAppender.appendNode(
|
||||
stackTraceData,
|
||||
astTree.body,
|
||||
node,
|
||||
CustomNodeAppender.getRandomStackTraceIndex(stackTraceData.length)
|
||||
);
|
||||
|
||||
NodeUtils.parentize(astTree);
|
||||
|
||||
assert.deepEqual(astTree, expectedAstTree);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getIndexByThreshold (blockStatementBodyLength: number, threshold: number = 0.1): number', () => {
|
||||
it('should returns random index between 0 and index based on threshold value', () => {
|
||||
describe('getRandomStackTraceIndex (stackTraceRootLength: number): number', () => {
|
||||
it('should returns random index between 0 and stack trace deata root length', () => {
|
||||
let index: number;
|
||||
|
||||
for (let i: number = 0; i < 10; i++) {
|
||||
index = CustomNodeAppender.getIndexByThreshold(100, 0.1);
|
||||
for (let i: number = 0; i < 100; i++) {
|
||||
index = CustomNodeAppender.getRandomStackTraceIndex(100);
|
||||
|
||||
assert.isAtLeast(index, 0);
|
||||
assert.isAtMost(index, 10);
|
||||
}
|
||||
|
||||
for (let i: number = 0; i < 10; i++) {
|
||||
index = CustomNodeAppender.getIndexByThreshold(10, 0.5);
|
||||
|
||||
assert.isAtLeast(index, 0);
|
||||
assert.isAtMost(index, 5);
|
||||
}
|
||||
|
||||
for (let i: number = 0; i < 10; i++) {
|
||||
index = CustomNodeAppender.getIndexByThreshold(1, 1);
|
||||
|
||||
assert.equal(index, 0);
|
||||
assert.isAtMost(index, 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import * as chai from 'chai';
|
||||
|
||||
import { StackTraceAnalyzer } from '../../../src/stack-trace-analyzer/StackTraceAnalyzer';
|
||||
|
||||
const assert: any = chai.assert;
|
||||
|
||||
describe('StackTraceAnalyzer', () => {
|
||||
describe('getLimitIndex (blockScopeBodyLength: number): number', () => {
|
||||
it('should returns correct limit index based on block scope body length', () => {
|
||||
const blockScopeBodyLength1: number = 100;
|
||||
const blockScopeBodyLength2: number = 22;
|
||||
const blockScopeBodyLength3: number = 26;
|
||||
const blockScopeBodyLength4: number = 28;
|
||||
const blockScopeBodyLength5: number = 34;
|
||||
|
||||
assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength1), 34);
|
||||
assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength2), 21);
|
||||
assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength3), 25);
|
||||
assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength4), 27);
|
||||
assert.equal(StackTraceAnalyzer.getLimitIndex(blockScopeBodyLength5), 27);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user