Replace Globals

  • RenameGlobals
  • Coporate
JavaScriptObfuscator allow developer replace the name of the variables/functions.

If the global identifiers be replaced, it will only keep the compability of the current file. 

So by default , JSO will not replace the global identifiers. 

If developer protect the files batchly, JSO can keep the compability with the files. 
		
And this feature can be turned on. So that's why it's under group 'Cross-File Obfuscation'



For example
a.js , there's a functionfunction HelperA(){ ... }
And
b.js , the code call a.js var data=HelperA(); 

When use the 'Replace Globals' feature, 
Make sure the a.js and b.js are in same JavaScriptObfuscator proejct.

So that when HelperA be replaced to a new name, for example, g9 , b.js can reference it:
var data=g9();
a.js
b.js
=>
a.js
b.js
If your project will not be called for third-party , all global identifiers could be renamed.

But sometimes developers wish they can control the rules .

In the dialog of Global Mapping, there's two options : Rename by rules and Custom Identityes .




For example, At 'Rename by rules' , specify a Regular expression 
^__ 

That will only replace the identifiers which's name starts with '__'



for example , for this code
function __internalGetSetting(){}
function __loadConfig(){}
function ShowLastError(){}

__internalGetSetting, __loadConfig are match the RegExp ^__ , so they will be renamed. 

And ShowLastError does not match the rule, so ShowLastError will keep the name not replaced. 
=>
The textbox of Rename by rules, is help developers to define the matched identifiers as private.

And that's mean the non-matched identifiers as public , keep the origianl name for third-party.
(Or the html code like onclick='MyPublicHandler()' )

Custom Identities is a direct mapping tool to specify how to replace the identifiers. 
for example, type these mapping code in Custom Identities
checkValue:?
localData:?

That means, all global identifiers which name is checkValue,localData will be replace as random name.



=>

For debugging, please specify a fixed mapping rule for the identifiers:
checkValue:d01
localData:l01

As the mapping, the checkValue will be replaced as d01 , and localData will be replaced as l01;

=>

JavaScriptObfuscator will automatically store the mapping information for each Project (saved in jsop).
Each identifiers will use the same name as the previous obfuscation does.

After once obfuscation, click 'Check last auto generated mapping' , you could get the mapping data. 



It's also a good information that can help developers know how many global identifiers the project has.

Developer can collect some and type them into 'Custom Identities' if they want.