Merge branch 'master' of git@github.com:icefire/Wii.py

This commit is contained in:
Giuseppe (LemonBoy) 2009-06-23 12:17:48 +02:00
commit f35b0041a6
2 changed files with 251 additions and 8 deletions

18
TPL.py
View File

@ -82,7 +82,7 @@ class TPL():
else: else:
self.file = None self.file = None
self.data = file self.data = file
def toTPL(self, outfile, width = 0, height = 0, format="RGBA8"): #single texture only def toTPL(self, outfile, (width, height) = (None, None), format = "RGBA8"): #single texture only
"""This converts a PNG image into a TPL. The PNG image is specified as the file parameter to the class initializer, while the output filename is specified here as the parameter outfile. Width and height are optional parameters and specify the size to resize the image to, if needed. Returns the output filename. """This converts a PNG image into a TPL. The PNG image is specified as the file parameter to the class initializer, while the output filename is specified here as the parameter outfile. Width and height are optional parameters and specify the size to resize the image to, if needed. Returns the output filename.
This only can create TPL images with a single texture.""" This only can create TPL images with a single texture."""
@ -97,8 +97,8 @@ class TPL():
img = Image.open(self.file) img = Image.open(self.file)
theWidth, theHeight = img.size theWidth, theHeight = img.size
if(width !=0 and height != 0 and (width != theWidth or height != theHeight)): if(width != None and height != None and (width != theWidth or height != theHeight)):
img.resize(width, height) img = img.resize((width, height), Image.ANTIALIAS)
w, h = img.size w, h = img.size
texhead = self.TPLTextureHeader() texhead = self.TPLTextureHeader()
@ -145,6 +145,7 @@ class TPL():
''' ADD toCMP ''' ''' ADD toCMP '''
raise Exception("toCMP not done") raise Exception("toCMP not done")
#tpldata = self.toCMP((w, h), img) #tpldata = self.toCMP((w, h), img)
texhead.data_off = 0x14 + len(texhead) texhead.data_off = 0x14 + len(texhead)
texhead.wrap = [0, 0] texhead.wrap = [0, 0]
texhead.filter = [1, 1] texhead.filter = [1, 1]
@ -187,7 +188,6 @@ class TPL():
f.close() f.close()
return outfile return outfile
def toI4(self, (w, h), img): def toI4(self, (w, h), img):
out = [0 for i in range(align(w, 4) * align(h, 4) / 2)] out = [0 for i in range(align(w, 4) * align(h, 4) / 2)]
outp = 0 outp = 0
@ -510,13 +510,15 @@ class TPL():
class imp(wx.Panel): class imp(wx.Panel):
def __init__(self, parent, id, im): def __init__(self, parent, id, im):
wx.Panel.__init__(self, parent, id) wx.Panel.__init__(self, parent, id)
w, h = im.size w = img.GetWidth()
h = img.GetHeight()
wx.StaticBitmap(self, -1, im, ( ((max(w, 300) - w) / 2), ((max(h, 200) - h) / 2) ), (w, h)) wx.StaticBitmap(self, -1, im, ( ((max(w, 300) - w) / 2), ((max(h, 200) - h) / 2) ), (w, h))
self.toImage("tmp.png") self.toImage("tmp.png")
img = Image.open("tmp.png") img = wx.Image("tmp.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
w, h = img.size w = img.GetWidth()
app = wx.App(redirect = True) h = img.GetHeight()
app = wx.App(redirect = False)
frame = wx.Frame(None, -1, "TPL (" + str(w) + ", " + str(h) + ")", size = (max(w, 300), max(h, 200))) frame = wx.Frame(None, -1, "TPL (" + str(w) + ", " + str(h) + ")", size = (max(w, 300), max(h, 200)))
image = imp(frame, -1, img) image = imp(frame, -1, img)
frame.Show(True) frame.Show(True)

View File

@ -300,6 +300,247 @@ class CONF:
"""sets the Serial Number key. (Shortcut for setKeyValue("SERNO", value))""" """sets the Serial Number key. (Shortcut for setKeyValue("SERNO", value))"""
return self.setKeyValue("SERNO", value) return self.setKeyValue("SERNO", value)
class netConfig:
"""This class performs network configuration. The file is located on the NAND at /shared2/sys/net/02/config.dat."""
class configEntry(Struct):
__endian__ = Struct.BE
def __format__(self):
self.selected = Struct.uint8
self.padding_1 = Struct.string(1987)
self.ssid = Struct.string(32)
self.padding_2 = Struct.uint8
self.ssid_len = Struct.uint8
self.padding_3 = Struct.string(2)
self.padding_4 = Struct.uint8
self.encryption = Struct.uint8 # OPEN: 0x00, WEP: 0x01, WPA-PSK (TKIP): 0x04, WPA2-PSK (AES): 0x05, WPA-PSK (AES): 0x06
self.padding_5 = Struct.string(2)
self.padding_6 = Struct.uint8
self.key_len = Struct.uint8
self.padding_7 = Struct.string(2)
self.key = Struct.string(64)
self.padding_3 = Struct.string(236)
def __init__(self, conf):
self.f = conf
if(not os.path.isfile(self.f)):
fp = open(self.f, "wb")
fp.write("\x00\x00\x00\x00\x01\x07\x00\x00")
fp.write("\x00" * 0x91C * 3)
fp.close()
fp = open(self.f, "rb")
head = fp.read(8)
if(head != "\x00\x00\x00\x00\x01\x07\x00\x00"):
print("Config file is invalid!\n")
def getNotBlank(self, config):
fp = open(self.f, "rb")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
fp.close()
if(sel & 0x20):
return 1
return 0
def getIPType(self, config):
if(not self.getNotBlank(config)):
return None
fp = open(self.f, "rb")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
if(sel & 0x04):
return 0
else:
return 1
fp.close()
return sel
def getWireType(self, config):
if(not self.getNotBlank(config)):
return None
fp = open(self.f, "rb")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
if(sel & 0x02):
return 0
else:
return 1
fp.close()
def getSSID(self, config):
if(not self.getNotBlank(config)):
return None
fp = open(self.f, "rb")
fp.seek(8 + (0x91C * config) + 2021)
len = unpack(">B", fp.read(1))[0]
fp.seek(8 + (0x91C * config) + 1988)
ssid = fp.read(len)
fp.close()
return ssid
def getEncryptionType(self, config):
if(not self.getNotBlank(config)):
return None
fp = open(self.f, "rb")
fp.seek(8 + (0x91C * config) + 2025)
crypt = unpack(">B", fp.read(1))[0]
type = ""
if(crypt == 0):
type = "OPEN"
elif(crypt == 1):
type = "WEP"
elif(crypt == 4):
type = "WPA (TKIP)"
elif(crypt == 5):
type = "WPA2"
elif(crypt == 6):
type = "WPA (AES)"
else:
print("Invalid crypto type %02X. Valid types are: ``OPEN'', ``WEP'', ``WPA (TKIP)'', ``WPA2'', or ``WPA (AES)''\n" % crypt)
fp.close()
return None
fp.close()
return type
def getEncryptionKey(self, config):
if(not self.getNotBlank(config)):
return None
fp = open(self.f, "rb")
fp.seek(8 + (0x91C * config) + 2025)
crypt = unpack(">B", fp.read(1))[0]
type = ""
if(crypt == 0):
type = "OPEN"
elif(crypt == 1):
type = "WEP"
elif(crypt == 4):
type = "WPA (TKIP)"
elif(crypt == 5):
type = "WPA2"
elif(crypt == 6):
type = "WPA (AES)"
else:
print("Invalid crypto type %02X. Valid types are: ``OPEN'', ``WEP'', ``WPA (TKIP)'', ``WPA2'', or ``WPA (AES)''\n" % crypt)
fp.close()
return None
if(crypt != "\x00"):
fp.seek(8 + (0x91C * config) + 2029)
keylen = unpack(">B", fp.read(1))[0]
fp.seek(8 + (0x91C * config) + 2032)
key = fp.read(keylen)
fp.close()
return key
fp.close()
return None
def clearConfig(self, config):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
sel &= 0xDF
fp.seek(8 + (0x91C * config))
fp.write(pack(">B", sel))
fp.close()
def setNotBlank(self, config):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
sel |= 0x20
fp.seek(8 + (0x91C * config))
fp.write(pack(">B", sel))
fp.close()
def setIPType(self, config, static):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
if(not static):
sel |= 0x04
else:
sel &= 0xFB
fp.seek(8 + (0x91C * config))
fp.write(pack(">B", sel))
fp.close()
self.setNotBlank(config)
def setWireType(self, config, wired):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * config))
sel = unpack(">B", fp.read(1))[0]
if(not wired):
sel |= 0x02
else:
sel &= 0xFD
fp.seek(8 + (0x91C * config))
fp.write(pack(">B", sel))
fp.close()
self.setNotBlank(config)
def setSSID(self, config, ssid):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * config) + 1988)
fp.write(ssid)
fp.seek(8 + (0x91C * config) + 2021)
fp.write(a2b_hex("%02X" % len(ssid)))
fp.close()
self.setNotBlank(config)
def setEncryption(self, config, crypt, key):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * config) + 2025)
if(crypt == "OPEN"):
fp.write("\x00")
elif(crypt == "WEP"):
fp.write("\x01")
elif(crypt == "WPA (TKIP)"):
fp.write("\x04")
elif(crypt == "WPA2"):
fp.write("\x05")
elif(crypt == "WPA (AES)"):
fp.write("\x06")
else:
print("Invalid crypto type. Valid types are: ``OPEN'', ``WEP'', ``WPA (TKIP)'', ``WPA2'', or ``WPA (AES)''\n")
fp.close()
return
if(crypt != "OPEN"):
fp.seek(8 + (0x91C * config) + 2029)
fp.write(a2b_hex("%02X" % len(key)))
fp.seek(8 + (0x91C * config) + 2032)
fp.write(key)
fp.close()
self.setNotBlank(config)
def selectConfig(self, config):
fp = open(self.f, "rb+")
fp.seek(8 + (0x91C * 0))
sel = unpack(">B", fp.read(1))[0]
if(config == 0):
sel |= 0x80
else:
sel &= 0x7F
fp.seek(8 + (0x91C * 0))
fp.write(pack(">B", sel))
fp.seek(8 + (0x91C * 1))
sel = unpack(">B", fp.read(1))[0]
if(config == 1):
sel |= 0x80
else:
sel &= 0x7F
fp.seek(8 + (0x91C * 1))
fp.write(pack(">B", sel))
fp.seek(8 + (0x91C * 2))
sel = unpack(">B", fp.read(1))[0]
if(config == 2):
sel |= 0x80
else:
sel &= 0x7F
fp.seek(8 + (0x91C * 2))
fp.write(pack(">B", sel))
self.setNotBlank(config)
fp.close()
class ContentMap: class ContentMap:
"""This class performs all content.map related actions. Has functions to add contents, and find contents by hash. """This class performs all content.map related actions. Has functions to add contents, and find contents by hash.
The ``map'' parameter is the location of the content.map file.""" The ``map'' parameter is the location of the content.map file."""