i forgot i could get name from class rather than object
parent
5600f94ba7
commit
197aff4402
|
@ -30,23 +30,8 @@ import logging
|
|||
|
||||
|
||||
class _CapstoneBase:
|
||||
def __init__(self):
|
||||
def __init__(self, payload: bytes, offset: int = 0):
|
||||
self.arch = self.__class__.__name__
|
||||
pass
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.objdump
|
||||
|
||||
def __len__(self) -> int:
|
||||
if not self.disassembly:
|
||||
logging.debug(
|
||||
f"payload_missing: use {self.__class__}.load(payload=bytes) prior"
|
||||
)
|
||||
return 0
|
||||
|
||||
return len(self.disassembly)
|
||||
|
||||
def load(self, payload: bytes, offset: int = 0):
|
||||
disassembly = list()
|
||||
|
||||
for opcode in self.capstone.disasm(payload, offset):
|
||||
|
@ -58,14 +43,14 @@ class _CapstoneBase:
|
|||
logging.debug("disassembly_empty")
|
||||
self.disassembly = list()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.objdump
|
||||
|
||||
def __len__(self) -> int:
|
||||
return len(self.disassembly)
|
||||
|
||||
@property
|
||||
def objdump(self) -> str:
|
||||
if not self.disassembly:
|
||||
logging.debug(
|
||||
f"payload_missing: use {self.__class__}.load(payload=bytes) prior"
|
||||
)
|
||||
return ""
|
||||
|
||||
opcodes = str()
|
||||
|
||||
for opcode in self.disassembly:
|
||||
|
@ -75,12 +60,6 @@ class _CapstoneBase:
|
|||
|
||||
@property
|
||||
def disasm(self) -> list:
|
||||
if not self.disassembly:
|
||||
logging.debug(
|
||||
f"payload_missing: use {self.__class__}.load(payload=bytes) prior"
|
||||
)
|
||||
return []
|
||||
|
||||
opcodes = list()
|
||||
|
||||
for opcode in self.disassembly:
|
||||
|
|
|
@ -89,22 +89,21 @@ def subdisassem_script():
|
|||
|
||||
for arch in archs:
|
||||
for offset in range(args.fuzz):
|
||||
disasembler = arch()
|
||||
exists = (
|
||||
session.query(Disassembly)
|
||||
.filter(Disassembly.checksum == checksum)
|
||||
.filter(Disassembly.offset == offset)
|
||||
.filter(Disassembly.arch == disasembler.arch)
|
||||
.filter(Disassembly.arch == arch.__name__)
|
||||
.first()
|
||||
)
|
||||
|
||||
if exists:
|
||||
logging.debug(
|
||||
f"subdiassembly_exists: {[disasembler.arch, checksum, offset]}"
|
||||
f"subdiassembly_exists: {[arch.__name__, checksum, offset]}"
|
||||
)
|
||||
continue
|
||||
|
||||
disasembler.load(payload=raw_bytes, offset=offset)
|
||||
disasembler = arch(payload=raw_bytes, offset=offset)
|
||||
row = Disassembly()
|
||||
row.arch = disasembler.arch
|
||||
row.checksum = checksum
|
||||
|
|
Loading…
Reference in New Issue