Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start = 0x2100D4
- def is_jis_char(s):
- '''test passed string: true if two bytes that decode to one SJIS char'''
- if len(s) != 2:
- return False
- try:
- if len(s.decode('cp932')) == 1:
- return True
- except UnicodeDecodeError:
- return False
- with open('NPJH50119.BIN', 'rb') as f:
- f.seek(0x2100d4) #Read in our .data block
- filedata = f.read(0x1a2250)
- slist = []
- output = []
- decode_fail = []
- pos = 0
- count = 0
- while pos < len(filedata):
- if (filedata[pos] > 0x1F and filedata[pos] < 0x80) or ( #ASCII char
- filedata[pos] == 0xA) or ( #Newline char
- is_jis_char(filedata[pos:pos+2])): #SJIS char
- count += 1
- end = filedata.find(b'\x00', pos)
- try: #Test decode
- s = filedata[pos:end].decode('cp932')
- except UnicodeDecodeError:
- decode_fail.append(hex(pos + start))
- pos = end
- pos += 4 - pos % 4 #Word-align pointer
- continue #Search for next string
- output.append((hex(pos + start), s)) #Save string and position
- pos = end
- pos += 4 - pos % 4 #Word-align pointer
- with open('o.txt', 'w', encoding='utf-8') as f:
- f.write('\n'.join([a + '\t' + b.replace('\n', '\n\t') for a, b in output]))
- with open('f.txt', 'w') as f:
- f.write('\n'.join(decode_fail))
Add Comment
Please, Sign In to add comment