juanlao7/codeclose

Using a variable name `replace`, prevents a valid product key from validating.

Closed this issue · 2 comments

If somewhere in the code, there is a variable called replace, license = validate(False) returns Invalid product key..

Thank you for reporting this issue!

This is a known but unsolvable issue of Codeclose. When Codeclose "protects" code, it does the following:

  1. Codeclose makes a first scan of all your code and extracts all identifiers that are assigned at least once, and creates a dictionary for mapping their names to their respective final obfuscated names.
  2. Codeclose injects in your code some extra functions for validating licenses in runtime.
  3. Finally Codeclose replaces all identifier occurrences (accesses & assignations) by their respective obfuscated name using the dictionary created on step 1.

Obfuscating only the identifiers that are being assigned prevents Codeclose from obfuscating Python's builtin identifiers or imported identifiers from external packages. The latter are commonly only accessed and never assigned.

However, this approach fails when the name of a variable you want to obfuscate is equal to the name of a builtin identifier. In your case Codeclose is obfuscating all occurrences of replace, including all references to Python's string.replace() builtin method. The injected functions that validate the license rely on string.replace(), and that's why they are failing.

Due to Python's duck-typing nature, when Codeclose finds a reference to replace it can't determine whether it's an actual reference to your variable (and should be obfuscated) or a reference to string.replace() (that shouldn't be obfuscated), so it always obfuscates it, just to be safe.

You can manually prevent that obfuscation from happening by using --keep-identifier replace when running codeclose protect.

Please let me know if that works!

That's what I did. It just took me a while to find the root cause of the error.