pfalcon / ScratchABlock

Yet another crippled decompiler project
https://github.com/EiNSTeiN-/decompiler/issues/9#issuecomment-103221200
GNU General Public License v3.0
104 stars 23 forks source link

decomp: split_node: Fix deepcopy import. #25

Closed maximumspatium closed 6 years ago

maximumspatium commented 6 years ago

I encountered an input that triggers the following import failure in decomp:split_node():

Error while processing file: sub_204bdc.lst
Traceback (most recent call last):
  File "apply_xform.py", line 229, in <module>
    changed = one_iter(input, output, iter_no)
  File "apply_xform.py", line 191, in one_iter
    handle_file(args)
  File "apply_xform.py", line 68, in handle_file
    raise e
  File "apply_xform.py", line 65, in handle_file
    handle_file_unprotected(args)
  File "apply_xform.py", line 93, in handle_file_unprotected
    mod.apply(cfg)
  File "/Users/maxim/Documents/Development/ScratchABlock_maxim/script_decompile.py", line 97, in apply
    if match_abnormal_sel(cfg):
  File "/Users/maxim/Documents/Development/ScratchABlock_maxim/decomp.py", line 458, in match_abnormal_sel
    split_node(cfg, v)
  File "/Users/maxim/Documents/Development/ScratchABlock_maxim/decomp.py", line 35, in split_node
    node2_props = copy.deepcopy(node_props)
AttributeError: 'function' object has no attribute 'deepcopy'

It looks like something "shadows" python's copy. Hence this simple fix.

pfalcon commented 6 years ago

I believe I hit that once also, and did something to work around that too. So how about we trying to fix it better this time? The issues seems to be exactly that "from copy import copy" is used somewhere, creating ambiguity between a module and a function name. And the right way to solve it would be use namespace reference (e.g. copy.copy()) everywhere. Let me know if you agree and I can fix it.

maximumspatium commented 6 years ago

Let me know if you agree and I can fix it.

Sure, +1 for a better fix (if you'll be able to spot the issue). Putting copy.copy(node_props) right before deepcopy invocation results in the same error. On the other hand, copy(node_props) works...

maximumspatium commented 6 years ago

"from copy import copy" is used somewhere

Yep, that's core.py...

maximumspatium commented 6 years ago

Another attempt to do the things right...

pfalcon commented 6 years ago

Merged, thanks!

pfalcon commented 6 years ago

Note that this is a part of bigger issue: https://github.com/pfalcon/ScratchABlock/issues/17 , for which I appreciate feedback.