sanex3339
2020-01-07 22:47:55 +03:00
parent f355309628
commit c98cfe1fbc
6 changed files with 43 additions and 5 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -141,8 +141,10 @@ export class ImportDeclarationTransformer extends AbstractNodeTransformer {
const newReplaceableIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
.replace(replaceableIdentifier.name, lexicalScopeNode);
replaceableIdentifier.name = newReplaceableIdentifier.name;
NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
if (replaceableIdentifier.name !== newReplaceableIdentifier.name) {
replaceableIdentifier.name = newReplaceableIdentifier.name;
NodeMetadata.set(replaceableIdentifier, { renamedIdentifier: true });
}
});
}
@@ -141,5 +141,37 @@ describe('ImportDeclarationTransformer', () => {
assert.equal(importSpecifierIdentifier, consoleLogIdentifier);
});
});
describe('Variant #5: Issue-360, prevent of set `renamedIdentifier` metadata property of all traversed identifiers', () => {
const importSpecifierRegExp1: RegExp = /import _0x[a-f0-9]{4,6} *from *'foo';/;
const importSpecifierRegExp2: RegExp = /import _0x[a-f0-9]{4,6} *from *'bar';/;
const variableDeclarationIdentifierRegExp: RegExp = /const _0x[a-f0-9]{4,6} *= *0x1;/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/issue-360.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true
}
).getObfuscatedCode();
});
it('Match 1: should transform first import specifier identifier name', () => {
assert.match(obfuscatedCode, importSpecifierRegExp1);
});
it('Match 2: should transform second import specifier identifier name', () => {
assert.match(obfuscatedCode, importSpecifierRegExp2);
});
it('Match 3: should transform variable declaration identifier name', () => {
assert.match(obfuscatedCode, variableDeclarationIdentifierRegExp);
});
});
});
});
@@ -0,0 +1,4 @@
import foo from 'foo';
import bar from 'bar';
const baz = 1;