def make_whiles(trace): trace = make(trace) explain("Loops -> whiles", trace) # clean up jumpdests trace = rewrite_trace( trace, lambda line: [] if opcode(line) == "jumpdest" else [line]) trace = simplify_trace(trace) return trace
def dec(): trace = VM(loader).run(target, stack=stack, timeout=60) explain("Initial decompiled trace", trace[1:]) if "--explain" in sys.argv: trace = rewrite_trace( trace, lambda line: [] if type(line) == str else [line]) explain("Without assembly", trace) trace = make_whiles(trace) explain("final", trace) if "--explain" in sys.argv: explain("folded", folder.fold(trace)) return trace
def dec(): trace = VM(loader).run(target) explain('Initial decompiled trace', trace[1:]) if '--explain' in sys.argv: trace = rewrite_trace( trace, lambda line: [] if type(line) == str else [line]) explain('Without assembly', trace) trace = make_whiles(trace) explain('final', trace) if '--explain' in sys.argv: explain('folded', folder.fold(trace)) return trace
trace = if_true continue jds_true = find_f_list(if_true, get_jds) jds_false = find_f_list(if_false, get_jds) assert (jd in jds_true) != (jd in jds_false), (jds_true, jds_false) def add_path(line): if line ~ ('goto', _, :svs): path2 = path for _, v_idx, v_val in svs: path2 = replace(path2, ('var', v_idx), v_val) return path2 + [line] else: return [line] if jd in jds_true: if_true = rewrite_trace(if_true, add_path) return path, if_true, if_false, cond else: if_false = rewrite_trace(if_false, add_path) return path, if_false, if_true, is_zero(cond) else: path.append(line) assert False, f'no if after label?{jd}'