2021-03-17 15:53:31 +01:00
|
|
|
import os, sys, struct, hashlib
|
2016-11-23 06:35:12 +01:00
|
|
|
|
|
|
|
output, datafile, iconarc, bannerarc, soundbns, namesfile = sys.argv[1:]
|
|
|
|
|
2021-03-17 15:53:31 +01:00
|
|
|
data = open(datafile,"rb").read()
|
2016-11-23 06:35:12 +01:00
|
|
|
|
|
|
|
names={}
|
|
|
|
|
|
|
|
for i in open(namesfile,"r"):
|
|
|
|
a,b = i.split("=")
|
|
|
|
while b[-1] == "\n":
|
|
|
|
b = b[:-1]
|
|
|
|
b = b.replace("\\n","\n")
|
2021-03-17 15:53:31 +01:00
|
|
|
names[a] = b
|
2016-11-23 06:35:12 +01:00
|
|
|
|
|
|
|
def getsize(x):
|
|
|
|
return os.stat(x).st_size
|
|
|
|
|
|
|
|
def pad(x,l):
|
|
|
|
if len(x) > l:
|
|
|
|
raise ValueError("%d > %d",len(x),l)
|
|
|
|
n = l-len(x)
|
2021-03-17 15:53:31 +01:00
|
|
|
return x + b"\x00"*n
|
2016-11-23 06:35:12 +01:00
|
|
|
|
2021-03-17 15:53:31 +01:00
|
|
|
imet = b"\x00"*0x40
|
|
|
|
imet += struct.pack(">4sIIIIII",b"IMET",0x600,3,getsize(iconarc),getsize(bannerarc),getsize(soundbns),1)
|
2016-11-23 06:35:12 +01:00
|
|
|
|
|
|
|
for i in ["jp", "en", "de", "fr", "sp", "it", "nl", "cn", None, "ko"]:
|
|
|
|
try:
|
|
|
|
imet += pad(names[i].encode("UTF-16BE"),0x54)
|
|
|
|
except KeyError:
|
2021-03-17 15:53:31 +01:00
|
|
|
imet += b"\x00"*0x54
|
|
|
|
imet += b"\x00"*(0x600 - len(imet))
|
2016-11-23 06:35:12 +01:00
|
|
|
|
2021-03-17 15:53:31 +01:00
|
|
|
imet = imet[:-16] + hashlib.md5(imet).digest()
|
2016-11-23 06:35:12 +01:00
|
|
|
|
2021-03-17 15:53:31 +01:00
|
|
|
open(output,"wb").write(imet)
|
2016-11-23 06:35:12 +01:00
|
|
|
|
2021-03-17 15:53:31 +01:00
|
|
|
f = open(sys.argv[1],"wb")
|
2016-11-23 06:35:12 +01:00
|
|
|
f.write(imet)
|
|
|
|
f.write(data)
|
|
|
|
|
|
|
|
fsize = f.tell()
|
|
|
|
|
|
|
|
if (fsize % 20) != 0:
|
2021-03-17 15:53:31 +01:00
|
|
|
f.write(b"\x00"*(20-(fsize%20)))
|
2016-11-23 06:35:12 +01:00
|
|
|
|
|
|
|
f.close()
|