diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-05-17 09:10:23 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-05-17 12:30:04 +0200 |
| commit | 6f7fbfb8b57c6a7dc382361520ab34c6d428b881 (patch) | |
| tree | 8122a45b48bfa7f6f5c546c2d1f31b841c88152e /miasm2/core/asmblock.py | |
| parent | f6a9db54b4f385d680abfe91b33c7c5f577118cb (diff) | |
| download | miasm-6f7fbfb8b57c6a7dc382361520ab34c6d428b881.tar.gz miasm-6f7fbfb8b57c6a7dc382361520ab34c6d428b881.zip | |
AsmBlock: constant for asmblockbad errno
Diffstat (limited to 'miasm2/core/asmblock.py')
| -rw-r--r-- | miasm2/core/asmblock.py | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/miasm2/core/asmblock.py b/miasm2/core/asmblock.py index 8740aeb7..f763d85f 100644 --- a/miasm2/core/asmblock.py +++ b/miasm2/core/asmblock.py @@ -297,13 +297,23 @@ class AsmBlockBad(AsmBlock): """Stand for a *bad* ASM block (malformed, unreachable, not disassembled, ...)""" - ERROR_TYPES = {-1: "Unknown error", - 0: "Unable to disassemble", - 1: "Null starting block", - 2: "Address forbidden by dont_dis", - } - def __init__(self, label=None, alignment=1, errno=-1, *args, **kwargs): + ERROR_UNKNOWN = -1 + ERROR_CANNOT_DISASM = 0 + ERROR_NULL_STARTING_BLOCK = 1 + ERROR_FORBIDDEN = 2 + ERROR_IO = 3 + + + ERROR_TYPES = { + ERROR_UNKNOWN: "Unknown error", + ERROR_CANNOT_DISASM: "Unable to disassemble", + ERROR_NULL_STARTING_BLOCK: "Null starting block", + ERROR_FORBIDDEN: "Address forbidden by dont_dis", + ERROR_IO: "IOError", + } + + def __init__(self, label=None, alignment=1, errno=ERROR_UNKNOWN, *args, **kwargs): """Instanciate an AsmBlock_bad. @label, @alignement: same as AsmBlock.__init__ @errno: (optional) specify a error type associated with the block @@ -311,6 +321,8 @@ class AsmBlockBad(AsmBlock): super(AsmBlockBad, self).__init__(label, alignment, *args, **kwargs) self._errno = errno + errno = property(lambda self: self._errno) + def __str__(self): error_txt = self.ERROR_TYPES.get(self._errno, self._errno) return "\n".join([str(self.label), @@ -1450,7 +1462,7 @@ class disasmEngine(object): if not cur_block.lines: job_done.add(offset) # Block is empty -> bad block - cur_block = AsmBlockBad(label, errno=2) + cur_block = AsmBlockBad(label, errno=AsmBlockBad.ERROR_FORBIDDEN) else: # Block is not empty, stop the desassembly pass and add a # constraint to the next block @@ -1475,18 +1487,25 @@ class disasmEngine(object): break off_i = offset + error = None try: instr = self.arch.dis(self.bin_stream, self.attrib, offset) - except (Disasm_Exception, IOError), e: + except Disasm_Exception as e: + log_asmblock.warning(e) + instr = None + error = AsmBlockBad.ERROR_CANNOT_DISASM + except IOError as e: log_asmblock.warning(e) instr = None + error = AsmBlockBad.ERROR_IO + if instr is None: log_asmblock.warning("cannot disasm at %X", int(off_i)) if not cur_block.lines: job_done.add(offset) # Block is empty -> bad block - cur_block = AsmBlockBad(label, errno=0) + cur_block = AsmBlockBad(label, errno=error) else: # Block is not empty, stop the desassembly pass and add a # constraint to the next block @@ -1499,7 +1518,7 @@ class disasmEngine(object): log_asmblock.warning("reach nul instr at %X", int(off_i)) if not cur_block.lines: # Block is empty -> bad block - cur_block = AsmBlockBad(label, errno=1) + cur_block = AsmBlockBad(label, errno=AsmBlockBad.ERROR_NULL_STARTING_BLOCK) else: # Block is not empty, stop the desassembly pass and add a # constraint to the next block |