mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Dynamic import and import.meta support
This commit is contained in:
@@ -3,6 +3,7 @@ Change Log
|
||||
v0.24.0
|
||||
---
|
||||
* **Internal refactoring:** completely new mechanism to rename variable names
|
||||
* Dynamic import and `import.meta` support. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/505
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/496
|
||||
|
||||
v0.23.2
|
||||
|
||||
Vendored
+6
-6
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -24,6 +24,7 @@
|
||||
"@gradecam/tsenum": "1.2.0",
|
||||
"@nuxtjs/opencollective": "0.2.2",
|
||||
"acorn": "7.1.0",
|
||||
"acorn-import-meta": "1.0.0",
|
||||
"chalk": "3.0.0",
|
||||
"chance": "1.1.4",
|
||||
"class-validator": "0.11.0",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as acorn from 'acorn';
|
||||
import acornImportMeta from 'acorn-import-meta';
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
import chalk, { Chalk } from 'chalk';
|
||||
@@ -70,7 +71,11 @@ export class ASTParserFacade {
|
||||
sourceType
|
||||
};
|
||||
|
||||
const program: ESTree.Program = <any>acorn.parse(input, config);
|
||||
const program: ESTree.Program = (
|
||||
<any>acorn
|
||||
.Parser.extend(acornImportMeta)
|
||||
.parse(input, config)
|
||||
);
|
||||
|
||||
if (comments.length) {
|
||||
program.comments = comments;
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
declare module 'acorn-import-meta' {
|
||||
import * as acorn from 'acorn';
|
||||
|
||||
function acornImportMeta (BaseParser: typeof acorn.Parser): typeof acorn.Parser;
|
||||
|
||||
export = acornImportMeta;
|
||||
}
|
||||
@@ -551,6 +551,27 @@ describe('JavaScriptObfuscator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('import.meta support', () => {
|
||||
const regExp: RegExp = /console\['log']\(import\.meta\['url']\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
beforeEach(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/import-meta.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should support `import.meta`', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mangled identifier names generator', () => {
|
||||
const regExp: RegExp = /var *c *= *0x1/;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
console.log(import.meta.url);
|
||||
+22
@@ -173,5 +173,27 @@ describe('ScopeIdentifiersTransformer ImportDeclaration identifiers', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationIdentifierRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #6: dynamic import support', () => {
|
||||
const dynamicImportRegExp: RegExp = /import\(_0x[a-f0-9]{4,6}\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/dynamic-import.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
renameGlobals: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should support dynamic import', () => {
|
||||
assert.match(obfuscatedCode, dynamicImportRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
var foo = 'foo';
|
||||
import(foo);
|
||||
@@ -196,7 +196,7 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/escodegen/-/escodegen-0.0.6.tgz#5230a9ce796e042cda6f086dbf19f22ea330659c"
|
||||
integrity sha1-UjCpznluBCzabwhtvxnyLqMwZZw=
|
||||
|
||||
"@types/eslint-scope@^3.7.0":
|
||||
"@types/eslint-scope@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.0.tgz#4792816e31119ebd506902a482caec4951fabd86"
|
||||
integrity sha512-O/ql2+rrCUe2W2rs7wMR+GqPRcgB6UiqN5RhrR5xruFlY7l9YLMn0ZkDzjoHLeiFkR8MCQZVudUuuvQ2BLC9Qw==
|
||||
@@ -468,6 +468,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
|
||||
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
|
||||
|
||||
acorn-import-meta@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/acorn-import-meta/-/acorn-import-meta-1.0.0.tgz#6cff1f01db3b60148934823d3d2dd0c08354aead"
|
||||
integrity sha512-yX652u86bKzuM+mzEHV84T0R+srQwTOmprUiFC3zlhlc02lBQzqxkB/H/7jexX9vlz/TRuQiZs9mKEDK3bbmhw==
|
||||
|
||||
acorn@7.1.0:
|
||||
version "7.1.0"
|
||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.0.tgz#949d36f2c292535da602283586c2477c57eb2d6c"
|
||||
|
||||
Reference in New Issue
Block a user