mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-01-23 09:16:20 -08:00
find functions based on first few similar bytes
This commit is contained in:
parent
7fd15ecfb4
commit
8add342a85
@ -100,7 +100,8 @@ class BinaryBlob(object):
|
|||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
self.parse_from_red()
|
self.parse_from_red()
|
||||||
self.find_in_crystal()
|
# self.find_in_crystal()
|
||||||
|
self.find_by_first_bytes()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
""" A beautiful poem.
|
""" A beautiful poem.
|
||||||
@ -113,6 +114,8 @@ class BinaryBlob(object):
|
|||||||
locnum = len(self.locations)
|
locnum = len(self.locations)
|
||||||
if locnum == 1:
|
if locnum == 1:
|
||||||
r += "located="+hex(self.locations[0])
|
r += "located="+hex(self.locations[0])
|
||||||
|
elif locnum <= 5:
|
||||||
|
r += "located="+str([hex(x) for x in self.locations])
|
||||||
else:
|
else:
|
||||||
r += "located="+str(locnum)
|
r += "located="+str(locnum)
|
||||||
r += ")"
|
r += ")"
|
||||||
@ -151,6 +154,29 @@ class BinaryBlob(object):
|
|||||||
if self.debug:
|
if self.debug:
|
||||||
print self.label + ": found " + str(len(self.locations)) + " matches."
|
print self.label + ": found " + str(len(self.locations)) + " matches."
|
||||||
|
|
||||||
|
def find_by_first_bytes(self):
|
||||||
|
""" Finds this blob in Crystal based on the first n bytes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# how many bytes to match
|
||||||
|
first_n = 3
|
||||||
|
|
||||||
|
# no match
|
||||||
|
if len(self.bytes) <= first_n:
|
||||||
|
return
|
||||||
|
|
||||||
|
finditer = findall_iter(self.bytes[0:first_n], cryrom)
|
||||||
|
self.locations = [match for match in finditer]
|
||||||
|
|
||||||
|
# filter out locations that suck
|
||||||
|
self.locations = [i for i in self.locations if abs(self.start_address - i) <= 0x8000]
|
||||||
|
|
||||||
|
if len(self.locations) > 0:
|
||||||
|
found_blobs.append(self)
|
||||||
|
|
||||||
|
if self.debug:
|
||||||
|
print self.label + ": found " + str(len(self.locations)) + " matches."
|
||||||
|
|
||||||
pokecrystal_rom_path = "../baserom.gbc"
|
pokecrystal_rom_path = "../baserom.gbc"
|
||||||
pokecrystal_src_path = "../main.asm"
|
pokecrystal_src_path = "../main.asm"
|
||||||
pokered_rom_path = "../pokered-baserom.gbc"
|
pokered_rom_path = "../pokered-baserom.gbc"
|
||||||
@ -191,7 +217,7 @@ def scan_red_asm(bank_stop=3, debug=True):
|
|||||||
print "scan_red_asm: switching to bank " + str(current_bank)
|
print "scan_red_asm: switching to bank " + str(current_bank)
|
||||||
|
|
||||||
elif line[0:6] != "INCBIN":
|
elif line[0:6] != "INCBIN":
|
||||||
if ":" in line:
|
if ":" in line and not ";XXX:" in line and not " ; XXX:" in line:
|
||||||
current_label = get_label_from_line(line)
|
current_label = get_label_from_line(line)
|
||||||
current_start_address = get_address_from_line_comment(line, \
|
current_start_address = get_address_from_line_comment(line, \
|
||||||
bank=current_bank)
|
bank=current_bank)
|
||||||
@ -222,7 +248,7 @@ def scan_red_asm(bank_stop=3, debug=True):
|
|||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
scan_red_asm()
|
scan_red_asm(bank_stop=3)
|
||||||
|
|
||||||
print "================================"
|
print "================================"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user