mirror of
https://github.com/fail0verflow/hbc.git
synced 2024-11-17 15:19:22 +01:00
WIP: Quick and dirty python3 port
This commit is contained in:
parent
a8e5f6c0f7
commit
cad274a7fb
@ -14,14 +14,14 @@ export ALAMEDA := $(CURDIR)/../../pywii/Alameda
|
||||
export PNG2TPL := $(CURDIR)/tools/png2tpl$(EXE)
|
||||
export MKBNS := $(CURDIR)/tools/mkbns$(EXE)
|
||||
export LZ77 := $(CURDIR)/tools/lz77$(EXE)
|
||||
export ADDIMD5 := python2 $(CURDIR)/tools/addimd5.py
|
||||
export ARCPACK := python2 $(PYWII)/arcpack.py
|
||||
export ADDIMD5 := python3 $(CURDIR)/tools/addimd5.py
|
||||
export ARCPACK := python3 $(PYWII)/arcpack.py
|
||||
export SOX := sox
|
||||
|
||||
all: channel.imet
|
||||
|
||||
channel.imet: build/data.arc names.txt tools/join-imet.py
|
||||
python2 tools/join-imet.py $@ build/data.arc build/icon.arc build/banner.arc build/sound.bns names.txt
|
||||
python3 tools/join-imet.py $@ build/data.arc build/icon.arc build/banner.arc build/sound.bns names.txt
|
||||
|
||||
build/data.arc : build/data/meta/icon.bin build/data/meta/banner.bin build/data/meta/sound.bin
|
||||
$(ARCPACK) $@ build/data
|
||||
@ -45,9 +45,9 @@ build/%.raw : sound/%.wav
|
||||
$(SOX) $< -r 32000 -c 2 -e signed-integer -b 16 -t raw $@
|
||||
|
||||
testi : channel.imet
|
||||
python2 $(ALAMEDA)/Alameda.py channel.imet icon
|
||||
python3 $(ALAMEDA)/Alameda.py channel.imet icon
|
||||
testb : channel.imet
|
||||
python2 $(ALAMEDA)/Alameda.py channel.imet banner
|
||||
python3 $(ALAMEDA)/Alameda.py channel.imet banner
|
||||
|
||||
$(PNG2TPL): tools/*.c
|
||||
$(MAKE) -C tools png2tpl$(EXE)
|
||||
|
@ -19,7 +19,7 @@ endif
|
||||
../build/$(TYPE)/arc/blyt/$(TYPE).brlyt $(ANIMS) : mk$(TYPE).py
|
||||
@[ ! -d ../build/$(TYPE)/arc/anim ] && mkdir -p ../build/$(TYPE)/arc/anim || true
|
||||
@[ ! -d ../build/$(TYPE)/arc/blyt ] && mkdir -p ../build/$(TYPE)/arc/blyt || true
|
||||
python2 mk$(TYPE).py ../build/$(TYPE)/arc/blyt/$(TYPE).brlyt $(ANIMS)
|
||||
python3 mk$(TYPE).py ../build/$(TYPE)/arc/blyt/$(TYPE).brlyt $(ANIMS)
|
||||
|
||||
../build/$(TYPE).arc : $(TPLS) ../build/$(TYPE)/arc/blyt/$(TYPE).brlyt $(ANIMS)
|
||||
$(ARCPACK) ../build/$(TYPE).arc ../build/$(TYPE)
|
||||
|
@ -244,7 +244,7 @@ class BubbleInstance:
|
||||
for i in tps:
|
||||
if len(i.Triplets) > 0:
|
||||
if i.Triplets[-1][0] >= self.Start:
|
||||
print "WTF at %s: %f >= %f"%(self.Picture.Name,i.Triplets[-1][0],self.Start)
|
||||
print("WTF at %s: %f >= %f"%(self.Picture.Name,i.Triplets[-1][0],self.Start))
|
||||
raise RuntimeError("We Have A Problem")
|
||||
|
||||
brlan.Anim[self.Picture.Name][Brlan.A_COORD][Brlan.C_X].Triplets.append((self.Start, self.X, 0))
|
||||
@ -293,15 +293,15 @@ class BubbleCollection:
|
||||
#print "Freeing instance: [%f-%f]"%(user.Start,user.End)
|
||||
tis[i] = pic, None
|
||||
def printinstances(self):
|
||||
print "Type Instances:"
|
||||
print("Type Instances:")
|
||||
for tid, tis in enumerate(self.TypeInstances):
|
||||
print " Type Instances for type %d (%s):"%(tid, self.BubbleTypes[tid][0].Name)
|
||||
print(" Type Instances for type %d (%s):"%(tid, self.BubbleTypes[tid][0].Name))
|
||||
for i, ti in enumerate(tis):
|
||||
pic, user = ti
|
||||
if user is None:
|
||||
print " %d: Picture %s, free"%(i,pic.Name)
|
||||
print(" %d: Picture %s, free"%(i,pic.Name))
|
||||
else:
|
||||
print " %d: Picture %s, user: %s [%f-%f]"%(i,pic.Name,repr(user),user.Start,user.End)
|
||||
print(" %d: Picture %s, user: %s [%f-%f]"%(i,pic.Name,repr(user),user.Start,user.End))
|
||||
def render(self):
|
||||
for t,c in self.BubbleTypes:
|
||||
t.makemat(self.Brlyt)
|
||||
@ -330,9 +330,9 @@ class BubbleCollection:
|
||||
i.render(self.Brlan)
|
||||
#self.printinstances()
|
||||
|
||||
print "Fake Start",fakeStart
|
||||
print "Loop Start",loopStart
|
||||
print "Loop End",loopEnd
|
||||
print("Fake Start",fakeStart)
|
||||
print("Loop Start",loopStart)
|
||||
print("Loop End",loopEnd)
|
||||
|
||||
col = BubbleCollection(brlyt, brlan, bubblepane)
|
||||
col.addtype(BubbleType("abubble1", 48, 48),1)
|
||||
@ -374,10 +374,10 @@ for i in col.Instances:
|
||||
col.render()
|
||||
|
||||
brldata = brlyt.Pack()
|
||||
open(sys.argv[1],"w").write(brldata)
|
||||
open(sys.argv[1],"wb").write(brldata)
|
||||
|
||||
bradata = brlan.Pack(loopStart)
|
||||
open(sys.argv[2],"w").write(bradata)
|
||||
open(sys.argv[2],"wb").write(bradata)
|
||||
|
||||
bradata = brlan.Pack(loopStart, loopEnd)
|
||||
open(sys.argv[3],"w").write(bradata)
|
||||
open(sys.argv[3],"wb").write(bradata)
|
||||
|
@ -111,7 +111,7 @@ brlyt.RootPane.Add(tit)
|
||||
|
||||
brldata = brlyt.Pack()
|
||||
|
||||
open(sys.argv[1],"w").write(brldata)
|
||||
open(sys.argv[1],"wb").write(brldata)
|
||||
|
||||
|
||||
brlan = Brlan()
|
||||
@ -177,6 +177,6 @@ brlan.Anim['shadow'][Brlan.A_COORD][Brlan.C_X].repsimple(0, 960, 2, -45, -0.1, 4
|
||||
|
||||
bradata = brlan.Pack(60*16)
|
||||
for a,b,c in brlan.Anim['waveb'][Brlan.A_COORD][Brlan.C_X].Triplets:
|
||||
print a,b,c
|
||||
print(a,b,c)
|
||||
|
||||
open(sys.argv[2],"w").write(bradata)
|
||||
open(sys.argv[2],"wb").write(bradata)
|
||||
|
@ -1,12 +1,12 @@
|
||||
import md5, sys, struct
|
||||
import hashlib, sys, struct
|
||||
|
||||
data= open(sys.argv[1]).read()
|
||||
data= open(sys.argv[1], "rb").read()
|
||||
|
||||
digest = md5.new(data).digest()
|
||||
digest = hashlib.md5(data).digest()
|
||||
|
||||
hdr = struct.pack(">4sI8x","IMD5",len(data))
|
||||
hdr = struct.pack(">4sI8x",b"IMD5",len(data))
|
||||
|
||||
f2 = open(sys.argv[2],"w")
|
||||
f2 = open(sys.argv[2],"wb")
|
||||
f2.write(hdr)
|
||||
f2.write(digest)
|
||||
f2.write(data)
|
||||
|
@ -1,8 +1,8 @@
|
||||
import os, sys, struct, md5
|
||||
import os, sys, struct, hashlib
|
||||
|
||||
output, datafile, iconarc, bannerarc, soundbns, namesfile = sys.argv[1:]
|
||||
|
||||
data = open(datafile,"r").read()
|
||||
data = open(datafile,"rb").read()
|
||||
|
||||
names={}
|
||||
|
||||
@ -11,7 +11,7 @@ for i in open(namesfile,"r"):
|
||||
while b[-1] == "\n":
|
||||
b = b[:-1]
|
||||
b = b.replace("\\n","\n")
|
||||
names[a] = b.decode("utf-8")
|
||||
names[a] = b
|
||||
|
||||
def getsize(x):
|
||||
return os.stat(x).st_size
|
||||
@ -20,29 +20,29 @@ def pad(x,l):
|
||||
if len(x) > l:
|
||||
raise ValueError("%d > %d",len(x),l)
|
||||
n = l-len(x)
|
||||
return x + "\x00"*n
|
||||
return x + b"\x00"*n
|
||||
|
||||
imet = "\x00"*0x40
|
||||
imet += struct.pack(">4sIIIIII","IMET",0x600,3,getsize(iconarc),getsize(bannerarc),getsize(soundbns),1)
|
||||
imet = b"\x00"*0x40
|
||||
imet += struct.pack(">4sIIIIII",b"IMET",0x600,3,getsize(iconarc),getsize(bannerarc),getsize(soundbns),1)
|
||||
|
||||
for i in ["jp", "en", "de", "fr", "sp", "it", "nl", "cn", None, "ko"]:
|
||||
try:
|
||||
imet += pad(names[i].encode("UTF-16BE"),0x54)
|
||||
except KeyError:
|
||||
imet += "\x00"*0x54
|
||||
imet += "\x00"*(0x600 - len(imet))
|
||||
imet += b"\x00"*0x54
|
||||
imet += b"\x00"*(0x600 - len(imet))
|
||||
|
||||
imet = imet[:-16] + md5.new(imet).digest()
|
||||
imet = imet[:-16] + hashlib.md5(imet).digest()
|
||||
|
||||
open(output,"w").write(imet)
|
||||
open(output,"wb").write(imet)
|
||||
|
||||
f = open(sys.argv[1],"w")
|
||||
f = open(sys.argv[1],"wb")
|
||||
f.write(imet)
|
||||
f.write(data)
|
||||
|
||||
fsize = f.tell()
|
||||
|
||||
if (fsize % 20) != 0:
|
||||
f.write("\x00"*(20-(fsize%20)))
|
||||
f.write(b"\x00"*(20-(fsize%20)))
|
||||
|
||||
f.close()
|
||||
|
@ -33,7 +33,7 @@ DIR_LIBS = \
|
||||
$(DEVKITPRO)/libogc/lib/wii \
|
||||
$(DEVKITPRO)/portlibs/ppc/lib
|
||||
|
||||
LIBS = mxml freetype png bz2 z db fat wiiuse bte ogc m
|
||||
LIBS = mxml freetype png z db fat wiiuse bte ogc m
|
||||
|
||||
MACHDEP = -g -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float
|
||||
CFLAGS = $(MACHDEP) -Os -Wall -DBASE_ADDR=$(BASE_ADDR) $(DIR_INCLUDES:%=-I%)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,335 +1,339 @@
|
||||
import struct, sys
|
||||
|
||||
class StructType(tuple):
|
||||
def __getitem__(self, value):
|
||||
return [self] * value
|
||||
def __call__(self, value, endian='<'):
|
||||
if isinstance(value, str):
|
||||
return struct.unpack(endian + tuple.__getitem__(self, 0), value[:tuple.__getitem__(self, 1)])[0]
|
||||
else:
|
||||
return struct.pack(endian + tuple.__getitem__(self, 0), value)
|
||||
|
||||
class StructException(Exception):
|
||||
pass
|
||||
|
||||
class Struct(object):
|
||||
__slots__ = ('__attrs__', '__baked__', '__defs__', '__endian__', '__next__', '__sizes__', '__values__')
|
||||
int8 = StructType(('b', 1))
|
||||
uint8 = StructType(('B', 1))
|
||||
|
||||
int16 = StructType(('h', 2))
|
||||
uint16 = StructType(('H', 2))
|
||||
|
||||
int32 = StructType(('l', 4))
|
||||
uint32 = StructType(('L', 4))
|
||||
|
||||
int64 = StructType(('q', 8))
|
||||
uint64 = StructType(('Q', 8))
|
||||
|
||||
float = StructType(('f', 4))
|
||||
|
||||
@classmethod
|
||||
def string(cls, len, offset=0, encoding=None, stripNulls=False, value=''):
|
||||
return StructType(('string', (len, offset, encoding, stripNulls, value)))
|
||||
|
||||
LE = '<'
|
||||
BE = '>'
|
||||
__endian__ = '<'
|
||||
|
||||
def __init__(self, func=None, unpack=None, **kwargs):
|
||||
self.__defs__ = []
|
||||
self.__sizes__ = []
|
||||
self.__attrs__ = []
|
||||
self.__values__ = {}
|
||||
self.__next__ = True
|
||||
self.__baked__ = False
|
||||
|
||||
if func == None:
|
||||
self.__format__()
|
||||
else:
|
||||
sys.settrace(self.__trace__)
|
||||
func()
|
||||
for name in func.func_code.co_varnames:
|
||||
value = self.__frame__.f_locals[name]
|
||||
self.__setattr__(name, value)
|
||||
|
||||
self.__baked__ = True
|
||||
|
||||
if unpack != None:
|
||||
if isinstance(unpack, tuple):
|
||||
self.unpack(*unpack)
|
||||
else:
|
||||
self.unpack(unpack)
|
||||
|
||||
if len(kwargs):
|
||||
for name in kwargs:
|
||||
self.__values__[name] = kwargs[name]
|
||||
|
||||
def __trace__(self, frame, event, arg):
|
||||
self.__frame__ = frame
|
||||
sys.settrace(None)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name in self.__slots__:
|
||||
return object.__setattr__(self, name, value)
|
||||
|
||||
if self.__baked__ == False:
|
||||
if not isinstance(value, list):
|
||||
value = [value]
|
||||
attrname = name
|
||||
else:
|
||||
attrname = '*' + name
|
||||
|
||||
self.__values__[name] = None
|
||||
|
||||
for sub in value:
|
||||
if isinstance(sub, Struct):
|
||||
sub = sub.__class__
|
||||
try:
|
||||
if issubclass(sub, Struct):
|
||||
sub = ('struct', sub)
|
||||
except TypeError:
|
||||
pass
|
||||
type_, size = tuple(sub)
|
||||
if type_ == 'string':
|
||||
self.__defs__.append(Struct.string)
|
||||
self.__sizes__.append(size)
|
||||
self.__attrs__.append(attrname)
|
||||
self.__next__ = True
|
||||
|
||||
if attrname[0] != '*':
|
||||
self.__values__[name] = size[3]
|
||||
elif self.__values__[name] == None:
|
||||
self.__values__[name] = [size[3] for val in value]
|
||||
elif type_ == 'struct':
|
||||
self.__defs__.append(Struct)
|
||||
self.__sizes__.append(size)
|
||||
self.__attrs__.append(attrname)
|
||||
self.__next__ = True
|
||||
|
||||
if attrname[0] != '*':
|
||||
self.__values__[name] = size()
|
||||
elif self.__values__[name] == None:
|
||||
self.__values__[name] = [size() for val in value]
|
||||
else:
|
||||
if self.__next__:
|
||||
self.__defs__.append('')
|
||||
self.__sizes__.append(0)
|
||||
self.__attrs__.append([])
|
||||
self.__next__ = False
|
||||
|
||||
self.__defs__[-1] += type_
|
||||
self.__sizes__[-1] += size
|
||||
self.__attrs__[-1].append(attrname)
|
||||
|
||||
if attrname[0] != '*':
|
||||
self.__values__[name] = 0
|
||||
elif self.__values__[name] == None:
|
||||
self.__values__[name] = [0 for val in value]
|
||||
else:
|
||||
try:
|
||||
self.__values__[name] = value
|
||||
except KeyError:
|
||||
raise AttributeError(name)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if self.__baked__ == False:
|
||||
return name
|
||||
else:
|
||||
try:
|
||||
return self.__values__[name]
|
||||
except KeyError:
|
||||
raise AttributeError(name)
|
||||
|
||||
def __len__(self):
|
||||
ret = 0
|
||||
arraypos, arrayname = None, None
|
||||
|
||||
for i in range(len(self.__defs__)):
|
||||
sdef, size, attrs = self.__defs__[i], self.__sizes__[i], self.__attrs__[i]
|
||||
|
||||
if sdef == Struct.string:
|
||||
size, offset, encoding, stripNulls, value = size
|
||||
if isinstance(size, str):
|
||||
size = self.__values__[size] + offset
|
||||
elif sdef == Struct:
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arrayname = attrs
|
||||
arraypos = 0
|
||||
size = len(self.__values__[attrs[1:]][arraypos])
|
||||
size = len(self.__values__[attrs])
|
||||
|
||||
ret += size
|
||||
|
||||
return ret
|
||||
|
||||
def unpack(self, data, pos=0):
|
||||
for name in self.__values__:
|
||||
if not isinstance(self.__values__[name], Struct):
|
||||
self.__values__[name] = None
|
||||
elif self.__values__[name].__class__ == list and len(self.__values__[name]) != 0:
|
||||
if not isinstance(self.__values__[name][0], Struct):
|
||||
self.__values__[name] = None
|
||||
|
||||
arraypos, arrayname = None, None
|
||||
|
||||
for i in range(len(self.__defs__)):
|
||||
sdef, size, attrs = self.__defs__[i], self.__sizes__[i], self.__attrs__[i]
|
||||
|
||||
if sdef == Struct.string:
|
||||
size, offset, encoding, stripNulls, value = size
|
||||
if isinstance(size, str):
|
||||
size = self.__values__[size] + offset
|
||||
|
||||
temp = data[pos:pos+size]
|
||||
if len(temp) != size:
|
||||
raise StructException('Expected %i byte string, got %i' % (size, len(temp)))
|
||||
|
||||
if encoding != None:
|
||||
temp = temp.decode(encoding)
|
||||
|
||||
if stripNulls:
|
||||
temp = temp.rstrip('\0')
|
||||
|
||||
if attrs[0] == '*':
|
||||
name = attrs[1:]
|
||||
if self.__values__[name] == None:
|
||||
self.__values__[name] = []
|
||||
self.__values__[name].append(temp)
|
||||
else:
|
||||
self.__values__[attrs] = temp
|
||||
pos += size
|
||||
elif sdef == Struct:
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arrayname = attrs
|
||||
arraypos = 0
|
||||
name = attrs[1:]
|
||||
self.__values__[attrs][arraypos].unpack(data, pos)
|
||||
pos += len(self.__values__[attrs][arraypos])
|
||||
arraypos += 1
|
||||
else:
|
||||
self.__values__[attrs].unpack(data, pos)
|
||||
pos += len(self.__values__[attrs])
|
||||
else:
|
||||
values = struct.unpack(self.__endian__+sdef, data[pos:pos+size])
|
||||
pos += size
|
||||
j = 0
|
||||
for name in attrs:
|
||||
if name[0] == '*':
|
||||
name = name[1:]
|
||||
if self.__values__[name] == None:
|
||||
self.__values__[name] = []
|
||||
self.__values__[name].append(values[j])
|
||||
else:
|
||||
self.__values__[name] = values[j]
|
||||
j += 1
|
||||
|
||||
return self
|
||||
|
||||
def pack(self):
|
||||
arraypos, arrayname = None, None
|
||||
|
||||
ret = ''
|
||||
for i in range(len(self.__defs__)):
|
||||
sdef, size, attrs = self.__defs__[i], self.__sizes__[i], self.__attrs__[i]
|
||||
|
||||
if sdef == Struct.string:
|
||||
size, offset, encoding, stripNulls, value = size
|
||||
if isinstance(size, str):
|
||||
size = self.__values__[size]+offset
|
||||
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arraypos = 0
|
||||
arrayname = attrs
|
||||
temp = self.__values__[attrs[1:]][arraypos]
|
||||
arraypos += 1
|
||||
else:
|
||||
temp = self.__values__[attrs]
|
||||
|
||||
if encoding != None:
|
||||
temp = temp.encode(encoding)
|
||||
|
||||
temp = temp[:size]
|
||||
ret += temp + ('\0' * (size - len(temp)))
|
||||
elif sdef == Struct:
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arraypos = 0
|
||||
arrayname = attrs
|
||||
ret += self.__values__[attrs[1:]][arraypos].pack()
|
||||
arraypos += 1
|
||||
else:
|
||||
ret += self.__values__[attrs].pack()
|
||||
else:
|
||||
values = []
|
||||
for name in attrs:
|
||||
if name[0] == '*':
|
||||
if arrayname != name:
|
||||
arraypos = 0
|
||||
arrayname = name
|
||||
values.append(self.__values__[name[1:]][arraypos])
|
||||
arraypos += 1
|
||||
else:
|
||||
values.append(self.__values__[name])
|
||||
|
||||
ret += struct.pack(self.__endian__+sdef, *values)
|
||||
return ret
|
||||
|
||||
def __getitem__(self, value):
|
||||
return [('struct', self.__class__)] * value
|
||||
|
||||
if __name__=='__main__':
|
||||
class TestStruct(Struct):
|
||||
__endian__ = Struct.LE
|
||||
def __format__(self):
|
||||
self.foo, self.bar = Struct.uint32, Struct.float
|
||||
self.baz = Struct.string(8)
|
||||
|
||||
self.omg = Struct.uint32
|
||||
self.wtf = Struct.string(self.omg)
|
||||
|
||||
class HaxStruct(Struct):
|
||||
__endian__ = Struct.LE
|
||||
def __format__(self):
|
||||
self.thing1 = Struct.uint32
|
||||
self.thing2 = Struct.uint32
|
||||
self.hax = HaxStruct
|
||||
|
||||
test = TestStruct()
|
||||
test.unpack('\xEF\xBE\xAD\xDE\x00\x00\x80\x3Fdeadbeef\x04\x00\x00\x00test\xCA\xFE\xBA\xBE\xBE\xBA\xFE\xCA')
|
||||
assert test.foo == 0xDEADBEEF
|
||||
assert test.bar == 1.0
|
||||
assert test.baz == 'deadbeef'
|
||||
assert test.omg == 4
|
||||
assert test.wtf == 'test'
|
||||
assert test.hax.thing1 == 0xBEBAFECA
|
||||
assert test.hax.thing2 == 0xCAFEBABE
|
||||
|
||||
print 'Tests successful'
|
||||
|
||||
"""
|
||||
@Struct.LE
|
||||
def TestStruct():
|
||||
foo, bar = Struct.uint32, Struct.float
|
||||
baz = Struct.string(8)
|
||||
|
||||
omg = Struct.uint32
|
||||
wtf = Struct.string(omg)
|
||||
|
||||
@Struct.LE
|
||||
def HaxStruct():
|
||||
thing1 = Struct.uint32
|
||||
thing2 = Struct.uint32
|
||||
hax = HaxStruct()
|
||||
|
||||
test = TestStruct()
|
||||
test.foo = 0xCAFEBABE
|
||||
test.bar = 0.0
|
||||
thing = test.hax.thing1
|
||||
test.hax.thing1 = test.hax.thing2
|
||||
test.hax.thing2 = thing
|
||||
assert test.pack() == '\xBE\xBA\xFE\xCA\0\0\0\0deadbeef\x04\x00\x00\x00test\xBE\xBA\xFE\xCA\xCA\xFE\xBA\xBE'
|
||||
"""
|
||||
import struct, sys
|
||||
|
||||
class StructType(tuple):
|
||||
def __getitem__(self, value):
|
||||
return [self] * value
|
||||
def __call__(self, value, endian='<'):
|
||||
if isinstance(value, bytes):
|
||||
return struct.unpack(endian + tuple.__getitem__(self, 0), value[:tuple.__getitem__(self, 1)])[0]
|
||||
else:
|
||||
return struct.pack(endian + tuple.__getitem__(self, 0), value)
|
||||
|
||||
class StructException(Exception):
|
||||
pass
|
||||
|
||||
class Struct:
|
||||
__slots__ = ('__attrs__', '__baked__', '__defs__', '__next__', '__sizes__', '__values__')
|
||||
int8 = StructType(('b', 1))
|
||||
uint8 = StructType(('B', 1))
|
||||
|
||||
int16 = StructType(('h', 2))
|
||||
uint16 = StructType(('H', 2))
|
||||
|
||||
int32 = StructType(('l', 4))
|
||||
uint32 = StructType(('L', 4))
|
||||
|
||||
int64 = StructType(('q', 8))
|
||||
uint64 = StructType(('Q', 8))
|
||||
|
||||
float = StructType(('f', 4))
|
||||
|
||||
@classmethod
|
||||
def string(cls, len, offset=0, encoding=None, stripNulls=False, value=''):
|
||||
return StructType(('string', (len, offset, encoding, stripNulls, value)))
|
||||
|
||||
LE = '<'
|
||||
BE = '>'
|
||||
__endian__ = '<'
|
||||
|
||||
def __init__(self, func=None, unpack=None, **kwargs):
|
||||
self.__defs__ = []
|
||||
self.__sizes__ = []
|
||||
self.__attrs__ = []
|
||||
self.__values__ = {}
|
||||
self.__next__ = True
|
||||
self.__baked__ = False
|
||||
|
||||
if func == None:
|
||||
self.__format__()
|
||||
else:
|
||||
sys.settrace(self.__trace__)
|
||||
func()
|
||||
for name in func.__code__.co_varnames:
|
||||
value = self.__frame__.f_locals[name]
|
||||
self.__setattr__(name, value)
|
||||
|
||||
self.__baked__ = True
|
||||
|
||||
if unpack != None:
|
||||
if isinstance(unpack, tuple):
|
||||
self.unpack(*unpack)
|
||||
else:
|
||||
self.unpack(unpack)
|
||||
|
||||
if len(kwargs):
|
||||
for name in kwargs:
|
||||
self.__values__[name] = kwargs[name]
|
||||
|
||||
def __trace__(self, frame, event, arg):
|
||||
self.__frame__ = frame
|
||||
sys.settrace(None)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name in self.__slots__:
|
||||
return object.__setattr__(self, name, value)
|
||||
|
||||
if self.__baked__ == False:
|
||||
if not isinstance(value, list):
|
||||
value = [value]
|
||||
attrname = name
|
||||
else:
|
||||
attrname = '*' + name
|
||||
|
||||
self.__values__[name] = None
|
||||
|
||||
for sub in value:
|
||||
if isinstance(sub, Struct):
|
||||
sub = sub.__class__
|
||||
try:
|
||||
if issubclass(sub, Struct):
|
||||
sub = ('struct', sub)
|
||||
except TypeError:
|
||||
pass
|
||||
type_, size = tuple(sub)
|
||||
if type_ == 'string':
|
||||
self.__defs__.append(Struct.string)
|
||||
self.__sizes__.append(size)
|
||||
self.__attrs__.append(attrname)
|
||||
self.__next__ = True
|
||||
|
||||
if attrname[0] != '*':
|
||||
self.__values__[name] = size[3]
|
||||
elif self.__values__[name] == None:
|
||||
self.__values__[name] = [size[3] for val in value]
|
||||
elif type_ == 'struct':
|
||||
self.__defs__.append(Struct)
|
||||
self.__sizes__.append(size)
|
||||
self.__attrs__.append(attrname)
|
||||
self.__next__ = True
|
||||
|
||||
if attrname[0] != '*':
|
||||
self.__values__[name] = size()
|
||||
elif self.__values__[name] == None:
|
||||
self.__values__[name] = [size() for val in value]
|
||||
else:
|
||||
if self.__next__:
|
||||
self.__defs__.append('')
|
||||
self.__sizes__.append(0)
|
||||
self.__attrs__.append([])
|
||||
self.__next__ = False
|
||||
|
||||
self.__defs__[-1] += type_
|
||||
self.__sizes__[-1] += size
|
||||
self.__attrs__[-1].append(attrname)
|
||||
|
||||
if attrname[0] != '*':
|
||||
self.__values__[name] = 0
|
||||
elif self.__values__[name] == None:
|
||||
self.__values__[name] = [0 for val in value]
|
||||
else:
|
||||
try:
|
||||
self.__values__[name] = value
|
||||
except KeyError:
|
||||
raise AttributeError(name)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if self.__baked__ == False:
|
||||
return name
|
||||
else:
|
||||
try:
|
||||
return self.__values__[name]
|
||||
except KeyError:
|
||||
raise AttributeError(name)
|
||||
|
||||
def __len__(self):
|
||||
ret = 0
|
||||
arraypos, arrayname = None, None
|
||||
|
||||
for i in range(len(self.__defs__)):
|
||||
sdef, size, attrs = self.__defs__[i], self.__sizes__[i], self.__attrs__[i]
|
||||
|
||||
if sdef == Struct.string:
|
||||
size, offset, encoding, stripNulls, value = size
|
||||
if isinstance(size, str):
|
||||
size = self.__values__[size] + offset
|
||||
elif sdef == Struct:
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arrayname = attrs
|
||||
arraypos = 0
|
||||
size = len(self.__values__[attrs[1:]][arraypos])
|
||||
size = len(self.__values__[attrs])
|
||||
|
||||
ret += size
|
||||
|
||||
return ret
|
||||
|
||||
def unpack(self, data, pos=0):
|
||||
for name in self.__values__:
|
||||
if not isinstance(self.__values__[name], Struct):
|
||||
self.__values__[name] = None
|
||||
elif self.__values__[name].__class__ == list and len(self.__values__[name]) != 0:
|
||||
if not isinstance(self.__values__[name][0], Struct):
|
||||
self.__values__[name] = None
|
||||
|
||||
arraypos, arrayname = None, None
|
||||
|
||||
for i in range(len(self.__defs__)):
|
||||
sdef, size, attrs = self.__defs__[i], self.__sizes__[i], self.__attrs__[i]
|
||||
|
||||
if sdef == Struct.string:
|
||||
size, offset, encoding, stripNulls, value = size
|
||||
if isinstance(size, str):
|
||||
size = self.__values__[size] + offset
|
||||
|
||||
temp = data[pos:pos+size]
|
||||
if len(temp) != size:
|
||||
raise StructException('Expected %i byte string, got %i' % (size, len(temp)))
|
||||
|
||||
if stripNulls:
|
||||
temp = temp.rstrip(b'\0')
|
||||
|
||||
if encoding != None:
|
||||
temp = temp.decode(encoding)
|
||||
else:
|
||||
temp = temp.decode("ascii")
|
||||
|
||||
if attrs[0] == '*':
|
||||
name = attrs[1:]
|
||||
if self.__values__[name] == None:
|
||||
self.__values__[name] = []
|
||||
self.__values__[name].append(temp)
|
||||
else:
|
||||
self.__values__[attrs] = temp
|
||||
pos += size
|
||||
elif sdef == Struct:
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arrayname = attrs
|
||||
arraypos = 0
|
||||
name = attrs[1:]
|
||||
self.__values__[attrs][arraypos].unpack(data, pos)
|
||||
pos += len(self.__values__[attrs][arraypos])
|
||||
arraypos += 1
|
||||
else:
|
||||
self.__values__[attrs].unpack(data, pos)
|
||||
pos += len(self.__values__[attrs])
|
||||
else:
|
||||
values = struct.unpack(self.__endian__+sdef, data[pos:pos+size])
|
||||
pos += size
|
||||
j = 0
|
||||
for name in attrs:
|
||||
if name[0] == '*':
|
||||
name = name[1:]
|
||||
if self.__values__[name] == None:
|
||||
self.__values__[name] = []
|
||||
self.__values__[name].append(values[j])
|
||||
else:
|
||||
self.__values__[name] = values[j]
|
||||
j += 1
|
||||
|
||||
return self
|
||||
|
||||
def pack(self):
|
||||
arraypos, arrayname = None, None
|
||||
|
||||
ret = b''
|
||||
for i in range(len(self.__defs__)):
|
||||
sdef, size, attrs = self.__defs__[i], self.__sizes__[i], self.__attrs__[i]
|
||||
|
||||
if sdef == Struct.string:
|
||||
size, offset, encoding, stripNulls, value = size
|
||||
if isinstance(size, str):
|
||||
size = self.__values__[size]+offset
|
||||
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arraypos = 0
|
||||
arrayname = attrs
|
||||
temp = self.__values__[attrs[1:]][arraypos]
|
||||
arraypos += 1
|
||||
else:
|
||||
temp = self.__values__[attrs]
|
||||
|
||||
if encoding != None:
|
||||
temp = temp.encode(encoding)
|
||||
elif isinstance(temp, str):
|
||||
temp = temp.encode("ascii")
|
||||
|
||||
temp = temp[:size]
|
||||
ret += temp + (b'\0' * (size - len(temp)))
|
||||
elif sdef == Struct:
|
||||
if attrs[0] == '*':
|
||||
if arrayname != attrs:
|
||||
arraypos = 0
|
||||
arrayname = attrs
|
||||
ret += self.__values__[attrs[1:]][arraypos].pack()
|
||||
arraypos += 1
|
||||
else:
|
||||
ret += self.__values__[attrs].pack()
|
||||
else:
|
||||
values = []
|
||||
for name in attrs:
|
||||
if name[0] == '*':
|
||||
if arrayname != name:
|
||||
arraypos = 0
|
||||
arrayname = name
|
||||
values.append(self.__values__[name[1:]][arraypos])
|
||||
arraypos += 1
|
||||
else:
|
||||
values.append(self.__values__[name])
|
||||
|
||||
ret += struct.pack(self.__endian__+sdef, *values)
|
||||
return ret
|
||||
|
||||
def __getitem__(self, value):
|
||||
return [('struct', self.__class__)] * value
|
||||
|
||||
if __name__=='__main__':
|
||||
class TestStruct(Struct):
|
||||
__endian__ = Struct.LE
|
||||
def __format__(self):
|
||||
self.foo, self.bar = Struct.uint32, Struct.float
|
||||
self.baz = Struct.string(8)
|
||||
|
||||
self.omg = Struct.uint32
|
||||
self.wtf = Struct.string(self.omg)
|
||||
|
||||
class HaxStruct(Struct):
|
||||
__endian__ = Struct.LE
|
||||
def __format__(self):
|
||||
self.thing1 = Struct.uint32
|
||||
self.thing2 = Struct.uint32
|
||||
self.hax = HaxStruct
|
||||
|
||||
test = TestStruct()
|
||||
test.unpack(b'\xEF\xBE\xAD\xDE\x00\x00\x80\x3Fdeadbeef\x04\x00\x00\x00test\xCA\xFE\xBA\xBE\xBE\xBA\xFE\xCA')
|
||||
assert test.foo == 0xDEADBEEF
|
||||
assert test.bar == 1.0
|
||||
assert test.baz == b'deadbeef'
|
||||
assert test.omg == 4
|
||||
assert test.wtf == b'test'
|
||||
assert test.hax.thing1 == 0xBEBAFECA
|
||||
assert test.hax.thing2 == 0xCAFEBABE
|
||||
|
||||
print('Tests successful')
|
||||
|
||||
"""
|
||||
@Struct.LE
|
||||
def TestStruct():
|
||||
foo, bar = Struct.uint32, Struct.float
|
||||
baz = Struct.string(8)
|
||||
|
||||
omg = Struct.uint32
|
||||
wtf = Struct.string(omg)
|
||||
|
||||
@Struct.LE
|
||||
def HaxStruct():
|
||||
thing1 = Struct.uint32
|
||||
thing2 = Struct.uint32
|
||||
hax = HaxStruct()
|
||||
|
||||
test = TestStruct()
|
||||
test.foo = 0xCAFEBABE
|
||||
test.bar = 0.0
|
||||
thing = test.hax.thing1
|
||||
test.hax.thing1 = test.hax.thing2
|
||||
test.hax.thing2 = thing
|
||||
assert test.pack() == '\xBE\xBA\xFE\xCA\0\0\0\0deadbeef\x04\x00\x00\x00test\xBE\xBA\xFE\xCA\xCA\xFE\xBA\xBE'
|
||||
"""
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from wii import *
|
||||
from .wii import *
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/python3
|
||||
# Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
|
||||
# Copyright 2008 Hector Martin <marcan@marcansoft.com>
|
||||
# Licensed under the terms of the GNU GPL, version 2
|
||||
@ -12,11 +12,11 @@ except ImportError:
|
||||
from Crypto.Util.number import bytes_to_long, long_to_bytes
|
||||
|
||||
# y**2 + x*y = x**3 + x + b
|
||||
ec_b = "\x00\x66\x64\x7e\xde\x6c\x33\x2c\x7f\x8c\x09\x23\xbb\x58\x21"+\
|
||||
"\x3b\x33\x3b\x20\xe9\xce\x42\x81\xfe\x11\x5f\x7d\x8f\x90\xad"
|
||||
ec_b = (b"\x00\x66\x64\x7e\xde\x6c\x33\x2c\x7f\x8c\x09\x23\xbb\x58\x21"+
|
||||
b"\x3b\x33\x3b\x20\xe9\xce\x42\x81\xfe\x11\x5f\x7d\x8f\x90\xad")
|
||||
|
||||
def hexdump(s,sep=""):
|
||||
return sep.join(map(lambda x: "%02x"%ord(x),s))
|
||||
return sep.join(["%02x"%ord(x) for x in s])
|
||||
|
||||
def bhex(s,sep=""):
|
||||
return hexdump(long_to_bytes(s,30),sep)
|
||||
@ -41,20 +41,20 @@ class ByteArray(array):
|
||||
else:
|
||||
array.__setitem__(self, item, value & 0xFF)
|
||||
def __long__(self):
|
||||
return bytes_to_long(self.tostring())
|
||||
return bytes_to_long(self.tobytes())
|
||||
def __str__(self):
|
||||
return ''.join(["%02x"%ord(x) for x in self.tostring()])
|
||||
return ''.join(["%02x"%x for x in self.tobytes()])
|
||||
def __repr__(self):
|
||||
return "ByteArray('%s')"%''.join(["\\x%02x"%ord(x) for x in self.tostring()])
|
||||
return "ByteArray('%s')"%''.join(["\\x%02x"%x for x in self.tobytes()])
|
||||
|
||||
class ELT_PY:
|
||||
SIZEBITS=233
|
||||
SIZE=(SIZEBITS+7)/8
|
||||
square = ByteArray("\x00\x01\x04\x05\x10\x11\x14\x15\x40\x41\x44\x45\x50\x51\x54\x55")
|
||||
square = ByteArray(b"\x00\x01\x04\x05\x10\x11\x14\x15\x40\x41\x44\x45\x50\x51\x54\x55")
|
||||
def __init__(self, initializer=None):
|
||||
if isinstance(initializer, long) or isinstance(initializer, int):
|
||||
if isinstance(initializer, int) or isinstance(initializer, int):
|
||||
self.d = ByteArray(long_to_bytes(initializer,self.SIZE))
|
||||
elif isinstance(initializer, str):
|
||||
elif isinstance(initializer, bytes):
|
||||
self.d = ByteArray(initializer)
|
||||
elif isinstance(initializer, ByteArray):
|
||||
self.d = ByteArray(initializer)
|
||||
@ -80,12 +80,12 @@ class ELT_PY:
|
||||
return cmp(self.d,other.d)
|
||||
|
||||
def __long__(self):
|
||||
return long(self.d)
|
||||
return int(self.d)
|
||||
def __repr__(self):
|
||||
return repr(self.d).replace("ByteArray","ELT")
|
||||
def __str__(self):
|
||||
return str(self.d)
|
||||
def __nonzero__(self):
|
||||
def __bytes__(self):
|
||||
return bytes(self.d)
|
||||
def __bool__(self):
|
||||
for x in self.d:
|
||||
if x != 0:
|
||||
return True
|
||||
@ -184,21 +184,21 @@ class ELT_PY:
|
||||
def __setitem__(self,item,value):
|
||||
self.d[item] = value
|
||||
def tobignum(self):
|
||||
return bytes_to_long(self.d.tostring())
|
||||
return bytes_to_long(self.d.tobytes())
|
||||
def tobytes(self):
|
||||
return self.d.tostring()
|
||||
return self.d.tobytes()
|
||||
|
||||
class ELT_C(ELT_PY):
|
||||
def __mul__(self,other):
|
||||
if not isinstance(other,ELT):
|
||||
return NotImplemented
|
||||
return ELT(_ec.elt_mul(self.d.tostring(),other.d.tostring()))
|
||||
return ELT(_ec.elt_mul(self.d.tobytes(),other.d.tobytes()))
|
||||
def __rdiv__(self,other):
|
||||
if other != 1:
|
||||
return ELT_PY.__rdiv__(self,other)
|
||||
return ELT(_ec.elt_inv(self.d.tostring()))
|
||||
return ELT(_ec.elt_inv(self.d.tobytes()))
|
||||
def _square(self):
|
||||
return ELT(_ec.elt_square(self.d.tostring()))
|
||||
return ELT(_ec.elt_square(self.d.tobytes()))
|
||||
|
||||
if fastelt:
|
||||
ELT = ELT_C
|
||||
@ -207,7 +207,7 @@ else:
|
||||
|
||||
class Point:
|
||||
def __init__(self,x,y=None):
|
||||
if isinstance(x,str) and (y is None) and (len(x) == 60):
|
||||
if isinstance(x,bytes) and (y is None) and (len(x) == 60):
|
||||
self.x = ELT(x[:30])
|
||||
self.y = ELT(x[30:])
|
||||
elif isinstance(x,Point):
|
||||
@ -292,7 +292,7 @@ class Point:
|
||||
return "(%s,%s)"%(str(self.x),str(self.y))
|
||||
def __repr__(self):
|
||||
return "Point"+str(self)
|
||||
def __nonzero__(self):
|
||||
def __bool__(self):
|
||||
return self.x or self.y
|
||||
def tobytes(self):
|
||||
return self.x.tobytes() + self.y.tobytes()
|
||||
@ -305,15 +305,15 @@ def bn_inv(a,N):
|
||||
|
||||
# order of the addition group of points
|
||||
ec_N = bytes_to_long(
|
||||
"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+\
|
||||
"\x13\xe9\x74\xe7\x2f\x8a\x69\x22\x03\x1d\x26\x03\xcf\xe0\xd7")
|
||||
b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
b"\x13\xe9\x74\xe7\x2f\x8a\x69\x22\x03\x1d\x26\x03\xcf\xe0\xd7")
|
||||
|
||||
# base point
|
||||
ec_G = Point(
|
||||
"\x00\xfa\xc9\xdf\xcb\xac\x83\x13\xbb\x21\x39\xf1\xbb\x75\x5f"+
|
||||
"\xef\x65\xbc\x39\x1f\x8b\x36\xf8\xf8\xeb\x73\x71\xfd\x55\x8b"+
|
||||
"\x01\x00\x6a\x08\xa4\x19\x03\x35\x06\x78\xe5\x85\x28\xbe\xbf"+
|
||||
"\x8a\x0b\xef\xf8\x67\xa7\xca\x36\x71\x6f\x7e\x01\xf8\x10\x52")
|
||||
b"\x00\xfa\xc9\xdf\xcb\xac\x83\x13\xbb\x21\x39\xf1\xbb\x75\x5f"+
|
||||
b"\xef\x65\xbc\x39\x1f\x8b\x36\xf8\xf8\xeb\x73\x71\xfd\x55\x8b"+
|
||||
b"\x01\x00\x6a\x08\xa4\x19\x03\x35\x06\x78\xe5\x85\x28\xbe\xbf"+
|
||||
b"\x8a\x0b\xef\xf8\x67\xa7\xca\x36\x71\x6f\x7e\x01\xf8\x10\x52")
|
||||
|
||||
def generate_ecdsa(k, sha):
|
||||
k = bytes_to_long(k)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2008 Hector Martin <marcan@marcansoft.com>
|
||||
# Licensed under the terms of the GNU GPL, version 2
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
||||
@ -21,7 +21,7 @@ except ImportError:
|
||||
from Crypto.Util.number import bytes_to_long, long_to_bytes
|
||||
from Crypto.Signature import pkcs1_15
|
||||
|
||||
import ec
|
||||
from . import ec
|
||||
|
||||
WII_RSA4096 = 0
|
||||
WII_RSA2048 = 1
|
||||
@ -30,13 +30,13 @@ WII_ECDSA = 2
|
||||
sigtypes = [ "RSA-4096", "RSA-2048", "EC-DSA" ]
|
||||
|
||||
def load_rsa_key(issuer):
|
||||
print "Loading private key for %s" % issuer
|
||||
print("Loading private key for %s" % issuer)
|
||||
path = os.path.join(os.environ["HOME"], ".wii", "dpki", issuer + ".pem")
|
||||
return RSA.importKey(open(path, "r").read())
|
||||
|
||||
signkeyfuncs = [ load_rsa_key, load_rsa_key, None ]
|
||||
|
||||
NULL_IV = "\x00"*16
|
||||
NULL_IV = b"\x00"*16
|
||||
|
||||
keylist = [
|
||||
"common-key",
|
||||
@ -86,13 +86,13 @@ known_titles_noregion = {
|
||||
}
|
||||
|
||||
def hexdump(s,sep=" "):
|
||||
return sep.join(map(lambda x: "%02x"%ord(x),s))
|
||||
return sep.join(["%02x"%x for x in s])
|
||||
|
||||
def strcmp(s1,s2):
|
||||
clen = min(len(s1),len(s2))
|
||||
|
||||
for i in range(clen):
|
||||
if s1[i] == "\0" and s2[i] == "\0":
|
||||
if s1[i] == 0 and s2[i] == 0:
|
||||
return True
|
||||
if s1[i] != s2[i]:
|
||||
return False
|
||||
@ -101,10 +101,10 @@ def strcmp(s1,s2):
|
||||
def ascii(s):
|
||||
s2 = ""
|
||||
for c in s:
|
||||
if ord(c)<0x20 or ord(c)>0x7e:
|
||||
if c<0x20 or c>0x7e:
|
||||
s2 += "."
|
||||
else:
|
||||
s2 += c
|
||||
s2 += chr(c)
|
||||
return s2
|
||||
|
||||
def pad(s,c,l):
|
||||
@ -114,15 +114,10 @@ def pad(s,c,l):
|
||||
|
||||
def chexdump(s):
|
||||
for i in range(0,len(s),16):
|
||||
print "%08x %s %s |%s|"%(i,pad(hexdump(s[i:i+8],' ')," ",23),pad(hexdump(s[i+8:i+16],' ')," ",23),pad(ascii(s[i:i+16])," ",16))
|
||||
print("%08x %s %s |%s|"%(i,pad(hexdump(s[i:i+8],' ')," ",23),pad(hexdump(s[i+8:i+16],' ')," ",23),pad(ascii(s[i:i+16])," ",16)))
|
||||
|
||||
def getcstring(s):
|
||||
s2 = ""
|
||||
for c in s:
|
||||
if c == "\x00":
|
||||
break
|
||||
s2 += c
|
||||
return s2
|
||||
return s.split(b"\x00")[0].decode("ascii")
|
||||
|
||||
def align(n,a):
|
||||
if a == 0:
|
||||
@ -132,10 +127,10 @@ def align(n,a):
|
||||
return n
|
||||
|
||||
def rangel(n,s):
|
||||
return range(n,n+s)
|
||||
return list(range(n,n+s))
|
||||
|
||||
def xrangel(n,s):
|
||||
return xrange(n,n+s)
|
||||
return range(n,n+s)
|
||||
|
||||
def falign(f,a):
|
||||
f.seek(align(f.tell(),a))
|
||||
@ -200,7 +195,7 @@ def loadkeys(path = None):
|
||||
try:
|
||||
keys[key] = open(path + os.sep + key, "rb").read()
|
||||
except:
|
||||
print "Warning: failed to load key %s"%key
|
||||
print("Warning: failed to load key %s"%key)
|
||||
|
||||
def loadkeys_dpki(path = None):
|
||||
if path is None:
|
||||
@ -210,7 +205,7 @@ def loadkeys_dpki(path = None):
|
||||
def parse_certs(blob):
|
||||
certs = {}
|
||||
certlist = []
|
||||
while blob != "":
|
||||
while blob != b"":
|
||||
cert = WiiCert(blob)
|
||||
certs[cert.name] = cert
|
||||
certlist.append(cert)
|
||||
@ -250,7 +245,7 @@ class WiiPKAlgo:
|
||||
code = ">"+codes[bytes]
|
||||
matchlen = len(match)
|
||||
|
||||
for pad in xrange(0, 256**bytes):
|
||||
for pad in range(0, 256**bytes):
|
||||
pad += 0x4612512415125316
|
||||
pad %= 256**bytes
|
||||
padsig = signature + pack(code, pad)
|
||||
@ -270,11 +265,11 @@ class WiiRSA(WiiPKAlgo):
|
||||
def get_digest(self, signature):
|
||||
lsig = bytes_to_long(signature)
|
||||
if lsig >= self.n:
|
||||
print "Warning: signature larger than modulus, using sig%modulus as signature"
|
||||
print("Warning: signature larger than modulus, using sig%modulus as signature")
|
||||
ldec = pow(lsig, self.e, self.n)
|
||||
dec = long_to_bytes(ldec)
|
||||
pad = len(signature) - len(dec)
|
||||
dec = "\x00"*pad+dec
|
||||
dec = b"\x00"*pad+dec
|
||||
return dec[-20:]
|
||||
|
||||
def sign(self, data, key):
|
||||
@ -340,11 +335,11 @@ class WiiDisc:
|
||||
return self.partitions
|
||||
|
||||
def showinfo(self):
|
||||
print "Game %s, maker %s, magic %08x: %s"%(self.gamecode, self.makercode, self.magic, self.gamename)
|
||||
print("Game %s, maker %s, magic %08x: %s"%(self.gamecode, self.makercode, self.magic, self.gamename))
|
||||
self.read_partitions()
|
||||
print "%d partitions in ISO:"%len(self.partitions)
|
||||
print("%d partitions in ISO:"%len(self.partitions))
|
||||
for p_num,p_dat in enumerate(self.partitions):
|
||||
print " [%2d] 0x%010x (%08x)"%(p_num,p_dat[0],p_dat[1])
|
||||
print(" [%2d] 0x%010x (%08x)"%(p_num,p_dat[0],p_dat[1]))
|
||||
|
||||
class WiiSigned:
|
||||
sigsizes = [512, 256, 60]
|
||||
@ -370,7 +365,7 @@ class WiiSigned:
|
||||
|
||||
def update(self):
|
||||
self.data = pack(">I",self.sigtype+0x10000) + self.signature
|
||||
self.data += "\x00" * (self.body_offset - len(self.data))
|
||||
self.data += b"\x00" * (self.body_offset - len(self.data))
|
||||
self.data += self.body
|
||||
|
||||
def parse(self):
|
||||
@ -388,7 +383,7 @@ class WiiSigned:
|
||||
raise ValueError("Signature type %s does not match certificate type %s!"%(sigtypes[self.sigtype],sigtypes[cert.key_type]))
|
||||
return cert.pkalgo.get_digest(self.sigtype, self.signature)
|
||||
|
||||
def brute_sha(self, match = "\x00", fillshort = None):
|
||||
def brute_sha(self, match = b"\x00", fillshort = None):
|
||||
l = len(match)
|
||||
|
||||
if fillshort is None:
|
||||
@ -408,7 +403,7 @@ class WiiSigned:
|
||||
if len(issuer) > 39:
|
||||
raise ValueError("issuer name too long!")
|
||||
self.issuer = issuer.split("-")
|
||||
self.body = issuer + "\x00" * (0x40 - len(issuer)) + self.body[0x40:]
|
||||
self.body = issuer + b"\x00" * (0x40 - len(issuer)) + self.body[0x40:]
|
||||
self.update()
|
||||
|
||||
def update_signature(self, sig):
|
||||
@ -416,7 +411,7 @@ class WiiSigned:
|
||||
self.data = pack(">I",self.sigtype+0x10000) + self.signature + self.data[len(sig) + 4:]
|
||||
|
||||
def null_signature(self):
|
||||
self.signature = "\x00"*len(self.signature)
|
||||
self.signature = b"\x00"*len(self.signature)
|
||||
self.data = pack(">I",self.sigtype+0x10000) + self.signature + self.data[len(self.signature) + 4:]
|
||||
|
||||
def sign(self,certs):
|
||||
@ -453,22 +448,22 @@ class WiiSigned:
|
||||
if cert.pkalgo.can_get_digest:
|
||||
signhash = cert.pkalgo.get_digest(self.signature)
|
||||
if myhash == signhash:
|
||||
print it+"%s signed by %s using %s: %s [OK]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash))
|
||||
print(it+"%s signed by %s using %s: %s [OK]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash)))
|
||||
elif strcmp(myhash, signhash):
|
||||
print it+"%s signed by %s using %s: %s [BUG]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash))
|
||||
print it+" Signature hash: %s"%hexdump(signhash)
|
||||
print(it+"%s signed by %s using %s: %s [BUG]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash)))
|
||||
print(it+" Signature hash: %s"%hexdump(signhash))
|
||||
else:
|
||||
print it+"%s signed by %s using %s: %s [FAIL]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash))
|
||||
print it+" Signature hash: %s"%hexdump(signhash)
|
||||
print(it+"%s signed by %s using %s: %s [FAIL]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash)))
|
||||
print(it+" Signature hash: %s"%hexdump(signhash))
|
||||
else:
|
||||
sigok = cert.pkalgo.check_digest(self.signature,myhash)
|
||||
if sigok:
|
||||
print it+"%s signed by %s using %s: %s [OK]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash))
|
||||
print(it+"%s signed by %s using %s: %s [OK]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash)))
|
||||
else:
|
||||
print it+"%s signed by %s using %s: %s [FAIL]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash))
|
||||
print(it+"%s signed by %s using %s: %s [FAIL]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash)))
|
||||
|
||||
except KeyError:
|
||||
print it+"%s signed by %s using %s: %s [ISSUER NOT FOUND]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash))
|
||||
print(it+"%s signed by %s using %s: %s [ISSUER NOT FOUND]"%(self.type, "-".join(self.issuer), sigtypes[self.sigtype], hexdump(myhash)))
|
||||
|
||||
class WiiTik(WiiSigned):
|
||||
def __init__(self, data):
|
||||
@ -480,7 +475,7 @@ class WiiTik(WiiSigned):
|
||||
def parse(self):
|
||||
self.title_key_enc = self.body[0x7f:0x8f]
|
||||
self.title_id = self.body[0x9c:0xa4]
|
||||
self.title_key_iv = self.title_id + "\x00"*8
|
||||
self.title_key_iv = self.title_id + b"\x00"*8
|
||||
self.common_key_index = ord(self.body[0xb1:0xb2])
|
||||
|
||||
try:
|
||||
@ -489,7 +484,7 @@ class WiiTik(WiiSigned):
|
||||
elif self.common_key_index == 1:
|
||||
key = keys["korean-key"]
|
||||
else:
|
||||
print "WARNING: OLD FAKESIGNED TICKET WITH BAD KEY OFFSET, ASSUMING NORMAL COMMON KEY"
|
||||
print("WARNING: OLD FAKESIGNED TICKET WITH BAD KEY OFFSET, ASSUMING NORMAL COMMON KEY")
|
||||
key = keys["common-key"]
|
||||
aes = AES.new(key, AES.MODE_CBC, self.title_key_iv)
|
||||
self.title_key = aes.decrypt(self.title_key_enc)
|
||||
@ -505,13 +500,13 @@ class WiiTik(WiiSigned):
|
||||
return 0x164
|
||||
|
||||
def showinfo(self, it=""):
|
||||
print it+"ETicket: "
|
||||
print it+" Title ID: "+repr(self.title_id)
|
||||
print it+" Title key IV: "+hexdump(self.title_key_iv)
|
||||
print it+" Title key (encrypted): "+hexdump(self.title_key_enc)
|
||||
print it+" Common key index: %d" % self.common_key_index
|
||||
print(it+"ETicket: ")
|
||||
print(it+" Title ID: "+repr(self.title_id))
|
||||
print(it+" Title key IV: "+hexdump(self.title_key_iv))
|
||||
print(it+" Title key (encrypted): "+hexdump(self.title_key_enc))
|
||||
print(it+" Common key index: %d" % self.common_key_index)
|
||||
if self.title_key is not None:
|
||||
print it+" Title key (decrypted): "+hexdump(self.title_key)
|
||||
print(it+" Title key (decrypted): "+hexdump(self.title_key))
|
||||
|
||||
class WiiPartitionOffsets:
|
||||
def __init__(self, data):
|
||||
@ -528,9 +523,9 @@ class WiiPartitionOffsets:
|
||||
self.data_size = unpack(">I",self.data[0x18:0x1c])[0]<<2
|
||||
|
||||
def showinfo(self, it=""):
|
||||
print it+"TMD @ 0x%x [0x%x], Certs @ 0x%x [0x%x], H3 @ 0x%x, Data @ 0x%x [0x%x]"%(
|
||||
print(it+"TMD @ 0x%x [0x%x], Certs @ 0x%x [0x%x], H3 @ 0x%x, Data @ 0x%x [0x%x]"%(
|
||||
self.tmd_offset, self.tmd_size, self.cert_offset, self.cert_size,
|
||||
self.h3_offset, self.data_offset, self.data_size)
|
||||
self.h3_offset, self.data_offset, self.data_size))
|
||||
|
||||
def update(self):
|
||||
self.data = pack(">II",self.tmd_size, self.tmd_offset>>2)
|
||||
@ -600,20 +595,20 @@ class WiiTmd(WiiSigned):
|
||||
self.update()
|
||||
|
||||
def showinfo(self,it=""):
|
||||
print it+"TMD: "
|
||||
print it+" Versions: %d, CA CRL %d, Signer CRL %d, System %d-%d"%(
|
||||
self.version,self.ca_crl_version,self.signer_crl_version,self.sys_version>>32,self.sys_version&0xffffffff)
|
||||
print it+" Title ID: %s-%s (%s-%s)"%(hexdump(self.title_id[:4],''),hexdump(self.title_id[4:],''),repr(self.title_id[:4]),repr(self.title_id[4:]))
|
||||
print it+" Title Type: %d"%self.title_type
|
||||
print it+" Group ID: %s"%repr(self.group_id)
|
||||
print it+" Access Rights: 0x%08x"%self.access_rights
|
||||
print it+" Title Version: 0x%x"%self.title_version
|
||||
print it+" Boot Index: %d"%self.boot_index
|
||||
print it+" Contents:"
|
||||
print it+" ID Index Type Size Hash"
|
||||
print(it+"TMD: ")
|
||||
print(it+" Versions: %d, CA CRL %d, Signer CRL %d, System %d-%d"%(
|
||||
self.version,self.ca_crl_version,self.signer_crl_version,self.sys_version>>32,self.sys_version&0xffffffff))
|
||||
print(it+" Title ID: %s-%s (%s-%s)"%(hexdump(self.title_id[:4],''),hexdump(self.title_id[4:],''),repr(self.title_id[:4]),repr(self.title_id[4:])))
|
||||
print(it+" Title Type: %d"%self.title_type)
|
||||
print(it+" Group ID: %s"%repr(self.group_id))
|
||||
print(it+" Access Rights: 0x%08x"%self.access_rights)
|
||||
print(it+" Title Version: 0x%x"%self.title_version)
|
||||
print(it+" Boot Index: %d"%self.boot_index)
|
||||
print(it+" Contents:")
|
||||
print(it+" ID Index Type Size Hash")
|
||||
for ct in self.get_content_records():
|
||||
|
||||
print it+" %08X %-5d 0x%-5x %-12s %s"%(ct.cid, ct.index, ct.ftype, "0x%x"%ct.size,hexdump(ct.sha))
|
||||
print(it+" %08X %-5d 0x%-5x %-12s %s"%(ct.cid, ct.index, ct.ftype, "0x%x"%ct.size,hexdump(ct.sha)))
|
||||
|
||||
class WiiCert(WiiSigned):
|
||||
key_sizes = [516, 260, 60]
|
||||
@ -638,7 +633,7 @@ class WiiCert(WiiSigned):
|
||||
self.pkalgo = self.pk_types[self.key_type](self.key)
|
||||
|
||||
def showinfo(self,it=""):
|
||||
print it+"%s (%s)"%(self.name,sigtypes[self.key_type])
|
||||
print(it+"%s (%s)"%(self.name,sigtypes[self.key_type]))
|
||||
|
||||
class WiiRootCert:
|
||||
def __init__(self, data):
|
||||
@ -650,7 +645,7 @@ class WiiRootCert:
|
||||
self.key_type = 0
|
||||
|
||||
def showinfo(self,it=""):
|
||||
print it+"%s (%s)"%(self.name,sigtypes[self.key_type])
|
||||
print(it+"%s (%s)"%(self.name,sigtypes[self.key_type]))
|
||||
|
||||
class WiiPartition:
|
||||
BLOCKS_PER_SUBGROUP = 8
|
||||
@ -732,37 +727,37 @@ class WiiPartition:
|
||||
self.f.write(self.offsets.data)
|
||||
|
||||
def showinfo(self,it=""):
|
||||
print it+"Wii Partition at 0x%010x:"%(self.offset)
|
||||
print(it+"Wii Partition at 0x%010x:"%(self.offset))
|
||||
self.offsets.showinfo(" ")
|
||||
self.tik.showinfo(it+" ")
|
||||
self.tik.showsig(self.certs,it+" ")
|
||||
self.tmd.showinfo(it+" ")
|
||||
self.tmd.showsig(self.certs,it+" ")
|
||||
if self.checkh4hash():
|
||||
print it+" H4 hash check passed"
|
||||
print(it+" H4 hash check passed")
|
||||
else:
|
||||
print it+" H4 check failed: SHA1(H3) = "+hexdump(self.geth4hash())
|
||||
print it+" Data:"
|
||||
print it+" Blocks: %d"%self.data_blocks
|
||||
print it+" Subgroups: %d (plus %d blocks)"%(self.data_subgroups,self.extra_subgroup_blocks)
|
||||
print it+" Groups: %d (plus %d blocks)"%(self.data_groups,self.extra_group_blocks)
|
||||
print(it+" H4 check failed: SHA1(H3) = "+hexdump(self.geth4hash()))
|
||||
print(it+" Data:")
|
||||
print(it+" Blocks: %d"%self.data_blocks)
|
||||
print(it+" Subgroups: %d (plus %d blocks)"%(self.data_subgroups,self.extra_subgroup_blocks))
|
||||
print(it+" Groups: %d (plus %d blocks)"%(self.data_groups,self.extra_group_blocks))
|
||||
self.showcerts(it+" ")
|
||||
|
||||
def showcerts(self,it=""):
|
||||
print it+"Certificates: "
|
||||
print(it+"Certificates: ")
|
||||
for cert in self.certlist:
|
||||
cert.showinfo(it+" - ")
|
||||
cert.showsig(self.certs,it+" ")
|
||||
|
||||
def geth4hash(self):
|
||||
return SHA.new(''.join(self.h3) + "\x00"*self.TAIL_H3).digest()
|
||||
return SHA.new(b''.join(self.h3) + b"\x00"*self.TAIL_H3).digest()
|
||||
|
||||
def checkh4hash(self):
|
||||
return self.geth4hash() == self.tmd.get_content_records()[0].sha
|
||||
|
||||
def updateh3(self):
|
||||
self._seek(self.offsets.h3_offset)
|
||||
self.f.write(''.join(self.h3))
|
||||
self.f.write(b''.join(self.h3))
|
||||
|
||||
def updateh4(self):
|
||||
cr = self.tmd.get_content_records()[0]
|
||||
@ -903,7 +898,7 @@ class WiiPartition:
|
||||
else:
|
||||
raise ValueError("Attempted to read group past the end of the partition data")
|
||||
|
||||
data = ""
|
||||
data = b""
|
||||
for i in range(nblocks):
|
||||
data += self.readblock(blockoff+i)
|
||||
return data
|
||||
@ -919,7 +914,7 @@ class WiiPartition:
|
||||
if groupnum == self.data_groups and self.extra_group_blocks > 0 and len(data) == (self.extra_group_blocks * self.PLAIN_BLOCK_SIZE):
|
||||
blocks = self.extra_group_blocks
|
||||
writesize = blocks * self.CIPHER_BLOCK_SIZE
|
||||
data += "\x00" * (self.PLAIN_BLOCK_SIZE * self.BLOCKS_PER_GROUP - blocks)
|
||||
data += b"\x00" * (self.PLAIN_BLOCK_SIZE * self.BLOCKS_PER_GROUP - blocks)
|
||||
else:
|
||||
raise ValueError("Attempted to write group past the end of the partition data")
|
||||
else:
|
||||
@ -930,12 +925,12 @@ class WiiPartition:
|
||||
|
||||
h0 = []
|
||||
h1 = []
|
||||
h2 = ""
|
||||
h2 = b""
|
||||
for subgroup in range(self.SUBGROUPS_PER_GROUP):
|
||||
bh1 = ""
|
||||
bh1 = b""
|
||||
sh0 = []
|
||||
for block in range(self.BLOCKS_PER_SUBGROUP):
|
||||
bh0 = ""
|
||||
bh0 = b""
|
||||
for chunk in range(self.DATA_CHUNKS_PER_BLOCK):
|
||||
offset = subgroup * self.PLAIN_SUBGROUP_SIZE + block * self.PLAIN_BLOCK_SIZE + chunk * self.DATA_CHUNK_SIZE
|
||||
bh0 += SHA.new(data[offset:offset+self.DATA_CHUNK_SIZE]).digest()
|
||||
@ -946,16 +941,16 @@ class WiiPartition:
|
||||
h2 += SHA.new(bh1).digest()
|
||||
h3 = SHA.new(h2).digest()
|
||||
|
||||
data_out = ""
|
||||
data_out = b""
|
||||
for subgroup in range(self.SUBGROUPS_PER_GROUP):
|
||||
for block in range(self.BLOCKS_PER_SUBGROUP):
|
||||
shablock = ""
|
||||
shablock += h0[subgroup][block]
|
||||
shablock += "\x00"*20
|
||||
shablock += b"\x00"*20
|
||||
shablock += h1[subgroup]
|
||||
shablock += "\x00"*32
|
||||
shablock += b"\x00"*32
|
||||
shablock += h2
|
||||
shablock += "\x00"*32
|
||||
shablock += b"\x00"*32
|
||||
assert len(shablock) == self.SHA_SIZE, "sha block size messed up"
|
||||
aes = AES.new(self.tik.title_key, AES.MODE_CBC, NULL_IV)
|
||||
shablock = aes.encrypt(shablock)
|
||||
@ -1019,7 +1014,7 @@ class WiiCachedPartition(WiiPartition):
|
||||
|
||||
def _dprint(self, s, *args):
|
||||
if self.debug:
|
||||
print s%tuple(args)
|
||||
print(s%tuple(args))
|
||||
|
||||
def _readblock(self, blocknum):
|
||||
self._dprint("_readblock(0x%x)",blocknum)
|
||||
@ -1174,7 +1169,7 @@ class WiiCachedPartition(WiiPartition):
|
||||
hb = self.readblock(bstart - 1)
|
||||
hb = hb[:hdroff] + data[:header] + hb[hdroff+header:]
|
||||
self.writeblock(bstart - 1, hb)
|
||||
for block in xrange(bnum):
|
||||
for block in range(bnum):
|
||||
self.writeblock(block+bstart, data[header+block*self.PLAIN_BLOCK_SIZE:header+(block+1)*self.PLAIN_BLOCK_SIZE])
|
||||
if footer:
|
||||
fb = self.readblock(bstart+bnum)
|
||||
@ -1246,11 +1241,11 @@ class WiiApploader:
|
||||
self.extrafooter = data[0x20+self.textsize+self.trailersize:]
|
||||
|
||||
def showinfo(self, it=""):
|
||||
print it+"Apploader:"
|
||||
print it+" Date: %s"%self.date
|
||||
print it+" Entrypoint: 0x%08x"%self.entry
|
||||
print it+" Text size: 0x%x"%self.textsize
|
||||
print it+" Trailer size: 0x%x"%self.trailersize
|
||||
print(it+"Apploader:")
|
||||
print(it+" Date: %s"%self.date)
|
||||
print(it+" Entrypoint: 0x%08x"%self.entry)
|
||||
print(it+" Text size: 0x%x"%self.textsize)
|
||||
print(it+" Trailer size: 0x%x"%self.trailersize)
|
||||
|
||||
class WiiPartitionData:
|
||||
def __init__(self, partition):
|
||||
@ -1291,11 +1286,11 @@ class WiiPartitionData:
|
||||
self.dol = dol
|
||||
self.part.write(self.doloff, dol)
|
||||
def showinfo(self,it=""):
|
||||
print it+"Partition data:"
|
||||
print it+" Game Name: %s"%self.gamename
|
||||
print it+" Offsets: DOL @ 0x%x [0x%x], Apploader @ 0x%x [0x%x], FST @ 0x%x [0x%x]"%(self.doloff, self.dolsize, 0x2440, self.apploadersize, self.fstoff, self.fstsize)
|
||||
print(it+"Partition data:")
|
||||
print(it+" Game Name: %s"%self.gamename)
|
||||
print(it+" Offsets: DOL @ 0x%x [0x%x], Apploader @ 0x%x [0x%x], FST @ 0x%x [0x%x]"%(self.doloff, self.dolsize, 0x2440, self.apploadersize, self.fstoff, self.fstsize))
|
||||
self.apploader.showinfo(it+" ")
|
||||
print it+"FST:"
|
||||
print(it+"FST:")
|
||||
self.fst.show(it+" ")
|
||||
|
||||
class FakeFile:
|
||||
@ -1381,7 +1376,7 @@ class WiiWad:
|
||||
|
||||
self.f.seek(4)
|
||||
wt = self.f.read(2)
|
||||
if wt == "\x00\x00":
|
||||
if wt == b"\x00\x00":
|
||||
self.read_boot2hdr()
|
||||
else:
|
||||
self.read_hdr()
|
||||
@ -1389,7 +1384,7 @@ class WiiWad:
|
||||
certdata = self.f.read(self.cert_len)
|
||||
self.certlist = []
|
||||
self.certs = {}
|
||||
while certdata != "":
|
||||
while certdata != b"":
|
||||
cert = WiiCert(certdata)
|
||||
self.certs[cert.name] = cert
|
||||
self.certlist.append(cert)
|
||||
@ -1415,8 +1410,8 @@ class WiiWad:
|
||||
self.f.write(self.tik.data)
|
||||
|
||||
def showinfo(self,it=""):
|
||||
print it+"Wii Wad:"
|
||||
print it+" Header 0x%x Type %s Certs 0x%x Tik 0x%x TMD 0x%x Data 0x%x @ 0x%x Footer 0x%x"%(self.hdr_len, repr(self.wadtype), self.cert_len, self.tik_len, self.tmd_len, self.data_len, self.data_off, self.footer_len)
|
||||
print(it+"Wii Wad:")
|
||||
print(it+" Header 0x%x Type %s Certs 0x%x Tik 0x%x TMD 0x%x Data 0x%x @ 0x%x Footer 0x%x"%(self.hdr_len, repr(self.wadtype), self.cert_len, self.tik_len, self.tmd_len, self.data_len, self.data_off, self.footer_len))
|
||||
self.tik.showinfo(it+" ")
|
||||
self.tik.showsig(self.certs,it+" ")
|
||||
self.tmd.showinfo(it+" ")
|
||||
@ -1426,15 +1421,15 @@ class WiiWad:
|
||||
d = self.getcontent(ct.index)
|
||||
sha = SHA.new(d).digest()
|
||||
if sha != ct.sha:
|
||||
print it+" SHA-1 for content %08x is invalid:"%ct.cid, hexdump(sha)
|
||||
print it+" Expected:",hexdump(ct.sha)
|
||||
print(it+" SHA-1 for content %08x is invalid:"%ct.cid, hexdump(sha))
|
||||
print(it+" Expected:",hexdump(ct.sha))
|
||||
allok=False
|
||||
if allok:
|
||||
print it+" All content SHA-1 hashes are valid"
|
||||
print(it+" All content SHA-1 hashes are valid")
|
||||
self.showcerts(it+" ")
|
||||
|
||||
def showcerts(self,it=""):
|
||||
print it+"Certificates: "
|
||||
print(it+"Certificates: ")
|
||||
for cert in self.certlist:
|
||||
cert.showinfo(it+" - ")
|
||||
cert.showsig(self.certs,it+" ")
|
||||
@ -1447,7 +1442,7 @@ class WiiWad:
|
||||
if encrypted:
|
||||
return data
|
||||
|
||||
iv = pack(">H",index)+"\x00"*14
|
||||
iv = pack(">H",index)+b"\x00"*14
|
||||
aes = AES.new(self.tik.title_key, AES.MODE_CBC, iv)
|
||||
return aes.decrypt(data)[:ct.size]
|
||||
|
||||
@ -1470,14 +1465,14 @@ class WiiWadMaker(WiiWad):
|
||||
self.tik_len = len(self.tik.data)
|
||||
|
||||
# if boot2, set type to "ib"
|
||||
if self.tmd.title_id == "\x00\x00\x00\x01\x00\x00\x00\x01":
|
||||
if self.tmd.title_id == b"\x00\x00\x00\x01\x00\x00\x00\x01":
|
||||
if nandwad:
|
||||
self.wadtype = 0
|
||||
self.ALIGNMENT = 0
|
||||
else:
|
||||
self.wadtype = "ib"
|
||||
self.wadtype = b"ib"
|
||||
else:
|
||||
self.wadtype = "Is"
|
||||
self.wadtype = b"Is"
|
||||
|
||||
self.data_len = 0
|
||||
self.footer = footer
|
||||
@ -1509,16 +1504,16 @@ class WiiWadMaker(WiiWad):
|
||||
cr.size = len(data)
|
||||
self.tmd.update_content_record(i,cr)
|
||||
if len(data)%16 != 0:
|
||||
data += "\x00"*(16-len(data)%16)
|
||||
data += b"\x00"*(16-len(data)%16)
|
||||
falign(self.f,0x40)
|
||||
iv = pack(">H",cr.index)+"\x00"*14
|
||||
iv = pack(">H",cr.index)+b"\x00"*14
|
||||
aes = AES.new(self.tik.title_key, AES.MODE_CBC, iv)
|
||||
self.f.write(aes.encrypt(data))
|
||||
falign(self.f,0x40)
|
||||
|
||||
def adddata_encrypted(self, data):
|
||||
if len(data)%16 != 0:
|
||||
data += "\x00"*(16-len(data)%16)
|
||||
data += b"\x00"*(16-len(data)%16)
|
||||
falign(self.f,0x40)
|
||||
self.f.write(data)
|
||||
falign(self.f,0x40)
|
||||
@ -1531,7 +1526,7 @@ class WiiWadMaker(WiiWad):
|
||||
falign(self.f,self.ALIGNMENT)
|
||||
self.f.truncate()
|
||||
if pad:
|
||||
self.f.write("\x00"*0x40)
|
||||
self.f.write(b"\x00"*0x40)
|
||||
self.updatetmd()
|
||||
self.f.seek(0)
|
||||
if self.wadtype == 0:
|
||||
@ -1641,9 +1636,9 @@ class WiiFSTFile:
|
||||
self.off = off
|
||||
self.size = size
|
||||
def show(self, it=""):
|
||||
print "%s%s @ 0x%x [0x%x]"%(it,self.name,self.off,self.size)
|
||||
print("%s%s @ 0x%x [0x%x]"%(it,self.name,self.off,self.size))
|
||||
def generate(self, offset, stringoff, parent, dataoff, wiigcm=False):
|
||||
stringdata = self.name + "\x00"
|
||||
stringdata = self.name.encode("ascii") + b"\x00"
|
||||
off = self.off+dataoff
|
||||
if wiigcm:
|
||||
off >>= 2
|
||||
@ -1688,9 +1683,9 @@ class WiiFSTDir:
|
||||
raise ValueError("WTF")
|
||||
def show(self, it=""):
|
||||
if self.name == "":
|
||||
print it+"/"
|
||||
print(it+"/")
|
||||
else:
|
||||
print it+self.name+"/"
|
||||
print(it+self.name+"/")
|
||||
for i in self.entries:
|
||||
i.show(it+self.name+"/")
|
||||
def dump(self):
|
||||
@ -1698,15 +1693,15 @@ class WiiFSTDir:
|
||||
def add(self,x):
|
||||
self.entries.append(x)
|
||||
def generate(self, offset, stringoff, parent, dataoff, wiigcm=False):
|
||||
stringdata = self.name + "\x00"
|
||||
stringdata = self.name.encode("ascii") + b"\x00"
|
||||
myoff = offset
|
||||
mysoff = stringoff
|
||||
stringoff+=len(stringdata)
|
||||
offset += 1
|
||||
subdata=""
|
||||
subdata=b""
|
||||
for e in self.entries:
|
||||
d, s = e.generate(offset, stringoff, myoff, dataoff, wiigcm)
|
||||
offset += len(d)/12
|
||||
offset += len(d)//12
|
||||
stringoff += len(s)
|
||||
stringdata += s
|
||||
subdata += d
|
||||
|
@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import re
|
||||
import pywii as wii
|
||||
|
||||
hash = wii.SHA.new(open(sys.argv[2]).read()).digest().encode("hex")
|
||||
f = open(sys.argv[1], "r")
|
||||
f = open(sys.argv[1], "rb")
|
||||
data = f.read()
|
||||
f.close()
|
||||
data = re.sub('@SHA1SUM@', hash, data)
|
||||
open(sys.argv[3], "w").write(data)
|
||||
open(sys.argv[3], "wb").write(data)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path, struct
|
||||
import pywii as wii
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path, struct
|
||||
import pywii as wii
|
||||
@ -7,20 +7,24 @@ fstb = wii.WiiFSTBuilder(0x20)
|
||||
|
||||
fstb.addfrom(sys.argv[2])
|
||||
|
||||
arc = open(sys.argv[1],"wb")
|
||||
# dummy generate to get length
|
||||
fstlen = len(fstb.fst.generate())
|
||||
dataoff = wii.align(0x20+fstlen,0x20)
|
||||
fst = fstb.fst.generate(dataoff)
|
||||
try:
|
||||
arc = open(sys.argv[1],"wb")
|
||||
# dummy generate to get length
|
||||
fstlen = len(fstb.fst.generate())
|
||||
dataoff = wii.align(0x20+fstlen,0x20)
|
||||
fst = fstb.fst.generate(dataoff)
|
||||
|
||||
hdr = struct.pack(">IIII16x",0x55AA382d,0x20,fstlen,dataoff)
|
||||
arc.write(hdr)
|
||||
hdr = struct.pack(">IIII16x",0x55AA382d,0x20,fstlen,dataoff)
|
||||
arc.write(hdr)
|
||||
|
||||
arc.write(fst)
|
||||
wii.falign(arc,0x20)
|
||||
for f in fstb.files:
|
||||
data = open(f, "rb").read()
|
||||
arc.write(data)
|
||||
arc.write(fst)
|
||||
wii.falign(arc,0x20)
|
||||
for f in fstb.files:
|
||||
data = open(f, "rb").read()
|
||||
arc.write(data)
|
||||
wii.falign(arc,0x20)
|
||||
|
||||
arc.close()
|
||||
arc.close()
|
||||
except:
|
||||
os.remove(sys.argv[1])
|
||||
raise
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -15,12 +15,12 @@ certfile = args.pop(0)
|
||||
|
||||
certs, certlist = wii.parse_certs(open(args.pop(0), "rb").read())
|
||||
|
||||
print "Certification file %s: " % certfile
|
||||
print("Certification file %s: " % certfile)
|
||||
cert = wii.WiiCert(open(certfile, "rb").read())
|
||||
cert.showinfo(" ")
|
||||
cert.showsig(certs," ")
|
||||
|
||||
print "Certificates:"
|
||||
print("Certificates:")
|
||||
for cert in certlist:
|
||||
cert.showinfo(" - ")
|
||||
cert.showsig(certs," ")
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -11,7 +11,7 @@ disc.showinfo()
|
||||
|
||||
partitions = disc.read_partitions()
|
||||
|
||||
parts = range(len(partitions))
|
||||
parts = list(range(len(partitions)))
|
||||
|
||||
try:
|
||||
pnum = int(sys.argv[2])
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii
|
||||
@ -17,7 +17,7 @@ if sys.argv[1] == "-cetk":
|
||||
elif sys.argv[1] == "-tmd":
|
||||
signed = pywii.WiiTmd(open(infile, "rb").read())
|
||||
else:
|
||||
print "EYOUFAILIT"
|
||||
print("EYOUFAILIT")
|
||||
sys.exit(1)
|
||||
|
||||
certs, certlist = pywii.parse_certs(open(certfile).read())
|
||||
@ -25,11 +25,11 @@ certs, certlist = pywii.parse_certs(open(certfile).read())
|
||||
signed.update_issuer(issuer)
|
||||
|
||||
if not signed.sign(certs):
|
||||
print "dpki signing failed"
|
||||
print("dpki signing failed")
|
||||
sys.exit(1)
|
||||
|
||||
open(outfile, "wb").write(signed.data)
|
||||
|
||||
print "successfully signed %s" % outfile
|
||||
print("successfully signed %s" % outfile)
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import pywii as wii
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print "Usage: %s keyfile.[priv|pub] infile"%sys.argv[0]
|
||||
print("Usage: %s keyfile.[priv|pub] infile"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
if sys.argv[1] == "-":
|
||||
@ -12,46 +12,46 @@ if sys.argv[1] == "-":
|
||||
else:
|
||||
k = open(sys.argv[1],"rb").read()
|
||||
if len(k) not in (30,60):
|
||||
print "Failed to read key"
|
||||
print("Failed to read key")
|
||||
sys.exit(2)
|
||||
|
||||
if len(k) == 30:
|
||||
print "Key is a private key, generating public key..."
|
||||
print("Key is a private key, generating public key...")
|
||||
q = wii.ec.priv_to_pub(k)
|
||||
else:
|
||||
q = k
|
||||
|
||||
print "Public key:"
|
||||
print("Public key:")
|
||||
pq = q.encode('hex')
|
||||
print "X =",pq[:30]
|
||||
print " ",pq[30:60]
|
||||
print "Y =",pq[60:90]
|
||||
print " ",pq[90:]
|
||||
print
|
||||
print("X =",pq[:30])
|
||||
print(" ",pq[30:60])
|
||||
print("Y =",pq[60:90])
|
||||
print(" ",pq[90:])
|
||||
print()
|
||||
|
||||
indata = open(sys.argv[2],"rb").read()
|
||||
|
||||
if len(indata) < 64 or indata[:4] != "SIG0":
|
||||
print "Invalid header"
|
||||
print("Invalid header")
|
||||
sys.exit(3)
|
||||
|
||||
r = indata[4:34]
|
||||
s = indata[34:64]
|
||||
|
||||
sha = wii.SHA.new(indata[64:]).digest()
|
||||
print "SHA1: %s"%sha.encode('hex')
|
||||
print("SHA1: %s"%sha.encode('hex'))
|
||||
|
||||
print
|
||||
print "Signature:"
|
||||
print "R =",r[:15].encode('hex')
|
||||
print " ",r[15:].encode('hex')
|
||||
print "S =",s[:15].encode('hex')
|
||||
print " ",s[15:].encode('hex')
|
||||
print
|
||||
print()
|
||||
print("Signature:")
|
||||
print("R =",r[:15].encode('hex'))
|
||||
print(" ",r[15:].encode('hex'))
|
||||
print("S =",s[:15].encode('hex'))
|
||||
print(" ",s[15:].encode('hex'))
|
||||
print()
|
||||
|
||||
if wii.ec.check_ecdsa(q,r,s,sha):
|
||||
print "Signature is VALID"
|
||||
print("Signature is VALID")
|
||||
else:
|
||||
print "Signature is INVALID"
|
||||
print("Signature is INVALID")
|
||||
sys.exit(4)
|
||||
|
||||
|
@ -1,33 +1,33 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os
|
||||
import pywii as wii
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage: %s keyfile.priv"%sys.argv[0]
|
||||
print("Usage: %s keyfile.priv"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
print "Generating private key..."
|
||||
print("Generating private key...")
|
||||
|
||||
k = wii.ec.gen_priv_key()
|
||||
|
||||
print "Private key:"
|
||||
print("Private key:")
|
||||
pk = k.encode('hex')
|
||||
print "K =",pk[:30]
|
||||
print " ",pk[30:]
|
||||
print("K =",pk[:30])
|
||||
print(" ",pk[30:])
|
||||
|
||||
print
|
||||
print "Corresponding public key:"
|
||||
print()
|
||||
print("Corresponding public key:")
|
||||
q = wii.ec.priv_to_pub(k)
|
||||
pq = q.encode('hex')
|
||||
print "X =",pq[:30]
|
||||
print " ",pq[30:60]
|
||||
print "Y =",pq[60:90]
|
||||
print " ",pq[90:]
|
||||
print("X =",pq[:30])
|
||||
print(" ",pq[30:60])
|
||||
print("Y =",pq[60:90])
|
||||
print(" ",pq[90:])
|
||||
|
||||
fd = open(sys.argv[1],"wb")
|
||||
os.fchmod(fd.fileno(), 0o600)
|
||||
fd.write(k)
|
||||
fd.close()
|
||||
|
||||
print "Saved private key to %s"%sys.argv[1]
|
||||
print("Saved private key to %s"%sys.argv[1])
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import pywii as wii
|
||||
|
||||
if len(sys.argv) not in (2,3):
|
||||
print "Usage: %s keyfile.priv [keyfile.pub]"%sys.argv[0]
|
||||
print("Usage: %s keyfile.priv [keyfile.pub]"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
if sys.argv[1] == "-":
|
||||
@ -12,19 +12,19 @@ if sys.argv[1] == "-":
|
||||
else:
|
||||
k = open(sys.argv[1],"rb").read()
|
||||
if len(k) != 30:
|
||||
print "Failed to read private key"
|
||||
print("Failed to read private key")
|
||||
sys.exit(2)
|
||||
|
||||
print "Public key:"
|
||||
print("Public key:")
|
||||
q = wii.ec.priv_to_pub(k)
|
||||
pq = q.encode('hex')
|
||||
print "X =",pq[:30]
|
||||
print " ",pq[30:60]
|
||||
print "Y =",pq[60:90]
|
||||
print " ",pq[90:]
|
||||
print("X =",pq[:30])
|
||||
print(" ",pq[30:60])
|
||||
print("Y =",pq[60:90])
|
||||
print(" ",pq[90:])
|
||||
|
||||
if len(sys.argv) == 3:
|
||||
fd = open(sys.argv[2],"wb")
|
||||
fd.write(q)
|
||||
fd.close()
|
||||
print "Saved public key to %s"%sys.argv[2]
|
||||
print("Saved public key to %s"%sys.argv[2])
|
||||
|
@ -1,10 +1,9 @@
|
||||
#!/usr/bin/env python2
|
||||
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import pywii as wii
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
print "Usage: %s keyfile.priv infile outfile"%sys.argv[0]
|
||||
print("Usage: %s keyfile.priv infile outfile"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
if sys.argv[1] == "-":
|
||||
@ -13,20 +12,20 @@ else:
|
||||
k = open(sys.argv[1],"rb").read()
|
||||
|
||||
if len(k) != 30:
|
||||
print "Failed to read private key"
|
||||
print("Failed to read private key")
|
||||
sys.exit(2)
|
||||
|
||||
indata = open(sys.argv[2],"rb").read()
|
||||
sha = wii.SHA.new(indata).digest()
|
||||
|
||||
print "SHA1: %s"%sha.encode('hex')
|
||||
print
|
||||
print "Signature:"
|
||||
print("SHA1: %s"%sha.encode('hex'))
|
||||
print()
|
||||
print("Signature:")
|
||||
r,s = wii.ec.generate_ecdsa(k,sha)
|
||||
print "R =",r[:15].encode('hex')
|
||||
print " ",r[15:].encode('hex')
|
||||
print "S =",s[:15].encode('hex')
|
||||
print " ",s[15:].encode('hex')
|
||||
print("R =",r[:15].encode('hex'))
|
||||
print(" ",r[15:].encode('hex'))
|
||||
print("S =",s[:15].encode('hex'))
|
||||
print(" ",s[15:].encode('hex'))
|
||||
|
||||
outdata = "SIG0" + r + s + indata
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -11,8 +11,8 @@ def parseint(d):
|
||||
return int(d)
|
||||
|
||||
if len(sys.argv) < 4 or len(sys.argv) > 7:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <file to extract to> [Partition offset] [length]"%sys.argv[0]
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <file to extract to> [Partition offset] [length]"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, data_name = sys.argv[1:4]
|
||||
@ -27,19 +27,19 @@ if len(sys.argv) == 6:
|
||||
copy_length = parseint(sys.argv[5])
|
||||
|
||||
if copy_length is not None and copy_length < 0:
|
||||
print "Error: negative copy length"
|
||||
print("Error: negative copy length")
|
||||
sys.exit(1)
|
||||
|
||||
disc = wii.WiiDisc(iso_name)
|
||||
disc.showinfo()
|
||||
part = wii.WiiCachedPartition(disc, partno, cachesize=32, debug=False, checkhash=False)
|
||||
if part_offset >= part.data_bytes:
|
||||
print "Error: Offset past end of partition"
|
||||
print("Error: Offset past end of partition")
|
||||
sys.exit(1)
|
||||
if copy_length is None:
|
||||
copy_length = part.data_bytes - part_offset
|
||||
if copy_length > (part.data_bytes - part_offset):
|
||||
print "Error: Length too large"
|
||||
print("Error: Length too large")
|
||||
sys.exit(1)
|
||||
|
||||
dataf = open(data_name, "wb")
|
||||
@ -49,7 +49,7 @@ while left > 0:
|
||||
blocklen = min(left, 4*1024*1024)
|
||||
d = part.read(offset, blocklen)
|
||||
if len(d) != blocklen:
|
||||
print "Part EOF reached!"
|
||||
print("Part EOF reached!")
|
||||
sys.exit(1)
|
||||
dataf.write(d)
|
||||
offset += blocklen
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/python3
|
||||
|
||||
import sys, os, os.path
|
||||
sys.path.append(os.path.realpath(os.path.dirname(sys.argv[0]))+"/../Common")
|
||||
@ -7,8 +7,8 @@ import pywii as wii
|
||||
wii.loadkeys(os.environ["HOME"]+os.sep+".wii")
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <dol output>"%sys.argv[0]
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <dol output>"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, dol_name = sys.argv[1:4]
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -11,8 +11,8 @@ def parseint(d):
|
||||
return int(d)
|
||||
|
||||
if len(sys.argv) < 4 or len(sys.argv) > 7:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <root path to extract to> "%sys.argv[0]
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <root path to extract to> "%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, data_name = sys.argv[1:4]
|
||||
@ -27,19 +27,19 @@ if len(sys.argv) == 6:
|
||||
copy_length = parseint(sys.argv[5])
|
||||
|
||||
if copy_length is not None and copy_length < 0:
|
||||
print "Error: negative copy length"
|
||||
print("Error: negative copy length")
|
||||
sys.exit(1)
|
||||
|
||||
disc = wii.WiiDisc(iso_name)
|
||||
disc.showinfo()
|
||||
part = wii.WiiCachedPartition(disc, partno, cachesize=32, debug=False, checkhash=False)
|
||||
if part_offset >= part.data_bytes:
|
||||
print "Error: Offset past end of partition"
|
||||
print("Error: Offset past end of partition")
|
||||
sys.exit(1)
|
||||
if copy_length is None:
|
||||
copy_length = part.data_bytes - part_offset
|
||||
if copy_length > (part.data_bytes - part_offset):
|
||||
print "Error: Length too large"
|
||||
print("Error: Length too large")
|
||||
sys.exit(1)
|
||||
|
||||
dataf = open(data_name, "wb")
|
||||
@ -49,7 +49,7 @@ while left > 0:
|
||||
blocklen = min(left, 4*1024*1024)
|
||||
d = part.read(offset, blocklen)
|
||||
if len(d) != blocklen:
|
||||
print "Part EOF reached!"
|
||||
print("Part EOF reached!")
|
||||
sys.exit(1)
|
||||
dataf.write(d)
|
||||
offset += blocklen
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -6,8 +6,8 @@ import pywii as wii
|
||||
wii.loadkeys()
|
||||
|
||||
if len(sys.argv) != 5:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <apploader text> <apploader trailer>"%sys.argv[0]
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <apploader text> <apploader trailer>"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, app_name, trail_name = sys.argv[1:5]
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -11,8 +11,8 @@ def parseint(d):
|
||||
return int(d)
|
||||
|
||||
if len(sys.argv) < 4 or len(sys.argv) > 7:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <file to inject> [Partition offset] [data offset] [length]"%sys.argv[0]
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <file to inject> [Partition offset] [data offset] [length]"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, data_name = sys.argv[1:4]
|
||||
@ -34,10 +34,10 @@ if copy_length == None:
|
||||
copy_length = data_len - data_offset
|
||||
copy_end = data_offset + copy_length
|
||||
if copy_length < 0:
|
||||
print "Error: negative copy length"
|
||||
print("Error: negative copy length")
|
||||
sys.exit(1)
|
||||
if copy_end > data_len:
|
||||
print "Error: data file is too small"
|
||||
print("Error: data file is too small")
|
||||
sys.exit(1)
|
||||
|
||||
disc = wii.WiiDisc(iso_name)
|
||||
@ -52,7 +52,7 @@ while left > 0:
|
||||
blocklen = min(left, 4*1024*1024)
|
||||
d = dataf.read(blocklen)
|
||||
if len(d) != blocklen:
|
||||
print "File EOF reached!"
|
||||
print("File EOF reached!")
|
||||
sys.exit(1)
|
||||
part.write(offset, d)
|
||||
offset += blocklen
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -6,8 +6,8 @@ import pywii as wii
|
||||
wii.loadkeys()
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <dol to inject>"%sys.argv[0]
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <dol to inject>"%sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, dol_name = sys.argv[1:4]
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -6,9 +6,9 @@ import pywii as wii
|
||||
wii.loadkeys()
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
print "Usage:"
|
||||
print " python %s <encrypted ISO> <partition number> <IOS version>"%sys.argv[0]
|
||||
print " IOS version should be just the minor number (16, 33, etc) in decimal"
|
||||
print("Usage:")
|
||||
print(" python %s <encrypted ISO> <partition number> <IOS version>"%sys.argv[0])
|
||||
print(" IOS version should be just the minor number (16, 33, etc) in decimal")
|
||||
sys.exit(1)
|
||||
|
||||
iso_name, partno, ios = sys.argv[1:4]
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
|
||||
def hexdump(s):
|
||||
return ' '.join(map(lambda x: "%02x"%x,map(ord,s)))
|
||||
return ' '.join(["%02x"%x for x in list(map(ord,s))])
|
||||
|
||||
isofile = sys.argv[1]
|
||||
disc = WiiDisc(isofile)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -6,7 +6,7 @@ import pywii as wii
|
||||
wii.loadkeys()
|
||||
|
||||
tikfile = sys.argv[1]
|
||||
print "fixing Tik file %s " % tikfile
|
||||
print("fixing Tik file %s " % tikfile)
|
||||
tik = wii.WiiTik(open(tikfile, "rb").read())
|
||||
tik.null_signature()
|
||||
tik.brute_sha()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -17,12 +17,12 @@ certs = None
|
||||
if len(args) > 0:
|
||||
certs, certlist = wii.parse_certs(open(args.pop(0), "rb").read())
|
||||
|
||||
print "ETicket file %s:"%tikfile
|
||||
print("ETicket file %s:"%tikfile)
|
||||
tik = wii.WiiTik(open(tikfile, "rb").read())
|
||||
tik.showinfo(" ")
|
||||
if certs is not None:
|
||||
tik.showsig(certs," ")
|
||||
print "Certificates:"
|
||||
print("Certificates:")
|
||||
for cert in certlist:
|
||||
cert.showinfo(" - ")
|
||||
cert.showsig(certs," ")
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -6,7 +6,7 @@ import pywii as wii
|
||||
wii.loadkeys()
|
||||
|
||||
tmdfile = sys.argv[1]
|
||||
print "TMD file %s:"%tmdfile
|
||||
print("TMD file %s:"%tmdfile)
|
||||
tmd = wii.WiiTmd(open(tmdfile, "rb").read())
|
||||
tmd.null_signature()
|
||||
tmd.brute_sha()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -17,12 +17,12 @@ certs = None
|
||||
if len(args) > 0:
|
||||
certs, certlist = wii.parse_certs(open(args.pop(0), "rb").read())
|
||||
|
||||
print "TMD file %s:"%tmdfile
|
||||
print("TMD file %s:"%tmdfile)
|
||||
tmd = wii.WiiTmd(open(tmdfile, "rb").read())
|
||||
tmd.showinfo(" ")
|
||||
if certs is not None:
|
||||
tmd.showsig(certs," ")
|
||||
print "Certificates:"
|
||||
print("Certificates:")
|
||||
for cert in certlist:
|
||||
cert.showinfo(" - ")
|
||||
cert.showsig(certs," ")
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -14,7 +14,7 @@ args = sys.argv[1:]
|
||||
tmdfile = args.pop(0)
|
||||
indir = args.pop(0)
|
||||
|
||||
print "updating content records of TMD file %s" % tmdfile
|
||||
print("updating content records of TMD file %s" % tmdfile)
|
||||
tmd = wii.WiiTmd(open(tmdfile, "rb").read())
|
||||
|
||||
for i, cr in enumerate(tmd.get_content_records()):
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
@ -14,7 +14,7 @@ if len(args) == 2:
|
||||
else:
|
||||
newvers = int(args.pop(0), 16)
|
||||
|
||||
print "setting version of TMD file %s to 0x%04x" % (tmdfile, newvers)
|
||||
print("setting version of TMD file %s to 0x%04x" % (tmdfile, newvers))
|
||||
tmd = wii.WiiTmd(open(tmdfile, "rb").read())
|
||||
tmd.title_version = newvers
|
||||
tmd.update()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, os.path
|
||||
import pywii as wii
|
||||
|
Loading…
Reference in New Issue
Block a user