Guest User

RTT2 EBOOT Dump

a guest
Sep 24th, 2016
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. start = 0x2100D4
  2.  
  3. def is_jis_char(s):
  4.     '''test passed string: true if two bytes that decode to one SJIS char'''
  5.     if len(s) != 2:
  6.         return False
  7.     try:
  8.         if len(s.decode('cp932')) == 1:
  9.             return True
  10.     except UnicodeDecodeError:
  11.         return False
  12.    
  13. with open('NPJH50119.BIN', 'rb') as f:
  14.     f.seek(0x2100d4)                #Read in our .data block
  15.     filedata = f.read(0x1a2250)
  16. slist = []
  17. output = []
  18. decode_fail = []
  19. pos = 0
  20. count = 0
  21. while pos < len(filedata):
  22.     if (filedata[pos] > 0x1F and filedata[pos] < 0x80) or (     #ASCII char
  23.         filedata[pos] == 0xA) or (                              #Newline char
  24.         is_jis_char(filedata[pos:pos+2])):                      #SJIS char
  25.         count += 1
  26.         end = filedata.find(b'\x00', pos)
  27.         try:                                        #Test decode
  28.             s = filedata[pos:end].decode('cp932')
  29.         except UnicodeDecodeError:
  30.             decode_fail.append(hex(pos + start))
  31.             pos = end
  32.             pos += 4 - pos % 4                      #Word-align pointer
  33.             continue                                #Search for next string
  34.         output.append((hex(pos + start), s))        #Save string and position
  35.         pos = end
  36.     pos += 4 - pos % 4                              #Word-align pointer
  37. with open('o.txt', 'w', encoding='utf-8') as f:
  38.     f.write('\n'.join([a + '\t' + b.replace('\n', '\n\t') for a, b in output]))
  39. with open('f.txt', 'w') as f:
  40.     f.write('\n'.join(decode_fail))
RAW Paste Data