Top

miasm2.arch.x86.disasm module

from miasm2.core.asmblock import disasmEngine
from miasm2.arch.x86.arch import mn_x86


cb_x86_funcs = []


def cb_x86_disasm(*args, **kwargs):
    for func in cb_x86_funcs:
        func(*args, **kwargs)


class dis_x86(disasmEngine):
    attrib = None

    def __init__(self, bs=None, **kwargs):
        super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
        self.dis_block_callback = cb_x86_disasm


class dis_x86_16(dis_x86):
    attrib = 16


class dis_x86_32(dis_x86):
    attrib = 32


class dis_x86_64(dis_x86):
    attrib = 64

Module variables

var cb_x86_funcs

Functions

def cb_x86_disasm(

*args, **kwargs)

def cb_x86_disasm(*args, **kwargs):
    for func in cb_x86_funcs:
        func(*args, **kwargs)

Classes

class dis_x86

class dis_x86(disasmEngine):
    attrib = None

    def __init__(self, bs=None, **kwargs):
        super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
        self.dis_block_callback = cb_x86_disasm

Ancestors (in MRO)

  • dis_x86
  • miasm2.core.asmblock.disasmEngine
  • __builtin__.object

Class variables

var attrib

Instance variables

var dis_bloc_callback

var dis_block_callback

var job_done

var symbol_pool

Methods

def __init__(

self, bs=None, **kwargs)

def __init__(self, bs=None, **kwargs):
    super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
    self.dis_block_callback = cb_x86_disasm

def dis_bloc(

self, offset)

DEPRECATED function Use dis_block instead of dis_bloc

def dis_bloc(self, offset):
    """
    DEPRECATED function
    Use dis_block instead of dis_bloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_block" instead of "dis_bloc"')
    return self.dis_block(offset)

def dis_block(

self, offset)

Disassemble the block at offset @offset and return the created AsmBlock @offset: targeted offset to disassemble

def dis_block(self, offset):
    """Disassemble the block at offset @offset and return the created
    AsmBlock
    @offset: targeted offset to disassemble
    """
    current_block, _ = self._dis_block(offset)
    return current_block

def dis_instr(

self, offset)

Disassemble one instruction at offset @offset and return the corresponding instruction instance @offset: targeted offset to disassemble

def dis_instr(self, offset):
    """Disassemble one instruction at offset @offset and return the
    corresponding instruction instance
    @offset: targeted offset to disassemble
    """
    old_lineswd = self.lines_wd
    self.lines_wd = 1
    try:
        block = self.dis_block(offset)
    finally:
        self.lines_wd = old_lineswd
    instr = block.lines[0]
    return instr

def dis_multibloc(

self, offset, blocs=None)

DEPRECATED function Use dis_multiblock instead of dis_multibloc

def dis_multibloc(self, offset, blocs=None):
    """
    DEPRECATED function
    Use dis_multiblock instead of dis_multibloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_multiblock" instead of "dis_multibloc"')
    return self.dis_multiblock(offset, blocs)

def dis_multiblock(

self, offset, blocks=None)

Disassemble every block reachable from @offset regarding specific disasmEngine conditions Return an AsmCFG instance containing disassembled blocks @offset: starting offset @blocks: (optional) AsmCFG instance of already disassembled blocks to merge with

def dis_multiblock(self, offset, blocks=None):
    """Disassemble every block reachable from @offset regarding
    specific disasmEngine conditions
    Return an AsmCFG instance containing disassembled blocks
    @offset: starting offset
    @blocks: (optional) AsmCFG instance of already disassembled blocks to
            merge with
    """
    log_asmblock.info("dis bloc all")
    job_done = set()
    if blocks is None:
        blocks = AsmCFG(self.loc_db)
    todo = [offset]
    bloc_cpt = 0
    while len(todo):
        bloc_cpt += 1
        if self.blocs_wd is not None and bloc_cpt > self.blocs_wd:
            log_asmblock.debug("blocks watchdog reached at %X", int(offset))
            break
        target_offset = int(todo.pop(0))
        if (target_offset is None or
                target_offset in job_done):
            continue
        cur_block, nexts = self._dis_block(target_offset, job_done)
        todo += nexts
        blocks.add_block(cur_block)
    blocks.apply_splitting(self.loc_db,
                           dis_block_callback=self.dis_block_callback,
                           mn=self.arch, attrib=self.attrib,
                           pool_bin=self.bin_stream)
    return blocks

def get_dis_bloc_callback(

self)

def get_dis_bloc_callback(self):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    return self.dis_block_callback

def get_job_done(

self)

def get_job_done(self):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return set()

def set_dis_bloc_callback(

self, function)

def set_dis_bloc_callback(self, function):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    self.dis_block_callback = function

def set_job_done(

self, _)

def set_job_done(self, _):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return

class dis_x86_16

class dis_x86_16(dis_x86):
    attrib = 16

Ancestors (in MRO)

Class variables

var attrib

Inheritance: dis_x86.attrib

Instance variables

var dis_bloc_callback

Inheritance: dis_x86.dis_bloc_callback

var dis_block_callback

Inheritance: dis_x86.dis_block_callback

var job_done

Inheritance: dis_x86.job_done

var symbol_pool

Inheritance: dis_x86.symbol_pool

Methods

def __init__(

self, bs=None, **kwargs)

Inheritance: dis_x86.__init__

def __init__(self, bs=None, **kwargs):
    super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
    self.dis_block_callback = cb_x86_disasm

def dis_bloc(

self, offset)

Inheritance: dis_x86.dis_bloc

DEPRECATED function Use dis_block instead of dis_bloc

def dis_bloc(self, offset):
    """
    DEPRECATED function
    Use dis_block instead of dis_bloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_block" instead of "dis_bloc"')
    return self.dis_block(offset)

def dis_block(

self, offset)

Inheritance: dis_x86.dis_block

Disassemble the block at offset @offset and return the created AsmBlock @offset: targeted offset to disassemble

def dis_block(self, offset):
    """Disassemble the block at offset @offset and return the created
    AsmBlock
    @offset: targeted offset to disassemble
    """
    current_block, _ = self._dis_block(offset)
    return current_block

def dis_instr(

self, offset)

Inheritance: dis_x86.dis_instr

Disassemble one instruction at offset @offset and return the corresponding instruction instance @offset: targeted offset to disassemble

def dis_instr(self, offset):
    """Disassemble one instruction at offset @offset and return the
    corresponding instruction instance
    @offset: targeted offset to disassemble
    """
    old_lineswd = self.lines_wd
    self.lines_wd = 1
    try:
        block = self.dis_block(offset)
    finally:
        self.lines_wd = old_lineswd
    instr = block.lines[0]
    return instr

def dis_multibloc(

self, offset, blocs=None)

Inheritance: dis_x86.dis_multibloc

DEPRECATED function Use dis_multiblock instead of dis_multibloc

def dis_multibloc(self, offset, blocs=None):
    """
    DEPRECATED function
    Use dis_multiblock instead of dis_multibloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_multiblock" instead of "dis_multibloc"')
    return self.dis_multiblock(offset, blocs)

def dis_multiblock(

self, offset, blocks=None)

Inheritance: dis_x86.dis_multiblock

Disassemble every block reachable from @offset regarding specific disasmEngine conditions Return an AsmCFG instance containing disassembled blocks @offset: starting offset @blocks: (optional) AsmCFG instance of already disassembled blocks to merge with

def dis_multiblock(self, offset, blocks=None):
    """Disassemble every block reachable from @offset regarding
    specific disasmEngine conditions
    Return an AsmCFG instance containing disassembled blocks
    @offset: starting offset
    @blocks: (optional) AsmCFG instance of already disassembled blocks to
            merge with
    """
    log_asmblock.info("dis bloc all")
    job_done = set()
    if blocks is None:
        blocks = AsmCFG(self.loc_db)
    todo = [offset]
    bloc_cpt = 0
    while len(todo):
        bloc_cpt += 1
        if self.blocs_wd is not None and bloc_cpt > self.blocs_wd:
            log_asmblock.debug("blocks watchdog reached at %X", int(offset))
            break
        target_offset = int(todo.pop(0))
        if (target_offset is None or
                target_offset in job_done):
            continue
        cur_block, nexts = self._dis_block(target_offset, job_done)
        todo += nexts
        blocks.add_block(cur_block)
    blocks.apply_splitting(self.loc_db,
                           dis_block_callback=self.dis_block_callback,
                           mn=self.arch, attrib=self.attrib,
                           pool_bin=self.bin_stream)
    return blocks

def get_dis_bloc_callback(

self)

Inheritance: dis_x86.get_dis_bloc_callback

def get_dis_bloc_callback(self):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    return self.dis_block_callback

def get_job_done(

self)

Inheritance: dis_x86.get_job_done

def get_job_done(self):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return set()

def set_dis_bloc_callback(

self, function)

Inheritance: dis_x86.set_dis_bloc_callback

def set_dis_bloc_callback(self, function):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    self.dis_block_callback = function

def set_job_done(

self, _)

Inheritance: dis_x86.set_job_done

def set_job_done(self, _):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return

class dis_x86_32

class dis_x86_32(dis_x86):
    attrib = 32

Ancestors (in MRO)

Class variables

var attrib

Inheritance: dis_x86.attrib

Instance variables

var dis_bloc_callback

Inheritance: dis_x86.dis_bloc_callback

var dis_block_callback

Inheritance: dis_x86.dis_block_callback

var job_done

Inheritance: dis_x86.job_done

var symbol_pool

Inheritance: dis_x86.symbol_pool

Methods

def __init__(

self, bs=None, **kwargs)

Inheritance: dis_x86.__init__

def __init__(self, bs=None, **kwargs):
    super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
    self.dis_block_callback = cb_x86_disasm

def dis_bloc(

self, offset)

Inheritance: dis_x86.dis_bloc

DEPRECATED function Use dis_block instead of dis_bloc

def dis_bloc(self, offset):
    """
    DEPRECATED function
    Use dis_block instead of dis_bloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_block" instead of "dis_bloc"')
    return self.dis_block(offset)

def dis_block(

self, offset)

Inheritance: dis_x86.dis_block

Disassemble the block at offset @offset and return the created AsmBlock @offset: targeted offset to disassemble

def dis_block(self, offset):
    """Disassemble the block at offset @offset and return the created
    AsmBlock
    @offset: targeted offset to disassemble
    """
    current_block, _ = self._dis_block(offset)
    return current_block

def dis_instr(

self, offset)

Inheritance: dis_x86.dis_instr

Disassemble one instruction at offset @offset and return the corresponding instruction instance @offset: targeted offset to disassemble

def dis_instr(self, offset):
    """Disassemble one instruction at offset @offset and return the
    corresponding instruction instance
    @offset: targeted offset to disassemble
    """
    old_lineswd = self.lines_wd
    self.lines_wd = 1
    try:
        block = self.dis_block(offset)
    finally:
        self.lines_wd = old_lineswd
    instr = block.lines[0]
    return instr

def dis_multibloc(

self, offset, blocs=None)

Inheritance: dis_x86.dis_multibloc

DEPRECATED function Use dis_multiblock instead of dis_multibloc

def dis_multibloc(self, offset, blocs=None):
    """
    DEPRECATED function
    Use dis_multiblock instead of dis_multibloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_multiblock" instead of "dis_multibloc"')
    return self.dis_multiblock(offset, blocs)

def dis_multiblock(

self, offset, blocks=None)

Inheritance: dis_x86.dis_multiblock

Disassemble every block reachable from @offset regarding specific disasmEngine conditions Return an AsmCFG instance containing disassembled blocks @offset: starting offset @blocks: (optional) AsmCFG instance of already disassembled blocks to merge with

def dis_multiblock(self, offset, blocks=None):
    """Disassemble every block reachable from @offset regarding
    specific disasmEngine conditions
    Return an AsmCFG instance containing disassembled blocks
    @offset: starting offset
    @blocks: (optional) AsmCFG instance of already disassembled blocks to
            merge with
    """
    log_asmblock.info("dis bloc all")
    job_done = set()
    if blocks is None:
        blocks = AsmCFG(self.loc_db)
    todo = [offset]
    bloc_cpt = 0
    while len(todo):
        bloc_cpt += 1
        if self.blocs_wd is not None and bloc_cpt > self.blocs_wd:
            log_asmblock.debug("blocks watchdog reached at %X", int(offset))
            break
        target_offset = int(todo.pop(0))
        if (target_offset is None or
                target_offset in job_done):
            continue
        cur_block, nexts = self._dis_block(target_offset, job_done)
        todo += nexts
        blocks.add_block(cur_block)
    blocks.apply_splitting(self.loc_db,
                           dis_block_callback=self.dis_block_callback,
                           mn=self.arch, attrib=self.attrib,
                           pool_bin=self.bin_stream)
    return blocks

def get_dis_bloc_callback(

self)

Inheritance: dis_x86.get_dis_bloc_callback

def get_dis_bloc_callback(self):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    return self.dis_block_callback

def get_job_done(

self)

Inheritance: dis_x86.get_job_done

def get_job_done(self):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return set()

def set_dis_bloc_callback(

self, function)

Inheritance: dis_x86.set_dis_bloc_callback

def set_dis_bloc_callback(self, function):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    self.dis_block_callback = function

def set_job_done(

self, _)

Inheritance: dis_x86.set_job_done

def set_job_done(self, _):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return

class dis_x86_64

class dis_x86_64(dis_x86):
    attrib = 64

Ancestors (in MRO)

Class variables

var attrib

Inheritance: dis_x86.attrib

Instance variables

var dis_bloc_callback

Inheritance: dis_x86.dis_bloc_callback

var dis_block_callback

Inheritance: dis_x86.dis_block_callback

var job_done

Inheritance: dis_x86.job_done

var symbol_pool

Inheritance: dis_x86.symbol_pool

Methods

def __init__(

self, bs=None, **kwargs)

Inheritance: dis_x86.__init__

def __init__(self, bs=None, **kwargs):
    super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
    self.dis_block_callback = cb_x86_disasm

def dis_bloc(

self, offset)

Inheritance: dis_x86.dis_bloc

DEPRECATED function Use dis_block instead of dis_bloc

def dis_bloc(self, offset):
    """
    DEPRECATED function
    Use dis_block instead of dis_bloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_block" instead of "dis_bloc"')
    return self.dis_block(offset)

def dis_block(

self, offset)

Inheritance: dis_x86.dis_block

Disassemble the block at offset @offset and return the created AsmBlock @offset: targeted offset to disassemble

def dis_block(self, offset):
    """Disassemble the block at offset @offset and return the created
    AsmBlock
    @offset: targeted offset to disassemble
    """
    current_block, _ = self._dis_block(offset)
    return current_block

def dis_instr(

self, offset)

Inheritance: dis_x86.dis_instr

Disassemble one instruction at offset @offset and return the corresponding instruction instance @offset: targeted offset to disassemble

def dis_instr(self, offset):
    """Disassemble one instruction at offset @offset and return the
    corresponding instruction instance
    @offset: targeted offset to disassemble
    """
    old_lineswd = self.lines_wd
    self.lines_wd = 1
    try:
        block = self.dis_block(offset)
    finally:
        self.lines_wd = old_lineswd
    instr = block.lines[0]
    return instr

def dis_multibloc(

self, offset, blocs=None)

Inheritance: dis_x86.dis_multibloc

DEPRECATED function Use dis_multiblock instead of dis_multibloc

def dis_multibloc(self, offset, blocs=None):
    """
    DEPRECATED function
    Use dis_multiblock instead of dis_multibloc
    """
    warnings.warn('DEPRECATION WARNING: use "dis_multiblock" instead of "dis_multibloc"')
    return self.dis_multiblock(offset, blocs)

def dis_multiblock(

self, offset, blocks=None)

Inheritance: dis_x86.dis_multiblock

Disassemble every block reachable from @offset regarding specific disasmEngine conditions Return an AsmCFG instance containing disassembled blocks @offset: starting offset @blocks: (optional) AsmCFG instance of already disassembled blocks to merge with

def dis_multiblock(self, offset, blocks=None):
    """Disassemble every block reachable from @offset regarding
    specific disasmEngine conditions
    Return an AsmCFG instance containing disassembled blocks
    @offset: starting offset
    @blocks: (optional) AsmCFG instance of already disassembled blocks to
            merge with
    """
    log_asmblock.info("dis bloc all")
    job_done = set()
    if blocks is None:
        blocks = AsmCFG(self.loc_db)
    todo = [offset]
    bloc_cpt = 0
    while len(todo):
        bloc_cpt += 1
        if self.blocs_wd is not None and bloc_cpt > self.blocs_wd:
            log_asmblock.debug("blocks watchdog reached at %X", int(offset))
            break
        target_offset = int(todo.pop(0))
        if (target_offset is None or
                target_offset in job_done):
            continue
        cur_block, nexts = self._dis_block(target_offset, job_done)
        todo += nexts
        blocks.add_block(cur_block)
    blocks.apply_splitting(self.loc_db,
                           dis_block_callback=self.dis_block_callback,
                           mn=self.arch, attrib=self.attrib,
                           pool_bin=self.bin_stream)
    return blocks

def get_dis_bloc_callback(

self)

Inheritance: dis_x86.get_dis_bloc_callback

def get_dis_bloc_callback(self):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    return self.dis_block_callback

def get_job_done(

self)

Inheritance: dis_x86.get_job_done

def get_job_done(self):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return set()

def set_dis_bloc_callback(

self, function)

Inheritance: dis_x86.set_dis_bloc_callback

def set_dis_bloc_callback(self, function):
    warnings.warn("""DEPRECATION WARNING: "dis_bloc_callback" use dis_block_callback.""")
    self.dis_block_callback = function

def set_job_done(

self, _)

Inheritance: dis_x86.set_job_done

def set_job_done(self, _):
    warnings.warn("""DEPRECATION WARNING: "job_done" is not needed anymore, support is dropped.""")
    return