Code cleanup in binbase_find.py.

This commit is contained in:
Markus Birth 2020-05-08 17:22:38 +02:00
parent ce673398c9
commit 1648b00426
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A

View File

@ -2,7 +2,6 @@
# https://github.com/mncoppola/ws30/blob/master/basefind.py
import gc
import os
import re
import signal
@ -20,26 +19,6 @@ pattern = re.compile(regexp)
regexpc = bytes("[{}]{{1,}}".format(chars), "us-ascii")
patternc = re.compile(regexpc)
def high_scores(signal, frame):
print("\nTop 20 base address candidates:")
for score in sorted(scores, key=itemgetter(1), reverse=True)[:20]:
print("0x{:x}\t{:d}".format(*score))
sys.exit(0)
def get_pointers(filename):
table = {}
with open(filename, "rb") as f:
while True:
try:
value = struct.unpack("<L", f.read(4))[0]
try:
table[value] += 1
except KeyError:
table[value] = 1
except:
break
return table
def get_strings(filename, size):
table = set()
offset = 0
@ -65,6 +44,26 @@ def get_strings(filename, size):
offset += 1
return table
def get_pointers(filename):
table = {}
with open(filename, "rb") as f:
while True:
try:
value = struct.unpack("<L", f.read(4))[0]
try:
table[value] += 1
except KeyError:
table[value] = 1
except:
break
return table
def high_scores(signal, frame):
print("\nTop 20 base address candidates:")
for score in sorted(scores, key=itemgetter(1), reverse=True)[:20]:
print("0x{:x}\t{:d}".format(*score))
sys.exit(0)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
@ -87,7 +86,6 @@ if __name__ == "__main__":
ptr_table = get_pointers(args.infile)
print("Total pointers found: {:d}".format(len(ptr_table)))
gc.disable()
signal.signal(signal.SIGINT, high_scores)
for base in range(args.min_addr, args.max_addr, args.page_size):