rocky / python-uncompyle6

A cross-version Python bytecode decompiler
GNU General Public License v3.0
3.79k stars 413 forks source link

Error in unicode decompilation Python 2.7 #443

Closed andrem-eberle closed 1 year ago

andrem-eberle commented 1 year ago

Description

Unicode strings in Python 2.7.18 are generating regular strings after decompilation.

This one might be a minor bug, and usually not an issue, but it breaks some tests in test_ast.py for the 2.7.18.

Also this one seems to include potential xdis disasm errors also, as it doesn't seem to flag the string as unicode?

How to Reproduce

Input:

var1 = u'x'
var2 = 'x'
print(type(var1))
print(type(var2))

run compileall & uncompyle6

Output Given

var1 = 'x'
var2 = 'x'
print(type(var1))
print(type(var2))

Running the first code will give:

<type 'unicode'>
<type 'str'>

For the uncompiled code:

<type 'str'>
<type 'str'>

Expected behavior

Should return the correct unicode form for the string.

Environment

Python 2.7.18 Ubuntu 16.0x

rocky commented 1 year ago

I am not totally sure, but this is probably better corrected in xdis, and then possibly no change is needed in this project.

I suggest looking at the recent change to xdis to see how Python 2's "long" type was recently handled in Python 3. Probably something similar for "unicode" is needed.

rocky commented 1 year ago

This was more an xdis bug than an uncompyle6 bug. The master branch of xdis now corrects this.

Flame-Codes commented 1 year ago

:blush: