From 4acddaff97ce6afb28086f4ce93afffceebd4f53 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Thu, 15 Aug 2013 13:00:51 -0400 Subject: imachine.json --- unrpyc/Makefile | 2 +- unrpyc/decompiler.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'unrpyc') diff --git a/unrpyc/Makefile b/unrpyc/Makefile index d30347f..9566bea 100644 --- a/unrpyc/Makefile +++ b/unrpyc/Makefile @@ -27,7 +27,7 @@ test: all jshint --show-non-errors *.json install: all - install -t ../www/scripts script.json script.json.gz + install -t ../www/scripts script.json script.json.gz imachine.json imachine.json.gz .PHONY: all clean test install .PRECIOUS: imachine.json.o diff --git a/unrpyc/decompiler.py b/unrpyc/decompiler.py index d25fa21..75aced6 100644 --- a/unrpyc/decompiler.py +++ b/unrpyc/decompiler.py @@ -282,6 +282,13 @@ class PrintRenPython(python_ast.NodeVisitor): self.f.write(', '.join(map(self.visit, node.keywords))) self.f.write('],\n') + def visit_Compare(self, node): + self.f.write('[') + self.f.write(self.visit(node.left)) + self.f.write(', ') + self.f.write(self.visit(node.comparators[0])) + self.f.write('], ') + def quote(self, string): return '"%s"' % string @@ -395,7 +402,10 @@ def print_Call(f, stmt, indent_level): f.write('],\n') def print_If(f, stmt, indent_level): - f.write('["if", "%s", [\n' % (escape_string(stmt.entries[0][0]), )) + f.write('["if", ') + if_stmt = compile(stmt.entries[0][0], '', 'exec', python_ast.PyCF_ONLY_AST).body[0] + PrintRenPython(f).visit(if_stmt) + f.write('[\n') for inner_stmt in stmt.entries[0][1]: print_statement(f, inner_stmt, indent_level + 1) @@ -409,7 +419,10 @@ def print_If(f, stmt, indent_level): for case in elif_entries: indent(f, indent_level) - f.write('], "elif", "%s", [\n' % escape_string(case[0])) + f.write('], "elif", ') + elif_stmt = compile(case[0], '', 'exec', python_ast.PyCF_ONLY_AST).body[0] + PrintRenPython(f).visit(if_stmt) + f.write('[\n') for inner_stmt in case[1]: print_statement(f, inner_stmt, indent_level + 1) @@ -433,7 +446,7 @@ def print_args(f, arginfo): f.write(', ') # if name is not None: # f.write("%s = " % json.dumps(name)) - f.write(json.dumps(val)) + f.write(json.dumps(eval(val))) # TODO positional? def print_params(f, paraminfo): -- cgit v1.2.3-70-g09d2