コード例 #1
0
ファイル: simplifier.py プロジェクト: w4kfu/miasm
 def do_merge_blocks(self, ssa, head):
     """
     Merge blocks with one parent/son
     @head: Location instance of the graph head
     """
     modified = merge_blocks(ssa.graph, set([head]))
     return modified
コード例 #2
0
    def do_dead_simp_ircfg(self, ircfg, head):
        """
        Apply:
        - dead_simp
        - remove_empty_assignblks
        - merge_blocks
        on the @ircfg until reaching fix point
        Return True if the graph has been modified

        @ircfg: IRCFG instance to simplify
        @head: Location instance of the ircfg head
        """
        modified = dead_simp(self.ir_arch, ircfg)
        modified |= remove_empty_assignblks(ircfg)
        modified |= merge_blocks(ircfg, set([head]))
        return modified
コード例 #3
0
ファイル: simplifier.py プロジェクト: cea-sec/miasm
    def do_dead_simp_ircfg(self, ircfg, head):
        """
        Apply:
        - dead_simp
        - remove_empty_assignblks
        - merge_blocks
        on the @ircfg until reaching fix point
        Return True if the graph has been modified

        @ircfg: IRCFG instance to simplify
        @head: Location instance of the ircfg head
        """
        modified = dead_simp(self.ir_arch, ircfg)
        modified |= remove_empty_assignblks(ircfg)
        modified |= merge_blocks(ircfg, set([head]))
        return modified
コード例 #4
0
    help="Apply simplifications rules (liveness, graph simplification, ...)")

args = parser.parse_args()

machine = Machine("x86_32")

loc_db = LocationDB()
cont = Container.from_stream(open(args.filename, 'rb'), loc_db)
mdis = machine.dis_engine(cont.bin_stream, loc_db=loc_db)
ir_arch = machine.ira(mdis.loc_db)
addr = int(args.address, 0)
deadrm = DeadRemoval(ir_arch)

asmcfg = mdis.dis_multiblock(addr)
ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg)
entry_points = set([mdis.loc_db.get_offset_location(addr)])

init_infos = ir_arch.arch.regs.regs_init
cst_propag_link = propagate_cst_expr(ir_arch, ircfg, addr, init_infos)

if args.simplify:
    ircfg.simplify(expr_simp)
    modified = True
    while modified:
        modified = False
        modified |= deadrm(ircfg)
        modified |= remove_empty_assignblks(ircfg)
        modified |= merge_blocks(ircfg, entry_points)

open("%s.propag.dot" % args.filename, 'w').write(ircfg.dot())
コード例 #5
0
G8_RES_IRB1 = gen_irblock(LBL1, [[
    ExprAssign(A, C),
    ExprAssign(IRDst, ExprLoc(LBL1, 32)),
]])

for irb in [G8_RES_IRB0, G8_RES_IRB1]:
    G8_RES.add_irblock(irb)

################# Tests

for i, (g_test, g_ref) in enumerate([
    (G1, G1_RES),
    (G2, G2_RES),
    (G3, G3_RES),
    (G4, G4_RES),
    (G5, G5_RES),
    (G6, G6_RES),
    (G7, G7_RES),
    (G8, G8_RES),
], 1):

    heads = g_test.heads()
    print('*' * 10, 'Test', i, "*" * 10)
    open('test_in_%d.dot' % i, 'w').write(g_test.dot())
    open('test_ref_%d.dot' % i, 'w').write(g_ref.dot())
    merge_blocks(g_test, heads)
    open('test_out_%d.dot' % i, 'w').write(g_test.dot())

    cmp_ir_graph(g_test, g_ref)
    print('\t', 'OK')
コード例 #6
0
ファイル: constant_propagation.py プロジェクト: cea-sec/miasm
                    help="Apply simplifications rules (liveness, graph simplification, ...)")

args = parser.parse_args()


machine = Machine("x86_32")

cont = Container.from_stream(open(args.filename, 'rb'))
mdis = machine.dis_engine(cont.bin_stream, loc_db=cont.loc_db)
ir_arch = machine.ira(mdis.loc_db)
addr = int(args.address, 0)

asmcfg = mdis.dis_multiblock(addr)
ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg)
entry_points = set([mdis.loc_db.get_offset_location(addr)])

init_infos = ir_arch.arch.regs.regs_init
cst_propag_link = propagate_cst_expr(ir_arch, ircfg, addr, init_infos)

if args.simplify:
    ircfg.simplify(expr_simp)
    modified = True
    while modified:
        modified = False
        modified |= dead_simp(ir_arch, ircfg)
        modified |= remove_empty_assignblks(ircfg)
        modified |= merge_blocks(ircfg, entry_points)


open("%s.propag.dot" % args.filename, 'w').write(ircfg.dot())