results sorting

master
JoYo 2022-01-20 12:24:33 -05:00
parent 197aff4402
commit 8640a29b3b
3 changed files with 21 additions and 7 deletions

View File

@ -49,6 +49,9 @@ class _CapstoneBase:
def __len__(self) -> int: def __len__(self) -> int:
return len(self.disassembly) return len(self.disassembly)
def __lt__(self, other):
return len(self) < len(other)
@property @property
def objdump(self) -> str: def objdump(self) -> str:
opcodes = str() opcodes = str()

View File

@ -28,6 +28,12 @@ class Disassembly(Base):
def __repr__(self): def __repr__(self):
return f"<Disassembly {json.dumps(self.values, indent=1)}>" return f"<Disassembly {json.dumps(self.values, indent=1)}>"
def __len__(self) -> int:
return self.count
def __lt__(self, other):
return len(self) < len(other)
@property @property
def values(self) -> dict: def values(self) -> dict:
values_dict = { values_dict = {

View File

@ -116,13 +116,18 @@ def subdisassem_script():
session.commit() session.commit()
count = session.query(Disassembly).order_by(desc("count")).first() tops = list()
tops = (
for arch in archs:
top = (
session.query(Disassembly) session.query(Disassembly)
.filter(Disassembly.count == count.count) .filter(Disassembly.arch == arch.__name__)
.order_by(desc("size")) .order_by(desc("count"))
.all() .first()
) )
tops.append(top)
tops = sorted(tops, key=len, reverse=True)
for top in tops[:3]: for top in tops[:3]:
logging.info(top) logging.info(top)