Added a function to dump the partition, need testing

This commit is contained in:
Giuseppe (LemonBoy) 2009-06-24 21:15:41 +02:00
parent ba1c30c5b8
commit 3de32d664e

24
disc.py
View File

@ -98,13 +98,12 @@ class WOD: #WiiOpticalDisc
blockStart = offset / 0x7C00 blockStart = offset / 0x7C00
blockLen = (align(size, 0x7C00)) / 0x7C00 blockLen = (align(size, 0x7C00)) / 0x7C00
for x in range(blockStart, blockLen): for x in range(blockStart, blockStart + blockLen):
try: try:
self.markedBlocks.index(blockStart + x) self.markedBlocks.index(blockStart + x)
except: except:
self.markedBlocks.append(blockStart + x) self.markedBlocks.append(blockStart + x)
#print '%s (%i blocks marked)' % (self.markedBlocks, len(self.markedBlocks))
def decryptBlock(self, block): def decryptBlock(self, block):
if len(block) != 0x8000: if len(block) != 0x8000:
raise Exception('Block size too big/small') raise Exception('Block size too big/small')
@ -115,6 +114,10 @@ class WOD: #WiiOpticalDisc
return Crypto().decryptData(self.partitionKey, blockIV, blockData, True) return Crypto().decryptData(self.partitionKey, blockIV, blockData, True)
def readBlock(self, blockNumber):
self.fp.seek(self.partitionOffset + 0x20000 + (0x8000 * blockNumber))
return self.decryptBlock(self.fp.read(0x8000))
def readPartition(self, offset, size): def readPartition(self, offset, size):
readStart = offset / 0x7C00 readStart = offset / 0x7C00
@ -135,7 +138,7 @@ class WOD: #WiiOpticalDisc
return blob[offset:offset + size] return blob[offset:offset + size]
def readUnencrypted(self, offset, size): def readUnencrypted(self, offset, size):
if offset > 0x20000: if offset + size > 0x20000:
raise Exception('This read is on encrypted data') raise Exception('This read is on encrypted data')
# FIXMII : Needs testing, extracting the tmd cause to have 10 null bytes in the end instead of 10 useful bytes at start :| # FIXMII : Needs testing, extracting the tmd cause to have 10 null bytes in the end instead of 10 useful bytes at start :|
@ -307,6 +310,18 @@ class WOD: #WiiOpticalDisc
def getPartitionMainDol(self): def getPartitionMainDol(self):
return self.readPartition (self.dolOffset, self.dolSize) return self.readPartition (self.dolOffset, self.dolSize)
def dumpPartition(self, fn):
rawPartition = open(fn, 'w+b')
print 'Partition useful data %i Mb' % (align(len(self.markedBlocks) * 0x7C00, 1024) / 1024 / 1024)
self.fp.seek(self.partitionOffset)
rawPartition.write(self.fp.read(0x2A4)) # Write teh TIK
rawPartition.write(self.readUnencrypted(0, 0x20000 - 0x2A4)) # Write the TMD and other stuff
for x in range(len(self.markedBlocks)):
rawPartition.write(self.readBlock(self.markedBlocks[x])) # Write each decrypted block
class updateInf(): class updateInf():
def __init__(self, f): def __init__(self, f):
@ -323,6 +338,7 @@ class updateInf():
for x in range(self.fileCount): for x in range(self.fileCount):
updateEntry = self.buffer[0x2f + x * 0x200:0x2f + (x + 1) * 0x200] updateEntry = self.buffer[0x2f + x * 0x200:0x2f + (x + 1) * 0x200]
titleType = ord(updateEntry[0]) titleType = ord(updateEntry[0])
titlePriority = ord(updateEntry[1])
titleFile = updateEntry[0x1:0x1 + 0x50] titleFile = updateEntry[0x1:0x1 + 0x50]
titleFile = titleFile[:titleFile.find('\x00')] titleFile = titleFile[:titleFile.find('\x00')]
titleName = updateEntry[0x1 + 0x50:0x1 + 0x50 + 0x40] titleName = updateEntry[0x1 + 0x50:0x1 + 0x50 + 0x40]