Created
November 22, 2016 18:21
-
-
Save wwylele/830f5046a0304c083e94d455bcda23a2 to your computer and use it in GitHub Desktop.
3DS config savegame parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3 | |
import struct | |
import sys | |
import os | |
if len(sys.argv)<2: | |
print("No input file") | |
exit() | |
flen=os.path.getsize(sys.argv[1]) | |
f=open(sys.argv[1], 'rb'); | |
block_count,data_offset=struct.unpack('HH',f.read(4)) | |
entries=[] | |
for i in range(block_count): | |
entries.append(struct.unpack('IIHH',f.read(12))) | |
entries.sort(key=lambda e:e[0]) | |
for e in entries: | |
print("****Entry[0x%08x] with flag 0x%04x, length 0x%08x"%(e[0],e[3],e[2])) | |
if e[2]<=4: | |
data=e[1].to_bytes(4, byteorder='little')[0:e[2]] | |
else: | |
f.seek(e[1],os.SEEK_SET) | |
data=f.read(e[2]) | |
for i in range(e[2]): | |
if i%16==15 and i!=e[2]-1: | |
ec="\n" | |
else: | |
ec="" | |
print("%02x "%data[i],end=ec) | |
print("\n") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment