rocky / python-uncompyle6

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

Decompiling 3.6.9 pyc results in - Error: IndexError: list index out of range #327

Closed Fohdeesha closed 4 years ago

Fohdeesha commented 4 years ago

Hi! I know you're a busy guy and I can't provide the source code, so I don't expect a fix - just posting for posterity in case maybe it's a simple bug to fix on uncompyle6's side. I am adding some custom cli commands to my router distro which is all processed by a ton of 3.6.9 pyc files. So far Uncompyle6 has flawlessly decompiled all of them I've needed. However there's one last pyc I need to modify that checks the integrity of all the cli commands/netconf YANG crap that gets passed through it. It's using sysrepo-python. When running a decompile, this is what I get:

##Running Uncompyle6 under python 3.6.9:
root@testing:~/pycdc# uncompyle6 /usr/lib/yams/python/yams/util/sysrepo.pyc
# uncompyle6 version 3.7.4
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.9 (default, Jul 17 2020, 12:50:27)
# [GCC 8.4.0]
# Embedded file name: /usr/lib/yams/python/yams/util/sysrepo.py
# Compiled at: 2020-08-18 01:00:57
# Size of source mod 2**32: 37976 bytes
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/uncompyle6/semantics/pysource.py", line 2079, in template_engine
    node[index]
  File "/usr/lib/python3.6/collections/__init__.py", line 1050, in __getitem__
    def __getitem__(self, i): return self.data[i]
IndexError: list index out of range

##Running Uncompyle6 under python 3.7.3:
root@testing:~/cli# uncompyle6 sysrepo.pyc
# uncompyle6 version 3.7.4
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.7.3 (default, Jul 25 2020, 13:03:44)
# [GCC 8.3.0]
# Embedded file name: /usr/lib/yams/python/yams/util/sysrepo.py
# Compiled at: 2020-08-17 21:00:57
# Size of source mod 2**32: 37976 bytes
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/uncompyle6/semantics/pysource.py", line 2079, in template_engine
    node[index]
  File "/usr/local/lib/python3.7/dist-packages/spark_parser/ast.py", line 23, in __getitem__
    return self.data[i]
IndexError: list index out of range

I tried to use Decompyle++ instead, which also errors out, but manages to spit out about 70% of the original py succesfully. It also successfully disassembled the whole file. Linked below are the original bytecode pyc, the failed partial py decompile from Decompyle++, as well as the assembly output from Decompyle++ -

https://fohdeesha.com/pyc/sysrepo.pyc https://fohdeesha.com/pyc/sysrepo-partial-failed.py https://fohdeesha.com/pyc/sysrepo.pyc-assembly.txt

Thank you for reading!

rocky commented 4 years ago

With commit 4bbdbe38948eb79b193c9624f5ee2ef12dbebf8e this decompiled okay.

However there should be other changes that need to be investigated as to why there error handling failed so badly, when there was a problem.

Fohdeesha commented 4 years ago

WOW! Thank you, I was not expecting that. Is there any place I can donate some beer money other than the github sponsorship?

rocky commented 4 years ago

Github sponsership is fine - thanks. You are like only the 2nd person to do so in all these months.

(But in truth, right now I am very busy and shouildn't devote too much time here.)