Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- GoldtreePy/Goldtree.py 2019-03-28 11:34:11.000000000 +0300
- +++ GoldtreePy_desu/Goldtree.py 2019-03-28 12:37:22.000000000 +0300
- @@ -22,6 +22,7 @@
- custom_match=lambda e:usb.util.endpoint_direction(e.bEndpointAddress)==usb.util.ENDPOINT_IN))
- class CommandId:
- + GLUC=0x43554c47
- ConnectionRequest=0
- ConnectionResponse=1
- NSPName=2
- @@ -32,19 +33,15 @@
- Finish=7
- class Command:
- - GLUC=0x43554c47
- def __init__(self,cmd_id=0,raw=None):
- if raw is None:
- self.cmd_id=cmd_id
- - self.magic=self.GLUC
- else:
- - self.magic,self.cmd_id=struct.unpack("=II",raw)
- - def magic_ok(self):
- - return self.magic==self.GLUC
- + self.cmd_id=struct.unpack("=I",raw)[0]
- def has_id(self,cmd_id):
- return self.cmd_id==cmd_id
- def __bytes__(self):
- - return struct.pack("=II",self.magic,self.cmd_id)
- + return struct.pack("=I",self.cmd_id)
- dev=get_switch()
- ep=get_ep(dev)
- @@ -57,13 +54,18 @@
- install_cancelled="Goldleaf has canceled the installation."
- def main():
- + gluc_cmd=Command(CommandId.GLUC)
- c=Command()
- + c.has_id(CommandId.ConnectionRequest)
- + write(bytes(gluc_cmd))
- write(bytes(c))
- - c=Command(raw=read(8))
- - if c.magic_ok():
- + c=Command(raw=read(4))
- + if c.has_id(CommandId.GLUC):
- + c=Command(raw=read(4))
- if c.has_id(CommandId.ConnectionResponse):
- print("Connection was established with Goldleaf.")
- c=Command(CommandId.NSPName)
- + write(bytes(gluc_cmd))
- write(bytes(c))
- base_name=os.path.basename(sys.argv[1])
- write(struct.pack("=I",len(base_name)))
- @@ -72,15 +74,17 @@
- resp=None
- while resp is None:
- try:
- - resp=read(8)
- + resp=read(4)
- c=Command(raw=resp)
- except usb.core.USBError:
- pass
- - if c.magic_ok():
- + if c.has_id(CommandId.GLUC):
- + c=Command(raw=read(4))
- if c.has_id(CommandId.Start):
- print("Goldleaf is ready for the installation. Preparing everything...")
- pnsp=PFS0(sys.argv[1])
- c=Command(CommandId.NSPData)
- + write(bytes(gluc_cmd))
- write(bytes(c))
- write(struct.pack("=I",len(pnsp.files)))
- tik_idx=-1
- @@ -94,8 +98,9 @@
- tik_idx=tmp_idx
- tmp_idx+=1
- while True:
- - c=Command(raw=read(8))
- - if c.magic_ok():
- + c=Command(raw=read(4))
- + if c.has_id(CommandId.GLUC):
- + c=Command(raw=read(4))
- if c.has_id(CommandId.NSPContent):
- idx=struct.unpack("=I",read(4))[0]
- print("Sending content '"+pnsp.files[idx].name+"'... ("+str(idx+1)+" of "+str(len(pnsp.files))+")")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement