ManuelBlanc / ljd

LuaJIT Raw-Bytecode Decompiler (LJD)
MIT License
1 stars 2 forks source link

ljd issue: AssertionError: Invalid node type: #1

Open ahxxm opened 5 years ago

ahxxm commented 5 years ago

sorry to submit issue here, but issue was disabled in original forked repo..

I got the error when decompiling this file md5.tar.gz , the full message is:

AssertionError: Invalid node type: <class 'ljd.ast.nodes.FunctionCall'> should be: (<class 'ljd.ast.nodes.Identifier'>, <class 'ljd.ast.nodes.TableElement'>, <class 'ljd.ast.nodes.MULTRES'>)
ahxxm commented 5 years ago

it makes sense(at least to me) that Constant and FunctionCall can be variable, I saw variables naming with utf-8 string in decompiled lua after patch..

but i didn't quite look into ast parsing, is holder.value == replacement reasonable? (without following change in _replace_node assert found will fail, now it can produce fairly good code combined with validator patch)..

diff --git a/ljd/ast/slotworks.py b/ljd/ast/slotworks.py
index ab47460..f67e678 100644
--- a/ljd/ast/slotworks.py
+++ b/ljd/ast/slotworks.py
@@ -188,10 +188,22 @@ def _eliminate_mass_assignments(massive):

 def _replace_node(holder, original, replacement):
     for key, value in holder.__dict__.items():
         if value == original:
             setattr(holder, key, replacement)
             return True
+        if value == replacement:
+            setattr(holder, key, replacement)
+            return True
+

     return False

diff --git a/ljd/ast/validator.py b/ljd/ast/validator.py
index de473c6..63fa2d4 100644
--- a/ljd/ast/validator.py
+++ b/ljd/ast/validator.py
@@ -67,6 +67,8 @@ EXPRESSION_TYPES = (
 )

 VARIABLE_TYPES = (
+    nodes.Constant,
+    nodes.FunctionCall,
     nodes.Identifier,
     nodes.TableElement,
     nodes.MULTRES  # It's not valid here, but it is a hack anyway...