Skip to content

Commit

Permalink
better err msg
Browse files Browse the repository at this point in the history
  • Loading branch information
DennyDai committed Dec 16, 2024
1 parent ee69c4e commit 693abd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/patcherex2/components/assemblers/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def __init__(self, p, arch: int, mode: int) -> None:
self.ks = keystone.Ks(arch, mode)

def _assemble(self, code: str, base=0, **kwargs) -> bytes:
binary, _ = self.ks.asm(code, base)
logger.debug(f"Assembled bytes: {bytes(binary)}")
return bytes(binary)
try:
binary, _ = self.ks.asm(code, base)
logger.debug(f"Assembled bytes: {bytes(binary)}")
return bytes(binary)
except Exception as e:
raise Exception(
f'Failed to assemble: """\n{code}\n"""\nat base: {hex(base)}'
) from e
13 changes: 9 additions & 4 deletions src/patcherex2/components/assemblers/keystone_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def __init__(self, p) -> None:
)

def _assemble(self, code: str, base=0, is_thumb=False) -> bytes:
ks = self.ks_thumb if is_thumb else self.ks_arm
binary, _ = ks.asm(code, base)
logger.debug(f"Assembled bytes: {bytes(binary)}")
return bytes(binary)
try:
ks = self.ks_thumb if is_thumb else self.ks_arm
binary, _ = ks.asm(code, base)
logger.debug(f"Assembled bytes: {bytes(binary)}")
return bytes(binary)
except Exception as e:
raise Exception(
f'Failed to assemble: """\n{code}\n"""\nat base: {hex(base)}'
) from e

0 comments on commit 693abd4

Please sign in to comment.