Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SPINBALL text extractor
- # notes:
- # PEA (label).l | 0x4879 label
- # User
- Rom_File = "Sonic Spinball (U) [!].bin"
- Tag_File = "str_list.txt"
- # Variables
- TAG_PEA = 0x4879
- # subs
- def add_tag(got_pos):
- global SRCH_STR
- # String found, add to database
- output_file.write(str(got_pos)) # read address
- output_file.write(str("|")) # separator
- output_file.write(str(SRCH_STR)) # string data
- output_file.write(str("|")) # separator
- input_file.seek(SRCH_STR) #copy string (needs to check for 0xFF align)
- d = True
- output_file.write(chr(0x22)) # "
- while d:
- a = input_file.read(1).decode("ascii")
- input_file.seek(-1,1)
- b = ord(input_file.read(1))
- if b != 0:
- output_file.write(str(a))
- else:
- SRCH_STR = input_file.tell()
- a = ord(input_file.read(1))
- if a == 0xFF:
- SRCH_STR = input_file.tell()
- d = False
- output_file.write(chr(0x22)) # "
- output_file.write("\n")
- input_file = open(Rom_File,"rb")
- output_file = open(Tag_File,"w")
- # *********************************************
- # Start
- # *********************************************
- got_text = 1
- # *** First pass ***
- print("FIRST PASS")
- SRCH_STR = 0xBE248
- NUMOF_STR = 293
- wrk = NUMOF_STR
- curr_pos = 0
- while wrk:
- # DIRECT SEARCH
- input_file.seek(curr_pos)
- a = (ord(input_file.read(1))&0xFF) << 24
- b = (ord(input_file.read(1))&0xFF) << 16
- c = (ord(input_file.read(1))&0xFF) << 8
- d = ord(input_file.read(1))&0xFF
- e = a|b|c|d
- curr_pos += 2 # <-- word align
- if e == SRCH_STR:
- wrk -= 1
- got_pos = curr_pos-2
- print("Got text",got_text,"of",NUMOF_STR,":",hex(got_pos))
- add_tag(got_pos)
- #print("Next:",hex(SRCH_STR))
- curr_pos = 0
- got_text += 1
- # *** Second pass ***
- print("SECOND PASS")
- SRCH_STR = 0xC14B0
- NUMOF_STR = 5
- wrk = NUMOF_STR
- curr_pos = 0
- while wrk:
- # DIRECT SEARCH
- input_file.seek(curr_pos)
- a = (ord(input_file.read(1))&0xFF) << 24
- b = (ord(input_file.read(1))&0xFF) << 16
- c = (ord(input_file.read(1))&0xFF) << 8
- d = ord(input_file.read(1))&0xFF
- e = a|b|c|d
- curr_pos += 2 # <-- word align
- if e == SRCH_STR:
- wrk -= 1
- got_pos = curr_pos-2
- print("Got text",got_text,"of",NUMOF_STR,":",hex(got_pos))
- add_tag(got_pos)
- #print("Next:",hex(SRCH_STR))
- curr_pos = 0
- got_text += 1
- # PEA SEARCH
- #input_file.seek(curr_pos)
- #b = (ord(input_file.read(1))&0xFF) << 8
- #a = ord(input_file.read(1))&0xFF
- #c = a|b
- #if c == TAG_PEA:
- #a = (ord(input_file.read(1))&0xFF) << 24
- #b = (ord(input_file.read(1))&0xFF) << 16
- #c = (ord(input_file.read(1))&0xFF) << 8
- #d = ord(input_file.read(1))&0xFF
- #e = a|b|c|d
- #if e == SRCH_STR:
- #wrk -= 1
- #got_pos = curr_pos+1
- #print("FOUND AT:",hex(got_pos))
- #add_tag(got_pos)
Add Comment
Please, Sign In to add comment