i forgot i could get name from class rather than object

master
JoYo 2022-01-19 13:51:39 -05:00
parent 5600f94ba7
commit 197aff4402
2 changed files with 10 additions and 32 deletions

View File

@ -30,23 +30,8 @@ import logging
class _CapstoneBase: class _CapstoneBase:
def __init__(self): def __init__(self, payload: bytes, offset: int = 0):
self.arch = self.__class__.__name__ 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() disassembly = list()
for opcode in self.capstone.disasm(payload, offset): for opcode in self.capstone.disasm(payload, offset):
@ -58,14 +43,14 @@ class _CapstoneBase:
logging.debug("disassembly_empty") logging.debug("disassembly_empty")
self.disassembly = list() self.disassembly = list()
def __repr__(self) -> str:
return self.objdump
def __len__(self) -> int:
return len(self.disassembly)
@property @property
def objdump(self) -> str: def objdump(self) -> str:
if not self.disassembly:
logging.debug(
f"payload_missing: use {self.__class__}.load(payload=bytes) prior"
)
return ""
opcodes = str() opcodes = str()
for opcode in self.disassembly: for opcode in self.disassembly:
@ -75,12 +60,6 @@ class _CapstoneBase:
@property @property
def disasm(self) -> list: def disasm(self) -> list:
if not self.disassembly:
logging.debug(
f"payload_missing: use {self.__class__}.load(payload=bytes) prior"
)
return []
opcodes = list() opcodes = list()
for opcode in self.disassembly: for opcode in self.disassembly:

View File

@ -89,22 +89,21 @@ def subdisassem_script():
for arch in archs: for arch in archs:
for offset in range(args.fuzz): for offset in range(args.fuzz):
disasembler = arch()
exists = ( exists = (
session.query(Disassembly) session.query(Disassembly)
.filter(Disassembly.checksum == checksum) .filter(Disassembly.checksum == checksum)
.filter(Disassembly.offset == offset) .filter(Disassembly.offset == offset)
.filter(Disassembly.arch == disasembler.arch) .filter(Disassembly.arch == arch.__name__)
.first() .first()
) )
if exists: if exists:
logging.debug( logging.debug(
f"subdiassembly_exists: {[disasembler.arch, checksum, offset]}" f"subdiassembly_exists: {[arch.__name__, checksum, offset]}"
) )
continue continue
disasembler.load(payload=raw_bytes, offset=offset) disasembler = arch(payload=raw_bytes, offset=offset)
row = Disassembly() row = Disassembly()
row.arch = disasembler.arch row.arch = disasembler.arch
row.checksum = checksum row.checksum = checksum