Advertisement
Guest User

wiiload.py

a guest
Jan 26th, 2011
3,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os, sys, zlib, socket, struct
  4.  
  5. ip = os.getenv("WIILOAD")
  6. assert ip.startswith("tcp:")
  7. wii_ip = (ip[4:], 4299)
  8.  
  9. filename = sys.argv[1]
  10.  
  11. WIILOAD_VERSION_MAJOR=0
  12. WIILOAD_VERSION_MINOR=5
  13.  
  14. len_uncompressed = os.path.getsize(filename)
  15. c_data = zlib.compress(open(filename).read(), 6)
  16.  
  17. chunk_size = 1024*128
  18. chunks = [c_data[i:i+chunk_size] for i  in range(0, len(c_data), chunk_size)]
  19.  
  20. args = [os.path.basename(filename)]+sys.argv[2:]
  21. args = "\x00".join(args) + "\x00"
  22.  
  23. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24. s.connect(wii_ip)
  25.  
  26. s.send("HAXX")
  27. s.send(struct.pack("B", WIILOAD_VERSION_MAJOR)) # one byte, unsigned
  28. s.send(struct.pack("B", WIILOAD_VERSION_MINOR)) # one byte, unsigned
  29. s.send(struct.pack(">H",len(args))) # bigendian, 2 bytes, unsigned
  30. s.send(struct.pack(">L",len(c_data))) # bigendian, 4 bytes, unsigned
  31. s.send(struct.pack(">L",len_uncompressed)) # bigendian, 4 bytes, unsigned
  32.  
  33. print len(chunks),"chunks to send"
  34. for piece in chunks:
  35.     s.send(piece)
  36.     sys.stdout.write("."); sys.stdout.flush()
  37. sys.stdout.write("\n")
  38.  
  39. s.send(args)
  40.  
  41. s.close()
  42. print "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement