|
| | parser = ArgumentParser("Dependency grapher") |
| |
| | help |
| |
| | nargs |
| |
| | action |
| |
| | args = parser.parse_args() |
| |
| | loc_db = LocationDB() |
| |
| | cont = Container.from_stream(fstream, loc_db) |
| |
| | arch = args.architecture if args.architecture else cont.arch |
| |
| | machine = Machine(arch) |
| |
| | elements = set() |
| |
| | regs = machine.mn.regs.all_regs_ids_byname |
| |
| | mdis = machine.dis_engine(cont.bin_stream, dont_dis_nulstart_bloc=True, loc_db=loc_db) |
| |
| | ir_arch = machine.ira(loc_db) |
| |
| dictionary | init_ctx = {} |
| |
| | e_mem = ExprMem(ExprId("ESP_init", 32) + ExprInt(4 * (i + 1), 32), 32) |
| |
| | asmcfg = mdis.dis_multiblock(int(args.func_addr, 0)) |
| |
| | ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg) |
| |
| | dg |
| |
| | target_addr = int(args.target_addr, 0) |
| |
| | current_loc_key = next(iter(ircfg.getby_offset(target_addr))) |
| |
| int | assignblk_index = 0 |
| |
| | current_block = ircfg.get_block(current_loc_key) |
| |
| list | json_solutions = [] |
| |
| string | fname = "sol_%d.dot" % sol_nb |
| |
| | results = sol.emul(ir_arch, ctx=init_ctx) |
| |
| dictionary | tokens = {str(k): str(v) for k, v in viewitems(results)} |
| |
| string | result = ", ".join("=".join(x) for x in viewitems(tokens)) |
| |
| | sat = sol.is_satisfiable |
| |
| dictionary | constraints = {} |
| |
| bool | EMULATION = True |
| |
| | STEP_COUNTER = count() |
| |
| | A = ExprId("a", 32) |
| |
| | B = ExprId("b", 32) |
| |
| | C = ExprId("c", 32) |
| |
| | D = ExprId("d", 32) |
| |
| | R = ExprId("r", 32) |
| |
| | COND = ExprId("cond", 32) |
| |
| | A_INIT = ExprId("a_init", 32) |
| |
| | B_INIT = ExprId("b_init", 32) |
| |
| | C_INIT = ExprId("c_init", 32) |
| |
| | D_INIT = ExprId("d_init", 32) |
| |
| | PC = ExprId("pc", 32) |
| |
| | SP = ExprId("sp", 32) |
| |
| | CST0 = ExprInt(0x0, 32) |
| |
| | CST1 = ExprInt(0x1, 32) |
| |
| | CST2 = ExprInt(0x2, 32) |
| |
| | CST3 = ExprInt(0x3, 32) |
| |
| | CST22 = ExprInt(0x22, 32) |
| |
| | CST23 = ExprInt(0x23, 32) |
| |
| | CST24 = ExprInt(0x24, 32) |
| |
| | CST33 = ExprInt(0x33, 32) |
| |
| | CST35 = ExprInt(0x35, 32) |
| |
| | CST37 = ExprInt(0x37, 32) |
| |
| | LBL0 = loc_db.add_location("lbl0", 0) |
| |
| | LBL1 = loc_db.add_location("lbl1", 1) |
| |
| | LBL2 = loc_db.add_location("lbl2", 2) |
| |
| | LBL3 = loc_db.add_location("lbl3", 3) |
| |
| | LBL4 = loc_db.add_location("lbl4", 4) |
| |
| | LBL5 = loc_db.add_location("lbl5", 5) |
| |
| | LBL6 = loc_db.add_location("lbl6", 6) |
| |
| | DNA = DependencyNode(LBL2, A, 0) |
| |
| | DNB = DependencyNode(LBL1, B, 1) |
| |
| | DNC = DependencyNode(LBL1, C, 0) |
| |
| | DNB2 = DependencyNode(LBL1, B, 1) |
| |
| | DNC2 = DependencyNode(LBL1, C, 0) |
| |
| | DNB3 = DependencyNode(LBL1, B, 1) |
| |
| | DNC3 = DependencyNode(LBL1, C, 0) |
| |
| | IRA = IRATest(loc_db) |
| |
| | IRDst = IRA.IRDst |
| |
| | END = ExprId("END", IRDst.size) |
| |
| | G1_IRA = IRA.new_ircfg() |
| |
| def | G1_IRB0 = gen_irblock(LBL0, [[ExprAssign(C, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G1_IRB1 = gen_irblock(LBL1, [[ExprAssign(B, C), ExprAssign(IRDst, ExprLoc(LBL2, 32))]]) |
| |
| def | G1_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, B), ExprAssign(IRDst, END)]]) |
| |
| | G2_IRA = IRA.new_ircfg() |
| |
| def | G2_IRB0 = gen_irblock(LBL0, [[ExprAssign(C, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G2_IRB1 = gen_irblock(LBL1, [[ExprAssign(B, CST2), ExprAssign(IRDst, ExprLoc(LBL2, 32))]]) |
| |
| def | G2_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, B + C), ExprAssign(IRDst, END)]]) |
| |
| | G3_IRA = IRA.new_ircfg() |
| |
| def | G3_IRB0 |
| |
| def | G3_IRB1 = gen_irblock(LBL1, [[ExprAssign(B, CST2), ExprAssign(IRDst, ExprLoc(LBL3, 32))]]) |
| |
| def | G3_IRB2 = gen_irblock(LBL2, [[ExprAssign(B, CST3), ExprAssign(IRDst, ExprLoc(LBL3, 32))]]) |
| |
| def | G3_IRB3 = gen_irblock(LBL3, [[ExprAssign(A, B + C), ExprAssign(IRDst, END)]]) |
| |
| | G4_IRA = IRA.new_ircfg() |
| |
| def | G4_IRB0 = gen_irblock(LBL0, [[ExprAssign(C, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G4_IRB1 |
| |
| def | G4_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, B), ExprAssign(IRDst, END)]]) |
| |
| | G5_IRA = IRA.new_ircfg() |
| |
| def | G5_IRB0 = gen_irblock(LBL0, [[ExprAssign(B, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G5_IRB1 |
| |
| def | G5_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, B), ExprAssign(IRDst, END)]]) |
| |
| | G6_IRA = IRA.new_ircfg() |
| |
| def | G6_IRB0 = gen_irblock(LBL0, [[ExprAssign(B, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G6_IRB1 = gen_irblock(LBL1, [[ExprAssign(A, B), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| | G7_IRA = IRA.new_ircfg() |
| |
| def | G7_IRB0 = gen_irblock(LBL0, [[ExprAssign(C, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G7_IRB1 |
| |
| def | G7_IRB2 = gen_irblock(LBL2, [[ExprAssign(D, A), ExprAssign(IRDst, END)]]) |
| |
| | G8_IRA = IRA.new_ircfg() |
| |
| def | G8_IRB0 = gen_irblock(LBL0, [[ExprAssign(C, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G8_IRB1 |
| |
| def | G8_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, B), ExprAssign(IRDst, END)]]) |
| |
| | G10_IRA = IRA.new_ircfg() |
| |
| def | G10_IRB1 |
| |
| def | G10_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, B), ExprAssign(IRDst, END)]]) |
| |
| | G11_IRA = IRA.new_ircfg() |
| |
| def | G11_IRB0 |
| |
| def | G11_IRB1 |
| |
| def | G11_IRB2 = gen_irblock(LBL2, [[ExprAssign(A, A - B), ExprAssign(IRDst, END)]]) |
| |
| | G12_IRA = IRA.new_ircfg() |
| |
| def | G12_IRB0 = gen_irblock(LBL0, [[ExprAssign(B, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G12_IRB1 |
| |
| def | G12_IRB2 = gen_irblock(LBL2, [[ExprAssign(B, A), ExprAssign(IRDst, END)]]) |
| |
| | G13_IRA = IRA.new_ircfg() |
| |
| def | G13_IRB0 |
| |
| def | G13_IRB1 |
| |
| def | G13_IRB2 |
| |
| def | G13_IRB3 = gen_irblock(LBL3, [[ExprAssign(R, C), ExprAssign(IRDst, END)]]) |
| |
| | G14_IRA = IRA.new_ircfg() |
| |
| def | G14_IRB0 |
| |
| def | G14_IRB1 |
| |
| def | G14_IRB2 |
| |
| def | G14_IRB3 = gen_irblock(LBL3, [[ExprAssign(R, D + B), ExprAssign(IRDst, END)]]) |
| |
| | G15_IRA = IRA.new_ircfg() |
| |
| def | G15_IRB0 = gen_irblock(LBL0, [[ExprAssign(A, CST1), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G15_IRB1 |
| |
| def | G15_IRB2 = gen_irblock(LBL2, [[ExprAssign(R, B), ExprAssign(IRDst, END)]]) |
| |
| | G16_IRA = IRA.new_ircfg() |
| |
| def | G16_IRB0 |
| |
| def | G16_IRB1 |
| |
| def | G16_IRB2 = gen_irblock(LBL2, [[ExprAssign(D, A), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G16_IRB3 = gen_irblock(LBL3, [[ExprAssign(R, D), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G16_IRB4 = gen_irblock(LBL4, [[ExprAssign(R, A), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| def | G16_IRB5 = gen_irblock(LBL5, [[ExprAssign(R, A), ExprAssign(IRDst, ExprLoc(LBL1, 32))]]) |
| |
| | G17_IRA = IRA.new_ircfg() |
| |
| def | G17_IRB0 |
| |
| def | G17_IRB1 |
| |
| def | G17_IRB2 |
| |
| | G1_TEST1_DN1 |
| |
| tuple | G1_INPUT = (set([G1_TEST1_DN1]), set([G1_IRB0.loc_key])) |
| |
| | G2_TEST1_DN1 |
| |
| tuple | G2_INPUT = (set([G2_TEST1_DN1]), set([G2_IRB0.loc_key])) |
| |
| | G3_TEST1_0_DN1 |
| |
| tuple | G3_INPUT = (set([G3_TEST1_0_DN1]), set([G3_IRB0.loc_key])) |
| |
| | G4_TEST1_DN1 |
| |
| tuple | G4_INPUT = (set([G4_TEST1_DN1]), set([G4_IRB0.loc_key])) |
| |
| | G5_TEST1_0_DN1 |
| |
| tuple | G5_INPUT = (set([G5_TEST1_0_DN1]), set([G5_IRB0.loc_key])) |
| |
| | G6_TEST1_0_DN1 |
| |
| tuple | G6_INPUT = (set([G6_TEST1_0_DN1]), set([G6_IRB0.loc_key])) |
| |
| | G7_TEST1_0_DN1 |
| |
| tuple | G7_INPUT = (set([G7_TEST1_0_DN1]), set([G7_IRB0.loc_key])) |
| |
| | G8_TEST1_0_DN1 |
| |
| tuple | G8_INPUT = (set([G8_TEST1_0_DN1]), set([G3_IRB0.loc_key])) |
| |
| | G9_TEST1_0_DN1 |
| |
| | G9_TEST1_0_DN5 |
| |
| tuple | G9_INPUT = (set([G9_TEST1_0_DN1, G9_TEST1_0_DN5]), set([G8_IRB0.loc_key])) |
| |
| | G10_TEST1_0_DN1 |
| |
| tuple | G10_INPUT = (set([G10_TEST1_0_DN1]), set([G10_IRB1.loc_key])) |
| |
| | G11_TEST1_DN1 |
| |
| tuple | G11_INPUT = (set([G11_TEST1_DN1]), set([G11_IRB0.loc_key])) |
| |
| | G12_TEST1_0_DN1 = DependencyNode(G12_IRB2.loc_key, B, 1) |
| |
| tuple | G12_INPUT = (set([G12_TEST1_0_DN1]), set([])) |
| |
| | G13_TEST1_0_DN4 = DependencyNode(G13_IRB3.loc_key, R, 1) |
| |
| tuple | G13_INPUT = (set([G13_TEST1_0_DN4]), set([])) |
| |
| | G14_TEST1_0_DN1 = DependencyNode(G14_IRB3.loc_key, R, 1) |
| |
| tuple | G14_INPUT = (set([G14_TEST1_0_DN1]), set([])) |
| |
| | G15_TEST1_0_DN1 = DependencyNode(G15_IRB2.loc_key, R, 1) |
| |
| tuple | G15_INPUT = (set([G15_TEST1_0_DN1]), set([])) |
| |
| | G16_TEST1_0_DN1 = DependencyNode(G16_IRB5.loc_key, R, 1) |
| |
| tuple | G16_INPUT = (set([G16_TEST1_0_DN1]), set([])) |
| |
| | G17_TEST1_DN1 = DependencyNode(G17_IRB2.loc_key, A, 1) |
| |
| tuple | G17_INPUT = (set([G17_TEST1_DN1]), set([])) |
| |
| | FAILED = set() |
| |
| list | flat_test_results |
| |
| list | test_results |
| |
| list | all_flats = [] |
| |
| | depnodes |
| |
| | heads |
| |
| list | suffix_key_list |
| |
| list | mode_suffix = suffix_key_list[g_ind] |
| |
| string | graph_test_key = "graph" + mode_suffix |
| |
| | all_results = set() |
| |
| | all_flat = set() |
| |
| def | flat_depnodes = get_flat_init_depnodes(depnodes) |
| |
| | test_num |
| |
| | end |
| |
Regression test module for DependencyGraph