Skip to content

Commit 1cff1db

Browse files
committed
Minor fixes in datalayer
1 parent 9a50fa0 commit 1cff1db

File tree

6 files changed

+51
-2
lines changed

6 files changed

+51
-2
lines changed

common/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
# User-defined exceptions
3+
class ApotheosisUnsupportedNodeObjectError(Exception):
4+
pass
5+
class ApotheosisUnsupportedDistanceAlgorithmError(Exception):
6+
pass
37
class ApotheosisUnmatchDistanceAlgorithmError(Exception):
48
pass
59
class ApotheosisIsEmptyError(Exception):

common/utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_DB_in_model(npages=0, nsearch_pages=None, algorithm=None, current_model
3636

3737
page_list = []
3838
insert_times = []
39-
for i, winmodule in enumerate(0, all_pages):
39+
for i, winmodule in enumerate(all_pages):
4040
if i % BATCH_PRINT == 0 and i != 0 and printlog:
4141
print(f"{int(i/BATCH_PRINT)}*{BATCH_PRINT} pages already inserted ({datetime.datetime.now()}) ...")
4242

datalayer/database/module.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ def __eq__(self, module):
2323
def __hash__(self):
2424
return hash(self.id)
2525

26+
def as_dict(self):
27+
return {
28+
"id": self.id,
29+
"file_version": self.file_version,
30+
"original_filename": self.original_filename,
31+
"internal_filename": self.internal_filename,
32+
"product_name": self.product_name,
33+
"company_name": self.company_name,
34+
"legal_copyright": self.legal_copyright,
35+
"classification": self.classification,
36+
"size": self.size,
37+
"base_address": self.base_address,
38+
"os": self.os.as_dict() if self.os else None
39+
}

datalayer/db_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_winmodules(self, algorithm: HashAlgorithm = TLSHHashAlgorithm, limit: in
131131
hash_column = "hashTLSH" if algorithm == TLSHHashAlgorithm else "hashSSDEEP"
132132
query = SQL_GET_ALL_PAGES.format(hash_column)
133133
if limit:
134-
query = SQL_GET_ALL_PAGES + f" LIMIT {limit}"
134+
query = query + f" LIMIT {limit}"
135135
self.cursor.execute(query)
136136
results = self.cursor.fetchall()
137137

datalayer/node/hash_node.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ def to_JSON(self):
4040

4141
def get_distance_algorithm(self):
4242
return self._hash_algorithm
43+
44+
def as_dict(self):
45+
return {
46+
"id": self._id,
47+
"hash_algorithm": self._hash_algorithm.__name__
48+
}
49+

datalayer/node/winmodule_hash_node.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ def get_draw_features(self):
2929
"module_version": {self._id: self._module.file_version},
3030
"os_version": {self._id: self._module.os.version}
3131
}
32+
33+
34+
def as_dict(self):
35+
node_dict = super().as_dict()
36+
if self._module:
37+
node_dict.update({
38+
"module_id": self._module.id,
39+
"file_version": self._module.file_version,
40+
"original_filename": self._module.original_filename,
41+
"internal_filename": self._module.internal_filename,
42+
"product_name": self._module.product_name,
43+
"company_name": self._module.company_name,
44+
"legal_copyright": self._module.legal_copyright,
45+
"classification": self._module.classification,
46+
"size": self._module.size,
47+
"base_address": self._module.base_address,
48+
})
49+
50+
if self._module.os:
51+
node_dict.update(self._module.os.as_dict())
52+
53+
return node_dict
54+
55+
3256

3357
def internal_serialize(self):
3458
return self.get_internal_page_id().to_bytes(I_SIZE, byteorder=BYTE_ORDER)

0 commit comments

Comments
 (0)