Skip to content

Control Globals and functions renaming #629

Closed

Description

@Shine753

I'm a little confused with the readme file.
If I use the renameGlobals=true parameter, it renames globals, and functions. ok.
If I have a function that is called from another script, the call is broken. ok.
So I have to exclude it from the renaming list with reservedNames. ok.

The problem is that doing this, it is not obfuscated.
Is there a way so I can rename it, at obfuscation, without touching the source code ?

For example, saying that this string THISFUNCTION, should always be renamed with this TiHiIiSiFiUiNiCiTiIiOiN or with ghfdffgfhdfjghdfgjdsfhgf when obfuscated.
This way, when I obfuscate any script, I can keep the function call by maintaining some coherence.
Same thing for globals.

note that THISFUNCTION can be a function name, and of course a string corresponding to a javascript call.

    SCRIPT 1 : function THISFUNCTION() {}
    SCRIPT 2 : <input type='button' onclick='THISFUNCTION();' />

Activity

  1. sanex3339 commented on Jun 23, 2020

    @sanex3339
    Member

    The solution is to implement name cache like uglifyJs and terser are doing.

  2. challengeable commented on Nov 18, 2020

    @challengeable

    Was this ever completed ?

  3. sanex3339 commented on Nov 18, 2020

    @sanex3339
    Member

    In the future. Right now I have other priorities.

  4. challengeable commented on Nov 18, 2020

    @challengeable

    Okay, is there a known workaround ?

  5. sanex3339 commented on Nov 18, 2020

    @sanex3339
    Member

    only with reservedNames

  6. challengeable commented on Nov 18, 2020

    @challengeable

    Returning a Map with the old function/vars => new obf functions/vars would allow us to come up with potential alternatives

  7. sanex3339 commented on Nov 18, 2020

    @sanex3339
    Member

    I will implement names cache (that writes into the file) in the future (like uglify.js does) but i haven't any date. Sometime in next year.

  8. sanex3339 commented on Mar 7, 2021

    @sanex3339
    Member

    I think, i have to implement this as the next big feature.

  9. 31 remaining items

  10. BlackYuzia commented on May 31, 2021

    @BlackYuzia
    Contributor

    hmm, that means what we can do something like REPLACE function inside obfuscator?

    Like:

    // config
    {
    "identifierNamesCache": { _date: new Date() } // just example, mb I wrong 
    }
    // code 
    const date = _date; // _date is not defined, but should be replaced by "new Date()"
  11. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    With

    "identifierNamesCache": {
         "globalIdentifiers": {
             _date: new Date() 
        }
    }
    

    You can do this, but this is not the expected use case for this option (because I limited globalIdentifiers usage to undeclared variables.
    If sometime in the future I will add the way to control identifier names, it will the way through identifierNamesGenerator option.

  12. BlackYuzia commented on May 31, 2021

    @BlackYuzia
    Contributor

    Tested, that work now
    image

  13. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    The empty option object now should work correctly

  14. BlackYuzia commented on May 31, 2021

    @BlackYuzia
    Contributor
    ReferenceError: Validation failed. errors:
    `identifierNamesCache` errors:
        - Passed value must be an identifier names cache object or `null` value
        "identifierNamesCache": {
            "globalIdentifiers": {
                "KRUZYAPIDOR": true
            },
            "propertyIdentifiers": {}
        }

    did that bug? 👀

    I was try do like you say - #629 (comment)

  15. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    No. Dictionary values should be strings.

  16. BlackYuzia commented on May 31, 2021

    @BlackYuzia
    Contributor

    image
    yep, work now.

    That all or we should test anything more?

  17. BlackYuzia commented on May 31, 2021

    @BlackYuzia
    Contributor

    @sanex3339 for use this like replace in code, we should add second obfuscate (or obfuscate only replaced values) or we get unobfuscated values, functions and etc.

  18. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    All replaced values won't be obfuscated. So as I said before this use case is not an expected use case.

  19. BlackYuzia commented on May 31, 2021

    @BlackYuzia
    Contributor

    yep, I now. I mean, if we add feature for replace code as expected, we also should add obfuscation for replaced values
    or we have second choice - obfuscate values before inserting for replace.

  20. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    I don't know how i will do this right now. Right now this is the cache only for reuse some names between files

  21. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    Thank you for testing. Probably from tomorrow and all this and partially next week I won't be able to finish this PR, because of my vacation. I'll finish in a week.

  22. sanex3339 commented on May 31, 2021

    @sanex3339
    Member

    Why not? Released as 2.14.0. Enjoy! For any bugs, please create a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions