mirror of
https://github.com/grp/Wii.py.git
synced 2025-06-18 23:05:48 -04:00
sorta started disc, now works as a "package" in multiple files
This commit is contained in:
parent
2ab32f4300
commit
b1f620ea01
BIN
Struct.pyc
Normal file
BIN
Struct.pyc
Normal file
Binary file not shown.
36
__init__.py
36
__init__.py
@ -1,29 +1,9 @@
|
|||||||
import os, hashlib, struct, subprocess, fnmatch, shutil, urllib, array
|
__all__ = []
|
||||||
import wx
|
|
||||||
from Crypto.Cipher import AES
|
|
||||||
import png
|
|
||||||
from Struct import Struct
|
|
||||||
|
|
||||||
__all__ = ['TPL', 'U8', 'compression', 'title', 'nand']
|
from common import *
|
||||||
|
from compression import *
|
||||||
def align(x, boundary):
|
from disc import *
|
||||||
return x + (x % boundary)
|
from nand import *
|
||||||
|
from title import *
|
||||||
class Crypto:
|
from TPL import *
|
||||||
"""This is a Cryptographic/hash class used to abstract away things (to make changes easier)"""
|
from U8 import *
|
||||||
def __init__(self):
|
|
||||||
return
|
|
||||||
def DecryptContent(self, titlekey, idx, data):
|
|
||||||
"""Decrypts a Content."""
|
|
||||||
iv = struct.pack(">H", idx) + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
|
||||||
if(len(data) % 16 != 0):
|
|
||||||
return AES.new(titlekey, AES.MODE_CBC, iv).decrypt(data + ("\x00" * (16 - (len(data) % 16))))[:len(data)]
|
|
||||||
else:
|
|
||||||
return AES.new(titlekey, AES.MODE_CBC, iv).decrypt(data)
|
|
||||||
def ValidateHash(self, data, hash):
|
|
||||||
"""Validates a hash. (BROKEN)"""
|
|
||||||
return 1 #hack
|
|
||||||
# if(hashlib.sha1(data).digest() == hash):
|
|
||||||
# return 1
|
|
||||||
# else:
|
|
||||||
# return 0
|
|
BIN
__init__.pyc
Normal file
BIN
__init__.pyc
Normal file
Binary file not shown.
28
common.py
Normal file
28
common.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import os, hashlib, struct, subprocess, fnmatch, shutil, urllib, array
|
||||||
|
import wx
|
||||||
|
from Crypto.Cipher import AES
|
||||||
|
import png
|
||||||
|
from Struct import Struct
|
||||||
|
|
||||||
|
def align(x, boundary):
|
||||||
|
return x + (x % boundary)
|
||||||
|
|
||||||
|
class Crypto:
|
||||||
|
"""This is a Cryptographic/hash class used to abstract away things (to make changes easier)"""
|
||||||
|
def __init__(self):
|
||||||
|
return
|
||||||
|
def DecryptContent(self, titlekey, idx, data):
|
||||||
|
"""Decrypts a Content."""
|
||||||
|
iv = struct.pack(">H", idx) + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||||
|
if(len(data) % 16 != 0):
|
||||||
|
return AES.new(titlekey, AES.MODE_CBC, iv).decrypt(data + ("\x00" * (16 - (len(data) % 16))))[:len(data)]
|
||||||
|
else:
|
||||||
|
return AES.new(titlekey, AES.MODE_CBC, iv).decrypt(data)
|
||||||
|
def ValidateHash(self, data, hash):
|
||||||
|
"""Validates a hash. (BROKEN)"""
|
||||||
|
return 1 #hack
|
||||||
|
# if(hashlib.sha1(data).digest() == hash):
|
||||||
|
# return 1
|
||||||
|
# else:
|
||||||
|
# return 0
|
||||||
|
|
BIN
common.pyc
Normal file
BIN
common.pyc
Normal file
Binary file not shown.
BIN
compression.pyc
Normal file
BIN
compression.pyc
Normal file
Binary file not shown.
97
disc.py
Normal file
97
disc.py
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
|
||||||
|
class WOD: #WiiOpticalDisc
|
||||||
|
def __init__(self, f):
|
||||||
|
self.f = f
|
||||||
|
|
||||||
|
|
||||||
|
class fsentry:
|
||||||
|
name = ""
|
||||||
|
parent = None
|
||||||
|
|
||||||
|
def __init__(self, name, parent):
|
||||||
|
self.name = ""
|
||||||
|
if(parent != None):
|
||||||
|
self.parent = parent
|
||||||
|
def path(self):
|
||||||
|
return parent.path() + "/" + name
|
||||||
|
|
||||||
|
class fsdir(fsentry):
|
||||||
|
def __init__(self, name, parent):
|
||||||
|
fsentry.__init__(self, name, parent)
|
||||||
|
|
||||||
|
class fsfile(fsentry):
|
||||||
|
size = 0
|
||||||
|
offset = 0
|
||||||
|
|
||||||
|
|
||||||
|
def extractPartition(self, index, fn = ""):
|
||||||
|
self.fp = open(self.f, "rb")
|
||||||
|
|
||||||
|
if(fn == ""):
|
||||||
|
fn = os.path.dirname(self.f) + "/" + os.path.basename(self.f).replace(".", "_") + "_out"
|
||||||
|
try:
|
||||||
|
origdir = os.getcwd()
|
||||||
|
os.mkdir(fn)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
os.chdir(fn)
|
||||||
|
|
||||||
|
self.titleid = self.fp.read(4)
|
||||||
|
self.publisher = self.fp.read(2)
|
||||||
|
|
||||||
|
self.fp.seek(0x18)
|
||||||
|
if(struct.unpack(">I", self.fp.read(4))[0] != 0x5D1C9EA3):
|
||||||
|
self.fp.seek(-4, 1)
|
||||||
|
raise ValueError("Not a valid Wii Disc (GC not supported)! Magic: %08x" % struct.unpack(">I", self.fp.read(4))[0])
|
||||||
|
|
||||||
|
self.fp.seek(0x40000)
|
||||||
|
partitions = struct.unpack(">I", self.fp.read(4))[0]
|
||||||
|
parttableoffs = struct.unpack(">I", self.fp.read(4))[0] << 2
|
||||||
|
|
||||||
|
channels = struct.unpack(">I", self.fp.read(4))[0]
|
||||||
|
chantableoffs = struct.unpack(">I", self.fp.read(4))[0] << 2
|
||||||
|
|
||||||
|
self.fp.seek(parttableoffs + (8 * index))
|
||||||
|
partitionoffs = struct.unpack(">I", self.fp.read(4))[0] << 2
|
||||||
|
partitiontype = struct.unpack(">I", self.fp.read(4))[0] #0 is data, 1 is update, 2 is installer
|
||||||
|
|
||||||
|
self.fp.seek(partitionoffs)
|
||||||
|
|
||||||
|
tikdata = self.fp.read(0x2A3)
|
||||||
|
open("tik").write(tikdata)
|
||||||
|
self.tik = Ticket("tik")
|
||||||
|
self.titlekey = self.tik.getTitleKey()
|
||||||
|
|
||||||
|
tmdsz = struct.unpack(">I", self.fp.read(4))[0]
|
||||||
|
tmdoffs = struct.unpack(">I", self.fp.read(4))[0]
|
||||||
|
|
||||||
|
certsz = struct.unpack(">I", self.fp.read(4))[0]
|
||||||
|
certoffs = struct.unpack(">I", self.fp.read(4))[0]
|
||||||
|
|
||||||
|
h3offs = struct.unpack(">I", self.fp.read(4))[0] << 2
|
||||||
|
h3sz = 0x18000
|
||||||
|
|
||||||
|
dataoffs = struct.unpack(">I", self.fp.read(4))[0] << 2
|
||||||
|
datasz = struct.unpack(">I", self.fp.read(4))[0] << 2
|
||||||
|
if(tmdoffs != self.fp.tell()):
|
||||||
|
raise ValueError("TMD is in wrong place, something is fucked...wtf?")
|
||||||
|
|
||||||
|
tmddata = self.fp.read(tmdsz)
|
||||||
|
open("tmd").write(tmddata)
|
||||||
|
|
||||||
|
self.tmd = TMD("tmd")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fst.seek(dataoffs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
os.chdir("..")
|
||||||
|
def _recurse(self, parent, names, recursion):
|
||||||
|
if(recursion == 0):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
6
test.py
6
test.py
@ -1,6 +0,0 @@
|
|||||||
import Wii
|
|
||||||
|
|
||||||
try:
|
|
||||||
Wii.U8("/Users/Xuzz/code/wadder3").pack("testing.u8")
|
|
||||||
except:
|
|
||||||
pass
|
|
Loading…
Reference in New Issue
Block a user