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