Created
October 22, 2013 14:17
-
-
Save ifree/7101525 to your computer and use it in GitHub Desktop.
small util get reading upk info
This file contains hidden or 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
# | |
# utils for get information of upk file | |
# http://wiki.beyondunreal.com/Legacy:Package_File_Format | |
DWORD = 4 | |
WORD = 2 | |
GUID = 16 | |
def endineFixWin(type,arr): | |
""" | |
this method may not correct due to different os's byte order | |
""" | |
if type == DWORD: | |
arr[0],arr[1],arr[2],arr[3]=arr[3],arr[2],arr[1],arr[0] | |
elif type==WORD: | |
arr[0],arr[1]=arr[1],arr[0] | |
return arr | |
UPKDef={ | |
"Signature": (0,DWORD), | |
"PackageVersion": (4,WORD), | |
"LicenseMode": (6,WORD), | |
"PackageFlags": (8,DWORD), | |
"NameCount": (12,DWORD), | |
"NameOffset": (16,DWORD), | |
"ExportCount": (20,DWORD), | |
"ExportOffset": (24,DWORD), | |
"ImportCount": (28,DWORD), | |
"ImportOffset": (32,DWORD), | |
"GUID": (36,GUID) | |
} | |
class UPK: | |
def __init__(self,f): | |
self.file=f | |
def readHeader(self,offset,count): | |
self.file.seek(offset) | |
return endineFixWin(count,bytearray(self.file.read(count))) | |
def __getitem__(self,name): | |
if name in UPKDef: | |
prop=UPKDef[name] | |
return self.readHeader(prop[0],prop[1]) | |
def isValid(self): | |
return str(self["Signature"]).encode('hex') == '9e2a83c1' | |
if __name__ == "__main__": | |
import sys,os | |
if len(sys.argv) < 2: | |
print "input file required" | |
elif not os.path.exists(sys.argv[1]): | |
print "invalid file path" | |
else: | |
file=open(sys.argv[1]) | |
upk=UPK(file) | |
print "is valid upk? ",upk.isValid() | |
for k in UPKDef.keys(): | |
print k,":",str(upk[k]).encode('hex') | |
file.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment