diff options
| author | Kyle Martin <krm504@nyu.edu> | 2019-05-30 19:23:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-30 19:23:06 -0400 |
| commit | 9b4ab06dfce606a23af9077856cf222b244e15ea (patch) | |
| tree | ded75f3d93d1158625d27e84e32df6b3a17c8ec1 /python | |
| parent | 4f13add7774cb0d5b97f1eccbfaaab07a647e5be (diff) | |
| parent | a0cf5857956a2ec64a9be62f1283e4f65b3f2bd1 (diff) | |
Merge pull request #1346 from joshwatson/fix-architecture-hook-assemble
Fix Architecture.assemble so that it works with ArchitectureHooks
Diffstat (limited to 'python')
| -rw-r--r-- | python/architecture.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/python/architecture.py b/python/architecture.py index 2d81beb0..e0ccfeeb 100644 --- a/python/architecture.py +++ b/python/architecture.py @@ -1056,15 +1056,23 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)): log.log_error(traceback.format_exc()) def _assemble(self, ctxt, code, addr, result, errors): + """ + This function calls the `assemble` command for the actual architecture plugin. + If the plugin does not provide an `assemble(self, code, addr)`-style function, + it uses the default function provided in CoreArchitecture. + """ try: - data, error_str = self.assemble(code, addr) - errors[0] = core.BNAllocString(str(error_str)) + data = self.assemble(code, addr) if data is None: return False buf = ctypes.create_string_buffer(len(data)) ctypes.memmove(buf, data, len(data)) core.BNSetDataBufferContents(result, buf, len(data)) return True + except ValueError as e: # Overriden `assemble` functions should raise a ValueError if the input was invalid (with a reasonable error message) + log.log_error(traceback.format_exc()) + errors[0] = core.BNAllocString(str(e)) + return False except: log.log_error(traceback.format_exc()) errors[0] = core.BNAllocString("Unhandled exception during assembly.\n") @@ -1272,7 +1280,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)): :return: the bytes for the assembled instructions or error string :rtype: (a tuple of instructions and empty string) or (or None and error string) """ - return None, "Architecture does not implement an assembler.\n" + raise NotImplementedError("Architecture does not implement an assembler.\n") @abc.abstractmethod def perform_is_never_branch_patch_available(self, data, addr): @@ -1770,6 +1778,8 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)): .. note :: It is important that the assembler used accepts a syntax identical to the one emitted by the \ disassembler. This will prevent confusing the user. + If there is an error in the input assembly, this function should raise a ValueError (with a reasonable error message). + :param str code: string representation of the instructions to be assembled :param int addr: virtual address that the instructions will be loaded at :return: the bytes for the assembled instructions |
