Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from json import dump,load
- from struct import pack as compile_bytes, unpack, calcsize as struct_size
- class RomStructure:
- format = "<"
- fields = "".split()
- def __init__(self,data):
- self.data=data
- def compile(self):
- return compile_bytes(self.format,*map(self.data.get,self.fields))
- @classmethod
- def decompile(self,bytes):
- return dict(zip(self.fields,unpack(self.format,bytes)))
- @classmethod
- def load_from(self,source,location):
- return self.decompile(source[location:location+struct_size(self.format)])
- class MapMetaStructure(RomStructure):
- format = "<IIIIHHBBBBHBB"
- fields =("map_data event_data map_scripts connection_header music index label "
- +"flash_thing weather type show_label battle_type").split()
- class MapConnectionStructure:
- format = "<IIBBH"
- fields = "type offset bank number filler".split()
- class MapConnectionHeader:
- format = "<II"
- fields = "size location".split()
- if __name__=="__main__":
- get_offset = lambda ptr:ptr&0x00FFFFFF
- from sys import argv;argv=argv[1:]
- from pprint import pprint
- i,end = 0,len(argv)
- while i<end:
- arg,i = argv[i],i+1
- if arg[arg.rfind("."):]==".gba":#found the Rom
- try: bytes = open(arg,'rb').read()#read the bytess
- except: raise
- else:
- while i<end:
- arg,i = argv[i],i+1
- try:offset = get_offset(int(arg,16))
- except:raise
- else:
- data=MapMetaStructure.load_from(bytes,offset)
- print("Map@",hex(offset))
- for key,value in data.items():
- if(isinstance(value,int)):print(key,hex(value))
- else:print(key,value)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement