45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
|
from sqlalchemy import create_engine, Column, Integer, String, LargeBinary
|
||
|
from sqlalchemy.ext.declarative import declarative_base
|
||
|
from sqlalchemy.orm import Session
|
||
|
from pathlib import Path
|
||
|
import json
|
||
|
|
||
|
from .disassemble import _CapstoneBase
|
||
|
|
||
|
Base = declarative_base()
|
||
|
|
||
|
|
||
|
def db_config(path: Path) -> Session:
|
||
|
engine = create_engine(f"sqlite:///{path.resolve()}", native_datetime=True)
|
||
|
Base.metadata.create_all(engine)
|
||
|
session = Session(engine)
|
||
|
return session
|
||
|
|
||
|
|
||
|
class Disassembly(Base):
|
||
|
__tablename__ = "Disassembly"
|
||
|
id = Column(Integer, primary_key=True)
|
||
|
arch = Column(String, nullable=False)
|
||
|
checksum = Column(String, nullable=False)
|
||
|
count = Column(Integer, nullable=False)
|
||
|
size = Column(Integer, nullable=False)
|
||
|
offset = Column(Integer, nullable=False)
|
||
|
opcodes = Column(String, nullable=False)
|
||
|
path = Column(String, nullable=False)
|
||
|
|
||
|
def __repr__(self):
|
||
|
return f"<Disassembly {json.dumps(self.values, indent=1)}>"
|
||
|
|
||
|
@property
|
||
|
def values(self) -> dict:
|
||
|
values_dict = {
|
||
|
"arch": self.arch,
|
||
|
"checksum": self.checksum,
|
||
|
"count": self.count,
|
||
|
"size": self.size,
|
||
|
"offset": self.offset,
|
||
|
"path": self.path,
|
||
|
}
|
||
|
|
||
|
return values_dict
|