sanex3339
2018-02-17 15:09:27 +03:00
parent 6378ea500d
commit 5f2273cc3d
6 changed files with 121 additions and 15 deletions
@@ -517,5 +517,41 @@ describe('DeadCodeInjectionTransformer', () => {
assert.isAtLeast(matchesLength, expectedMatchesLength);
});
});
describe('variant #12 - block statement with scope-hoisting', () => {
const regExp: RegExp = new RegExp(
`${variableMatch} *\\(\\); *` +
`var *${variableMatch} *= *0x2; *` +
`function *${variableMatch} *\\(\\) *{ *} *`,
'g'
);
const expectedMatchesLength: number = 5;
let matchesLength: number = 0;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/block-statement-with-scope-hoisting.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1
}
);
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
const functionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(regExp);
if (functionMatches) {
matchesLength = functionMatches.length;
} });
it('shouldn\'t collect block statements with scope-hoisting', () => {
assert.equal(matchesLength, expectedMatchesLength);
});
});
});
});
@@ -1,22 +1,37 @@
(function(){
function foo () {
var a = 1;
inner1();
var b = 2;
function inner1 () {}
var c = 3;
}
function bar () {
var a = 1;
inner2();
var b = 2;
function inner2 () {}
var c = 3;
}
function baz () {
var a = 1;
inner3();
var b = 2;
function inner3 () {}
var c = 3;
}
function bark () {
var a = 1;
inner4();
var b = 2;
function inner4 () {}
var c = 3;
}
function hawk () {
var a = 1;
inner5();
var b = 2;
function inner5 () {}
var c = 3;
}
})();