Exemplo n.º 1
0
Arquivo: ir.py Projeto: acru3l/miasm
 def add_instr(self, line, loc_key=None, gen_pc_updt=False):
     if loc_key is None:
         loc_key = self.loc_db.add_location()
     block = AsmBlock(loc_key)
     block.lines = [line]
     self.add_block(block, gen_pc_updt)
     return loc_key
Exemplo n.º 2
0
Arquivo: ir.py Projeto: guedou/miasm
 def add_instr(self, line, loc_key=None, gen_pc_updt=False):
     if loc_key is None:
         loc_key = self.symbol_pool.gen_loc_key()
     block = AsmBlock(loc_key)
     block.lines = [line]
     self.add_block(block, gen_pc_updt)
     return loc_key
Exemplo n.º 3
0
 def add_instr(self, line, loc_key=None, gen_pc_updt=False):
     if loc_key is None:
         loc_key = self.symbol_pool.gen_loc_key()
     block = AsmBlock(loc_key)
     block.lines = [line]
     self.add_block(block, gen_pc_updt)
     return loc_key
Exemplo n.º 4
0
Arquivo: ir.py Projeto: commial/miasm
    def add_instr_to_ircfg(self, instr, ircfg, loc_key=None, gen_pc_updt=False):
        """
        Add the native instruction @instr to the @ircfg
        @instr: instruction instance
        @ircfg: IRCFG instance
        @loc_key: loc_key instance of the instruction destination
        @gen_pc_updt: insert PC update effects between instructions
        """

        if loc_key is None:
            offset = getattr(instr, "offset", None)
            loc_key = self.loc_db.add_location(offset=offset)
        block = AsmBlock(loc_key)
        block.lines = [instr]
        self.add_asmblock_to_ircfg(block, ircfg, gen_pc_updt)
        return loc_key
Exemplo n.º 5
0
    def add_instr_to_ircfg(self, instr, ircfg, loc_key=None, gen_pc_updt=False):
        """
        Add the native instruction @instr to the @ircfg
        @instr: instruction instance
        @ircfg: IRCFG instance
        @loc_key: loc_key instance of the instruction destination
        @gen_pc_updt: insert PC update effects between instructions
        """

        if loc_key is None:
            offset = getattr(instr, "offset", None)
            loc_key = self.loc_db.add_location(offset=offset)
        block = AsmBlock(loc_key)
        block.lines = [instr]
        self.add_asmblock_to_ircfg(block, ircfg, gen_pc_updt)
        return loc_key
Exemplo n.º 6
0
Arquivo: ir.py Projeto: zhencang/miasm
 def add_instr(self, line, addr=0, gen_pc_updt=False):
     block = AsmBlock(self.gen_label())
     block.lines = [line]
     self.add_bloc(block, gen_pc_updt)
Exemplo n.º 7
0
dg = DiGraphSimplifier()
dg.enable_passes([remove_useless_blocks])
blocks = dg(blocks)

### Only two blocks should remain
assert len(blocks) == 2
assert first_block in blocks
assert last_block in blocks

## Graph the final output
open("graph2.dot", "w").write(blocks.dot())

# Test helper methods
## Label2block should always be updated
assert blocks.label2block(first_block.label) == first_block
my_block = AsmBlock(AsmLabel("testlabel"))
blocks.add_node(my_block)
assert len(blocks) == 3
assert blocks.label2block(first_block.label) == first_block
assert blocks.label2block(my_block.label) == my_block

## Bad blocks
assert len(list(blocks.get_bad_blocks())) == 0
assert len(list(blocks.get_bad_blocks_predecessors())) == 0
### Add a bad block, not linked
my_bad_block = AsmBlockBad(AsmLabel("testlabel_bad"))
blocks.add_node(my_bad_block)
assert list(blocks.get_bad_blocks()) == [my_bad_block]
assert len(list(blocks.get_bad_blocks_predecessors())) == 0
### Link the bad block and update edges
### Indeed, a sub-element has been modified (bto from a block from blocks)
Exemplo n.º 8
0
 def add_instr(self, l, ad=0, gen_pc_updt=False):
     b = AsmBlock(self.gen_label())
     b.lines = [l]
     self.add_bloc(b, gen_pc_updt)
Exemplo n.º 9
0
dg.enable_passes([remove_useless_blocks])
asmcfg = dg(asmcfg)

### Only two asmcfg should remain
assert len(asmcfg) == 2
assert first_block.loc_key in asmcfg.nodes()
assert last_block_loc_key in asmcfg.nodes()

## Graph the final output
open("graph2.dot", "w").write(asmcfg.dot())

# Test helper methods
## loc_key_to_block should always be updated
assert asmcfg.loc_key_to_block(first_block.loc_key) == first_block
testlabel = mdis.loc_db.get_or_create_name_location("testlabel")
my_block = AsmBlock(testlabel)
asmcfg.add_block(my_block)
assert len(asmcfg) == 3
assert asmcfg.loc_key_to_block(first_block.loc_key) == first_block
assert asmcfg.loc_key_to_block(my_block.loc_key) == my_block

## Bad asmcfg
assert len(list(asmcfg.get_bad_blocks())) == 0
assert len(list(asmcfg.get_bad_blocks_predecessors())) == 0
### Add a bad block, not linked
testlabel_bad = mdis.loc_db.get_or_create_name_location("testlabel_bad")
my_bad_block = AsmBlockBad(testlabel_bad)
asmcfg.add_block(my_bad_block)
assert list(asmcfg.get_bad_blocks()) == [my_bad_block]
assert len(list(asmcfg.get_bad_blocks_predecessors())) == 0
### Link the bad block and update edges
Exemplo n.º 10
0
 def add_instr(self, line, addr=0, gen_pc_updt=False):
     block = AsmBlock(self.gen_label())
     block.lines = [line]
     self.add_bloc(block, gen_pc_updt)