Description
uncompyle6 blindly trists the names of the variables in the code object even if they are not valid Python symbol names. This can lead to incorrect decompilation output
How to Reproduce
If we compile the following Python code into bytecode:
x = "Hello"
y = "World"
EVIL = 1
print(x + " " + y)
and manually rename the variable "EVIL" to "y = 'Hello' #", the output when running will still be "Hello World" but if we decompile it, the output from uncompyle will be:
x = "Hello"
y = "World"
y = 'Hello' # = 1
print(x + " " + y)
and running this code gives the output "Hello Hello".
A slightly more realistic example can be found below:
$ git clone https://github.com/ZetaTwo/python-obfuscator
$ cd python-obfuscator
$ ./test.sh
In this bytecode, one variable is named "i = 0\n j" making the decompiled implementation of the RC4 function different from the bytecode.
Expected behavior
I expect uncompyle6 to either warn about the presence of improperly named variables or simply rename them by for example replacing all invalid characters with "_".
Environment
$ uncompyle6 --version
uncompyle6 3.6.4
$ python3 -c "import sys; print(sys.version)"
3.7.3 (default, Oct 7 2019, 12:56:13)
[GCC 8.3.0]
OS: Ubuntu 19.04
Additional Environment or Context
I understand that you generally don't support obfuscated Python code but I think this is very simple to implement and does not contribute to making the code more complex. I'd be willing to implement this and provide a PR for this but I would like your opinion if it should be a warning or renaming the variables or maybe even some command line option to choose between the two.
Description
uncompyle6 blindly trists the names of the variables in the code object even if they are not valid Python symbol names. This can lead to incorrect decompilation output
How to Reproduce
If we compile the following Python code into bytecode:
and manually rename the variable "EVIL" to "y = 'Hello' #", the output when running will still be "Hello World" but if we decompile it, the output from uncompyle will be:
and running this code gives the output "Hello Hello".
A slightly more realistic example can be found below:
In this bytecode, one variable is named "i = 0\n j" making the decompiled implementation of the RC4 function different from the bytecode.
Expected behavior
I expect uncompyle6 to either warn about the presence of improperly named variables or simply rename them by for example replacing all invalid characters with "_".
Environment
OS: Ubuntu 19.04
Additional Environment or Context
I understand that you generally don't support obfuscated Python code but I think this is very simple to implement and does not contribute to making the code more complex. I'd be willing to implement this and provide a PR for this but I would like your opinion if it should be a warning or renaming the variables or maybe even some command line option to choose between the two.