Skip to content

Commit

Permalink
[Bug Fix] struct.unpack("L") varies in size
Browse files Browse the repository at this point in the history
Although python's documentation says otherwise, the "L" format stands
for long, and could be 4/8 bytes, depending on the compilation. Changed
it to use "I" (int) so the size will be 4 bytes fixed.

Fixes a bug reported in issue CheckPointSW#41.
  • Loading branch information
chkp-eyalit committed May 27, 2020
1 parent ac00dcf commit c1c6f45
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/thumbs_up/utils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, analyzer, feature_size, inner_offset, classifiers_start_offse
self._mixed_classifiers = {}
self._type_classifier = None
# seed the random generator
numpy.random.seed(seed=struct.unpack("L", ida_nalt.retrieve_input_file_md5()[:4])[0])
numpy.random.seed(seed=struct.unpack("I", ida_nalt.retrieve_input_file_md5()[:4])[0])

def isFuncStart(self, ea):
"""Check if the given effective address is the start of a known function.
Expand Down
2 changes: 1 addition & 1 deletion src/thumbs_up/utils/pattern_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def decide(self):
# Now check for a basic alignment rule
seen_eas = list(map(lambda x: x[0], self._records))
# Deterministic results per binary, but still random
random.seed(struct.unpack("L", ida_nalt.retrieve_input_file_md5()[:4])[0])
random.seed(struct.unpack("I", ida_nalt.retrieve_input_file_md5()[:4])[0])
while True:
# Check against two random candidates, and always make sure the representative isn't rare
measure_candidate = seen_eas[random.randint(0, len(seen_eas) - 1)]
Expand Down

0 comments on commit c1c6f45

Please sign in to comment.