Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f = open('feria.lsr', 'rb')
- x = f.read()
- f.close()
- f = open('feria.txt', 'rb')
- y = f.read()
- f.close()
- s = x.split(b'\0')
- t = y.split(b'\r\n|\r\n')
- r = []
- c = 0
- offset = 0
- for l in s:
- try:
- # Decoding successful and result != '':
- # Encode new string instead
- decoded = l.decode('shift-jis')
- if len(decoded) < 1:
- raise None
- try:
- encoded = t[c].decode('utf-8').encode('shift-jis')
- offset += len(encoded)-len(l)
- r.append(encoded)
- except:
- print("Could not encode item %d (%s) as shift-jis" % (c, t[c]))
- c += 1
- except:
- r.append(l)
- print('Offset: %d' % offset)
- # Add the offset to known data pointers that point to data after strings
- # 0x30 up to (and excluding) 0x64 are 32-bit integers pointing to
- # locations after the strings.
- # 0x271 is a 32-bit integer containing the length of the strings.
- b = list(b'\0'.join(r))
- for i in list(range(0x30, 0x64, 4)) + [0x271]:
- v = b[i] | b[i+1]<<8 | b[i+2]<<16 | b[i+3]<<24
- v += offset
- b[i] = v & 0xff
- b[i+1] = (v & 0xff00) >> 8
- b[i+2] = (v & 0xff0000) >> 16
- b[i+3] = (v & 0xff000000) >> 24
- r = bytes(b)
- f = open('feria_injected.lsr', 'wb')
- f.write(r)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment