lazy linear for rizin objdump
parent
d656d97818
commit
fbb437a809
|
@ -42,7 +42,7 @@ class _CapstoneBase:
|
|||
if disassembly:
|
||||
self.disassembly = disassembly
|
||||
else:
|
||||
logging.debug("disassembly_empty")
|
||||
logging.warning("disassembly_empty")
|
||||
self.disassembly = list()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
|
|
@ -5,16 +5,35 @@ import json
|
|||
|
||||
|
||||
class _RizinBase:
|
||||
def __init__(self, path: Path):
|
||||
def __init__(self, path: Path, offset: int = 0):
|
||||
rz_pipe = rzpipe.open(str(path.absolute()))
|
||||
|
||||
for cmd in self.arch_cmds:
|
||||
rz_pipe.cmd(cmd)
|
||||
|
||||
rz_pipe.cmd("aa")
|
||||
disassembly = list()
|
||||
|
||||
while offset < path.stat().st_size:
|
||||
result = rz_pipe.cmd(f"s {offset}")
|
||||
result = rz_pipe.cmd("pdj")
|
||||
result = json.loads(result)
|
||||
|
||||
for each in result:
|
||||
new_offset = int(each.get("offset"))
|
||||
|
||||
if offset >= new_offset:
|
||||
break
|
||||
|
||||
offset = new_offset
|
||||
disassembly += result
|
||||
|
||||
rz_pipe.quit()
|
||||
self.disassembly = json.loads(result)
|
||||
|
||||
if disassembly:
|
||||
self.disassembly = disassembly
|
||||
else:
|
||||
logging.warning("disassembly_empty")
|
||||
self.disassembly = list()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.objdump
|
||||
|
@ -38,7 +57,8 @@ class _RizinBase:
|
|||
for each in self.disassembly:
|
||||
offset = each.get("offset")
|
||||
opcode = each.get("opcode")
|
||||
if opcode:
|
||||
|
||||
if not opcode in ["invalid", "nop", None]:
|
||||
_objdump += f"{offset:#02x}:\t{opcode}\n"
|
||||
|
||||
self._objdump = _objdump
|
||||
|
@ -55,7 +75,7 @@ class _RizinBase:
|
|||
offset = each.get("offset")
|
||||
opcode = each.get("opcode")
|
||||
|
||||
if opcode:
|
||||
if not opcode in ["invalid", "nop", None]:
|
||||
mnemonic = opcode.split(" ")[0]
|
||||
opcode = opcode.split(" ")[1:]
|
||||
_disasm.append([offset, mnemonic, opcode])
|
||||
|
@ -263,7 +283,7 @@ class hppa(_RizinBase):
|
|||
|
||||
|
||||
class i4004(_RizinBase):
|
||||
arch_cmds = ["e asm.arch=i4004", "e asm.bits=4"]
|
||||
arch_cmds = ["e asm.arch=i4004"]
|
||||
|
||||
|
||||
class i8080(_RizinBase):
|
||||
|
|
|
@ -233,7 +233,7 @@ def subdisassem_script():
|
|||
)
|
||||
continue
|
||||
|
||||
disasembler = arch(path=args.bin_path)
|
||||
disasembler = arch(path=args.bin_path, offset=offset)
|
||||
row = Disassembly()
|
||||
row.arch = disasembler.__class__.__name__
|
||||
row.checksum = checksum
|
||||
|
|
Loading…
Reference in New Issue