forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevented mutation of the name sequences of
mangled
identifier name…
… generators
- Loading branch information
sanex3339
committed
Jul 10, 2020
1 parent
b2f5a91
commit d074bbe
Showing
10 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ngled-shuffled-identifier-names-generator/MangledShuffledIdentifierNamesGenerator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { assert } from 'chai'; | ||
|
||
import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator'; | ||
|
||
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; | ||
|
||
import { readFileAsString } from '../../../../helpers/readFileAsString'; | ||
|
||
import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade'; | ||
|
||
describe('MangledShuffledIdentifierNamesGenerator', () => { | ||
describe('Variant #1: prevent name sequence mutation of base `mangled` generator', () => { | ||
const functionsRegExp: RegExp = new RegExp( | ||
'function foo *\\(a, *b\\) *{} *' + | ||
'function foo *\\(a, *b\\) *{} *' + | ||
'function foo *\\(a, *b\\) *{} *' + | ||
'function foo *\\(a, *b\\) *{}' | ||
); | ||
|
||
let obfuscatedCode: string = ''; | ||
|
||
before(() => { | ||
const code: string = readFileAsString(__dirname + '/fixtures/prevent-name-sequence-mutation.js'); | ||
|
||
for (let i = 0; i < 4; i++) { | ||
const identifierNamesGenerator = i % 2 === 0 | ||
? IdentifierNamesGenerator.MangledIdentifierNamesGenerator | ||
: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator; | ||
|
||
obfuscatedCode += JavaScriptObfuscator.obfuscate( | ||
code, | ||
{ | ||
...NO_ADDITIONAL_NODES_PRESET, | ||
identifierNamesGenerator | ||
} | ||
).getObfuscatedCode(); | ||
} | ||
}); | ||
|
||
it('Should not mutate name sequences between mangled generators', () => { | ||
assert.notMatch(obfuscatedCode, functionsRegExp); | ||
}); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
...rs/mangled-shuffled-identifier-names-generator/fixtures/prevent-name-sequence-mutation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
function foo (bar, baz) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters