mirror of
https://github.com/grp/Wii.py.git
synced 2025-06-18 14:55:35 -04:00
fucking IMET bugs, but fixes too!
This commit is contained in:
parent
4ae54ed51b
commit
3512fb6535
19
U8.py
19
U8.py
@ -41,8 +41,8 @@ class U8():
|
||||
self.data_offset = recursion
|
||||
recursion += 1
|
||||
files = sorted(os.listdir(file))
|
||||
if(sorted(files) == ["banner.bin", "icon.bin", "sound.bin"]):
|
||||
files = ["icon.bin", "banner.bin", "sound.bin"]
|
||||
#if(sorted(files) == ["banner.bin", "icon.bin", "sound.bin"]):
|
||||
# files = ["icon.bin", "banner.bin", "sound.bin"]
|
||||
|
||||
oldsz = len(self.nodes)
|
||||
if(is_root != 1):
|
||||
@ -290,14 +290,14 @@ class IMET():
|
||||
class IMETHeader(Struct):
|
||||
__endian__ = Struct.BE
|
||||
def __format__(self):
|
||||
self.zeroes = Struct.uint8[64]
|
||||
self.zeroes = Struct.uint8[128]
|
||||
self.tag = Struct.string(4)
|
||||
self.unk = Struct.uint64
|
||||
self.sizes = Struct.uint32[3] #icon, banner, sound
|
||||
self.flag1 = Struct.uint32
|
||||
self.names = Struct.string(0x2A << 1, encoding = 'utf_16_be', stripNulls = True)[7]
|
||||
self.unk2 = Struct.uint32
|
||||
self.names = Struct.string(84, encoding = "utf-16-be", stripNulls = True)[7]
|
||||
self.zeroes2 = Struct.uint8[904]
|
||||
self.crypto = Struct.string(16)
|
||||
self.hash = Struct.string(16)
|
||||
def __init__(self, f):
|
||||
self.f = f
|
||||
def add(self, iconsz, bannersz, soundsz, name = "", langs = [], fn = ""):
|
||||
@ -312,6 +312,7 @@ class IMET():
|
||||
imet.sizes[0] = iconsz
|
||||
imet.sizes[1] = bannersz
|
||||
imet.sizes[2] = soundsz
|
||||
imet.unk2 = 0
|
||||
for i in range(len(imet.names)):
|
||||
if(len(langs) > 0 and langs[i] != ""):
|
||||
imet.names[i] = langs[i]
|
||||
@ -319,9 +320,11 @@ class IMET():
|
||||
imet.names[i] = name
|
||||
for i in imet.zeroes2:
|
||||
imet.zeroes2[i] = 0x00
|
||||
imet.crypto = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
imet.hash = "\x00" * 16
|
||||
|
||||
tmp = imet.pack()
|
||||
imet.crypto = str(hashlib.md5(tmp[0x40:0x600]).digest())
|
||||
imet.hash = hashlib.md5(tmp[0x40:0x640]).digest() #0x00 or 0x40?
|
||||
|
||||
data = imet.pack() + data
|
||||
|
||||
if(fn != ""):
|
||||
|
28
common.py
28
common.py
@ -17,42 +17,34 @@ class Crypto:
|
||||
def __init__(self):
|
||||
self.align = 64
|
||||
return
|
||||
def DecryptData(self, key, iv, data):
|
||||
def DecryptData(self, key, iv, data, align = True):
|
||||
"""Decrypts some data (aligns to 64 bytes, if needed)."""
|
||||
if((len(data) % self.align) != 0):
|
||||
if((len(data) % self.align) != 0 and align):
|
||||
return AES.new(key, AES.MODE_CBC, iv).decrypt(data + ("\x00" * (self.align - (len(data) % self.align))))
|
||||
else:
|
||||
return AES.new(key, AES.MODE_CBC, iv).decrypt(data)
|
||||
def EncryptData(self, key, iv, data):
|
||||
def EncryptData(self, key, iv, data, align = True):
|
||||
"""Encrypts some data (aligns to 64 bytes, if needed)."""
|
||||
if((len(data) % self.align) != 0):
|
||||
if((len(data) % self.align) != 0 and align):
|
||||
return AES.new(key, AES.MODE_CBC, iv).encrypt(data + ("\x00" * (self.align - (len(data) % self.align))))
|
||||
else:
|
||||
return AES.new(key, AES.MODE_CBC, iv).encrypt(data)
|
||||
def DecryptContent(self, titlekey, idx, data):
|
||||
"""Decrypts a Content."""
|
||||
iv = struct.pack(">H", idx) + "\x00" * 14
|
||||
self.DecryptData(titlekey, iv, data)
|
||||
return self.DecryptData(titlekey, iv, data)
|
||||
def DecryptTitleKey(self, commonkey, tid, enckey):
|
||||
"""Decrypts a Content."""
|
||||
iv = struct.pack(">Q", tid) + "\x00" * 8
|
||||
self.DecryptData(commonkey, iv, enckey)
|
||||
return self.DecryptData(commonkey, iv, enckey, False)
|
||||
def EncryptContent(self, titlekey, idx, data):
|
||||
"""Encrypts a Content."""
|
||||
iv = struct.pack(">H", idx) + "\x00" * 14
|
||||
self.EncryptData(titlekey, iv, data)
|
||||
def CreateSHAHash(self, data):
|
||||
if((len(data) % self.align) != 0):
|
||||
datax = data + ("\x00" * (self.align - (len(data) % align)))
|
||||
else:
|
||||
datax = data
|
||||
return hashlib.sha1(datax).digest()
|
||||
return self.EncryptData(titlekey, iv, data)
|
||||
def CreateSHAHash(self, data): #tested WORKING (without padding)
|
||||
return hashlib.sha1(data).digest()
|
||||
def CreateSHAHashHex(self, data):
|
||||
if((len(data) % self.align) != 0):
|
||||
datax = data + ("\x00" * (self.align - (len(data) % align)))
|
||||
else:
|
||||
datax = data
|
||||
return hashlib.sha1(datax).hexdigest()
|
||||
return hashlib.sha1(data).hexdigest()
|
||||
def CreateMD5HashHex(self, data):
|
||||
return hashlib.md5(data).hexdigest()
|
||||
def CreateMD5Hash(self, data):
|
||||
|
Loading…
Reference in New Issue
Block a user