question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Idea: Locally scoped variable can have the same mangled name

See original GitHub issue

Expected Behavior

Obfuscated code can have multiple locally scoped variable name identical. I know this could be difficult to implement, it is an idea, if someone have the skills to implement this.

It would make de obfuscation much harder

Example:

var a = 2 // can't use 'a' anymore as it is in the top scope
function(b, c) {
  return window[b] = c
}
for(var b = 0; b < c; b++) { // notice 'b', 'c' is also in the function, they where in local scope in the previous function
    var d = 5+b
}

This would be harder to de obfuscate as a variable name can have multiple purposes.

Current Behavior

Raw code

var myvalue = 2
function(key, value) {
  return window[key] = value
}
for(var i = 0; i < myvalue; i++) {
    var mycounter = 5+i
}

Obfuscated code

var a = 2
function(b, c) {
  return window[b] = c
}
for(var d = 0; d < e; d++) {
    var e = 5+d
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sanex3339commented, Dec 1, 2019

In this branch, I added the new preparing transformer, called ScopeTransformer, that added scope property to all nodes.

Then, in MangledIdentifierNamesGenerator identifiers for each scope are tried to generate.

1reaction
sanex3339commented, Dec 1, 2019

Much smallest minimal example with bug

 let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
        `
        (function () {
            let a = 0;
            
            function param1 (param1, param2) {
               
            }
        })();
        `,
        {
            ...NO_ADDITIONAL_NODES_PRESET,
            compact: false,
            stringArray: false,
            stringArrayThreshold: 1,
            transformObjectKeys: true,
            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
            seed: 1
        }
    ).getObfuscatedCode();

Obfuscated code with error:

(function () {
    let c = 0x0;
    function d(d, d) {
    }
}());
Read more comments on GitHub >

github_iconTop Results From Across the Web

Name Mangling - an overview | ScienceDirect Topics
In an all, a procedure can refer to global variables, local variables, and any variable declared in a surrounding lexical scope.
Read more >
questions about name mangling in C++ - Stack Overflow
In C++, you can have two functions with the same name as long as they ... Scoping is used to control access to...
Read more >
Instance Variable and Local Variable with Same Name
Answer: Yes — the scopes will not overlap so there will be two local variables, one per method, each with the same name....
Read more >
Name mangling - Wikipedia
The need for name mangling arises where the language allows different entities to be named with the same identifier as long as they...
Read more >
Name mangling (C++ only) - IBM
Name mangling is the encoding of function and variable names into unique names so that linkers can separate common names in the language....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found