Advertisement
developer_su

Untitled

Mar 28th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. --- GoldtreePy/Goldtree.py 2019-03-28 11:34:11.000000000 +0300
  2. +++ GoldtreePy_desu/Goldtree.py 2019-03-28 12:37:22.000000000 +0300
  3. @@ -22,6 +22,7 @@
  4. custom_match=lambda e:usb.util.endpoint_direction(e.bEndpointAddress)==usb.util.ENDPOINT_IN))
  5.  
  6. class CommandId:
  7. + GLUC=0x43554c47
  8. ConnectionRequest=0
  9. ConnectionResponse=1
  10. NSPName=2
  11. @@ -32,19 +33,15 @@
  12. Finish=7
  13.  
  14. class Command:
  15. - GLUC=0x43554c47
  16. def __init__(self,cmd_id=0,raw=None):
  17. if raw is None:
  18. self.cmd_id=cmd_id
  19. - self.magic=self.GLUC
  20. else:
  21. - self.magic,self.cmd_id=struct.unpack("=II",raw)
  22. - def magic_ok(self):
  23. - return self.magic==self.GLUC
  24. + self.cmd_id=struct.unpack("=I",raw)[0]
  25. def has_id(self,cmd_id):
  26. return self.cmd_id==cmd_id
  27. def __bytes__(self):
  28. - return struct.pack("=II",self.magic,self.cmd_id)
  29. + return struct.pack("=I",self.cmd_id)
  30.  
  31. dev=get_switch()
  32. ep=get_ep(dev)
  33. @@ -57,13 +54,18 @@
  34. install_cancelled="Goldleaf has canceled the installation."
  35.  
  36. def main():
  37. + gluc_cmd=Command(CommandId.GLUC)
  38. c=Command()
  39. + c.has_id(CommandId.ConnectionRequest)
  40. + write(bytes(gluc_cmd))
  41. write(bytes(c))
  42. - c=Command(raw=read(8))
  43. - if c.magic_ok():
  44. + c=Command(raw=read(4))
  45. + if c.has_id(CommandId.GLUC):
  46. + c=Command(raw=read(4))
  47. if c.has_id(CommandId.ConnectionResponse):
  48. print("Connection was established with Goldleaf.")
  49. c=Command(CommandId.NSPName)
  50. + write(bytes(gluc_cmd))
  51. write(bytes(c))
  52. base_name=os.path.basename(sys.argv[1])
  53. write(struct.pack("=I",len(base_name)))
  54. @@ -72,15 +74,17 @@
  55. resp=None
  56. while resp is None:
  57. try:
  58. - resp=read(8)
  59. + resp=read(4)
  60. c=Command(raw=resp)
  61. except usb.core.USBError:
  62. pass
  63. - if c.magic_ok():
  64. + if c.has_id(CommandId.GLUC):
  65. + c=Command(raw=read(4))
  66. if c.has_id(CommandId.Start):
  67. print("Goldleaf is ready for the installation. Preparing everything...")
  68. pnsp=PFS0(sys.argv[1])
  69. c=Command(CommandId.NSPData)
  70. + write(bytes(gluc_cmd))
  71. write(bytes(c))
  72. write(struct.pack("=I",len(pnsp.files)))
  73. tik_idx=-1
  74. @@ -94,8 +98,9 @@
  75. tik_idx=tmp_idx
  76. tmp_idx+=1
  77. while True:
  78. - c=Command(raw=read(8))
  79. - if c.magic_ok():
  80. + c=Command(raw=read(4))
  81. + if c.has_id(CommandId.GLUC):
  82. + c=Command(raw=read(4))
  83. if c.has_id(CommandId.NSPContent):
  84. idx=struct.unpack("=I",read(4))[0]
  85. 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