|
@@ -681,11 +681,11 @@ describe('BlockStatementControlFlowTransformer', function () {
|
|
|
switchCaseMap = switchCaseMapMatch.split('|').sort();
|
|
|
});
|
|
|
|
|
|
- it('should create switch-case map variable', () => {
|
|
|
+ it('should use correct kind of variable for switch-case map', () => {
|
|
|
assert.match(obfuscatedCode, switchCaseMapVariableRegExp);
|
|
|
});
|
|
|
|
|
|
- it('should create valid switch-case map variable with order of switch cases sequence', () => {
|
|
|
+ it('should use correct kind of variable for switch cases sequence', () => {
|
|
|
assert.deepEqual(switchCaseMap, expectedSwitchCasesSequence);
|
|
|
});
|
|
|
});
|
|
@@ -720,11 +720,50 @@ describe('BlockStatementControlFlowTransformer', function () {
|
|
|
switchCaseMap = switchCaseMapMatch.split('|').sort();
|
|
|
});
|
|
|
|
|
|
- it('should create switch-case map variable', () => {
|
|
|
+ it('should use correct kind of variable for switch-case map', () => {
|
|
|
assert.match(obfuscatedCode, switchCaseMapVariableRegExp);
|
|
|
});
|
|
|
|
|
|
- it('should create valid switch-case map variable with order of switch cases sequence', () => {
|
|
|
+ it('should use correct kind of variable for switch cases sequence', () => {
|
|
|
+ assert.deepEqual(switchCaseMap, expectedSwitchCasesSequence);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('`let` kind', () => {
|
|
|
+ let obfuscatedCode: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js');
|
|
|
+
|
|
|
+ obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
|
|
+ code,
|
|
|
+ {
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
+ controlFlowFlattening: true,
|
|
|
+ controlFlowFlatteningThreshold: 1
|
|
|
+ }
|
|
|
+ ).getObfuscatedCode();
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('switch-case map', () => {
|
|
|
+ const switchCaseMapVariableRegExp: RegExp = /let *_0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/;
|
|
|
+ const switchCaseMapStringRegExp: RegExp = /let *_0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/;
|
|
|
+ const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4'];
|
|
|
+
|
|
|
+ let switchCaseMap: string[];
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const switchCaseMapMatch: string = getRegExpMatch(obfuscatedCode, switchCaseMapStringRegExp);
|
|
|
+
|
|
|
+ switchCaseMap = switchCaseMapMatch.split('|').sort();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should use correct kind of variable for switch-case map', () => {
|
|
|
+ assert.match(obfuscatedCode, switchCaseMapVariableRegExp);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should use correct kind of variable for switch cases sequence', () => {
|
|
|
assert.deepEqual(switchCaseMap, expectedSwitchCasesSequence);
|
|
|
});
|
|
|
});
|