Fixed errors related to identifiers. Changed self defending helper

This commit is contained in:
sanex3339
2020-02-16 14:41:32 +03:00
parent 51523c0d5c
commit a2e9c05ce8
46 changed files with 843 additions and 306 deletions
@@ -5,6 +5,7 @@ import { TInputOptions } from '../../src/types/options/TInputOptions';
import { StringArrayEncoding } from '../../src/enums/StringArrayEncoding';
import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { evaluateInWorker } from '../helpers/evaluateInWorker';
import { readFileAsString } from '../helpers/readFileAsString';
import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscatorFacade';
@@ -36,7 +37,7 @@ describe('JavaScriptObfuscator runtime eval', function () {
unicodeEscapeSequence: true
};
this.timeout(100000);
this.timeout(200000);
[
{
@@ -164,5 +165,123 @@ describe('JavaScriptObfuscator runtime eval', function () {
);
});
});
describe(`Obfuscator. ${detailedDescription}`, () => {
const evaluationTimeout: number = 10000;
let evaluationResult: string;
beforeEach((done) => {
const code: string = readFileAsString(process.cwd() + '/dist/index.js');
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
code,
{
...baseOptions,
...options
}
).getObfuscatedCode();
evaluateInWorker(
`
${getEnvironmentCode()}
${obfuscatedCode}
module.exports.obfuscate('var foo = 1;').getObfuscatedCode();
`,
(response: string) => {
evaluationResult = response;
done();
},
(error: Error) => {
evaluationResult = error.message;
done();
},
() => {
done();
},
evaluationTimeout
);
});
it('should obfuscate code without any runtime errors after obfuscation: Variant #3 obfuscator', () => {
assert.equal(
evaluationResult,
'var foo=0x1;'
);
});
});
[
{
debugProtection: false,
selfDefending: false,
stringArray: true
},
{
debugProtection: false,
selfDefending: true,
stringArray: false
},
{
debugProtection: true,
selfDefending: false,
stringArray: false
},
{
debugProtection: true,
selfDefending: true,
stringArray: false
},
{
debugProtection: true,
selfDefending: true,
stringArray: true
}
].forEach((webpackBootstrapOptions: Partial<TInputOptions>) => {
describe(`Webpack bootstrap code. ${detailedDescription}. ${JSON.stringify(webpackBootstrapOptions)}`, () => {
const evaluationTimeout: number = 10000;
let evaluationResult: string;
beforeEach((done) => {
const code: string = readFileAsString(__dirname + '/fixtures/webpack-bootstrap.js');
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
code,
{
...baseOptions,
...options,
...webpackBootstrapOptions
}
).getObfuscatedCode();
evaluateInWorker(
`
${getEnvironmentCode()}
${obfuscatedCode}
`,
(response: string) => {
evaluationResult = response;
done();
},
(error: Error) => {
evaluationResult = error.message;
done();
},
() => {
done();
},
evaluationTimeout
);
});
it('should obfuscate code without any runtime errors after obfuscation: Variant #4 webpack bootstrap', () => {
assert.equal(
evaluationResult,
'foo'
);
});
});
});
});
});