Skip to content

Commit

Permalink
Check that decompilation.json is actually serializable.
Browse files Browse the repository at this point in the history
  • Loading branch information
palkeo committed May 14, 2020
1 parent e689e62 commit 31fa85a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pano/decompiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import dataclasses
import io
import json
import logging
import os
import sys
from contextlib import redirect_stdout

Expand All @@ -25,7 +27,6 @@ class Decompilation:
json: dict = dataclasses.field(default_factory=dict)



def decompile_bytecode(code: str, only_func_name=None) -> Decompilation:
loader = Loader()
loader.load_binary(code) # Code is actually hex.
Expand Down Expand Up @@ -140,7 +141,7 @@ def _decompile_with_loader(loader, only_func_name=None) -> Decompilation:
if target > 1 and loader.lines[target][1] == "jumpdest":
target += 1

@timeout_decorator.timeout(60*3, use_signals=True)
@timeout_decorator.timeout(60 * 3, use_signals=True)
def dec():
trace = VM(loader).run(target, stack=stack, timeout=60)
explain("Initial decompiled trace", trace[1:])
Expand Down Expand Up @@ -177,10 +178,7 @@ def dec():
"""

contract = Contract(
problems=problems,
functions=functions,
)
contract = Contract(problems=problems, functions=functions,)

contract.postprocess()

Expand All @@ -191,8 +189,12 @@ def dec():

try:
decompilation.json = contract.json()
# This would raise a TypeError if it's not serializable, which is an
# important assumption people can make.
json.dump(decompilation.json, open(os.devnull, "w"))
except Exception:
logger.exception("failed json dump")
logger.exception("Failed json serialization.")
decompilation.json = {}

text_output = io.StringIO()
with redirect_stdout(text_output):
Expand Down

0 comments on commit 31fa85a

Please sign in to comment.