Lucas Teske ревизий этого фрагмента 8 years ago. К ревизии
1 file changed, 687 insertions
prime.py(файл создан)
| @@ -0,0 +1,687 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | ||
| 3 | + | ''' | |
| 4 | + | ____ _ _ _ _ | |
| 5 | + | | _ \ _ __(_)_ __ ___ ___ | | (_) |__ _ __ __ _ _ __ _ _ | |
| 6 | + | | |_) | '__| | '_ ` _ \ / _ \ | | | | '_ \| '__/ _` | '__| | | | | |
| 7 | + | | __/| | | | | | | | | __/ | |___| | |_) | | | (_| | | | |_| | | |
| 8 | + | |_| |_| |_|_| |_| |_|\___| |_____|_|_.__/|_| \__,_|_| \__, | | |
| 9 | + | |___/ | |
| 10 | + | ||
| 11 | + | This is a Prime Library for Prime Server | |
| 12 | + | ''' | |
| 13 | + | ||
| 14 | + | import struct | |
| 15 | + | import binascii | |
| 16 | + | import pysodium | |
| 17 | + | import time | |
| 18 | + | import socket | |
| 19 | + | ||
| 20 | + | LAST_NOUNCE = "\x00" * 24 | |
| 21 | + | OFICIAL_SERVER_IP = "115.68.108.183" | |
| 22 | + | ||
| 23 | + | def DownloadProfile(accesscode, pk, sk): | |
| 24 | + | accesscode = accesscode.lower().replace(" ","") | |
| 25 | + | ||
| 26 | + | login = LoginPacket() | |
| 27 | + | login.AccessCode = accesscode | |
| 28 | + | ||
| 29 | + | tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| 30 | + | dest = (OFICIAL_SERVER_IP, 60000) | |
| 31 | + | tcp.connect(dest) | |
| 32 | + | data = EncryptPacket(login.ToBinary(), pk, sk) | |
| 33 | + | tcp.send (data) | |
| 34 | + | time.sleep(0.1) | |
| 35 | + | msg = "" | |
| 36 | + | profile = "" | |
| 37 | + | while True: | |
| 38 | + | msg += tcp.recv(4) | |
| 39 | + | if len(msg) > 0: | |
| 40 | + | size = struct.unpack("<I", msg[:4])[0] | |
| 41 | + | msg = msg[4:] | |
| 42 | + | msg += tcp.recv(size-4-len(msg)) | |
| 43 | + | while len(msg) < size-4: | |
| 44 | + | msg += tcp.recv((size-4) - len(msg)) | |
| 45 | + | ||
| 46 | + | data = DecryptPacket(msg, pk, sk) | |
| 47 | + | try: | |
| 48 | + | packtype = struct.unpack("<I",data[4:8])[0] | |
| 49 | + | if packtype == ProfilePacket.PacketType: | |
| 50 | + | print "Got Profile Packet!" | |
| 51 | + | profile = ProfilePacket() | |
| 52 | + | profile.FromBinary(data) | |
| 53 | + | print "NickName: %s" %profile.Nickname | |
| 54 | + | break | |
| 55 | + | else: | |
| 56 | + | print "PacketType: %s (%x)" %(packtype, packtype) | |
| 57 | + | except Exception,e: | |
| 58 | + | print "Error: %s" %e | |
| 59 | + | tcp.close() | |
| 60 | + | return profile | |
| 61 | + | ||
| 62 | + | def SendSongPacket(accesscode, pk, sk): | |
| 63 | + | pass | |
| 64 | + | ||
| 65 | + | def DecryptPacket(packet, pk, sk): | |
| 66 | + | nounce = packet[:24] | |
| 67 | + | data = packet[24:] | |
| 68 | + | LAST_NOUNCE = nounce | |
| 69 | + | return pysodium.crypto_box_open(data, nounce, pk, sk) | |
| 70 | + | ||
| 71 | + | def EncryptPacket(packet, pk, sk): | |
| 72 | + | nounce = LAST_NOUNCE | |
| 73 | + | data = pysodium.crypto_box(packet, nounce, pk, sk) | |
| 74 | + | return struct.pack("<I",len(data)+24+4) + nounce + data | |
| 75 | + | ||
| 76 | + | class RequestWorldBest: | |
| 77 | + | PacketHead = 2 | |
| 78 | + | PacketType = 0x1000008 | |
| 79 | + | ||
| 80 | + | def ToBinary(self): | |
| 81 | + | return struct.pack("<2I", self.PacketHead, self.PacketType) | |
| 82 | + | ||
| 83 | + | def FromBinary(self,binary): | |
| 84 | + | self.PacketHead, self.PacketType = struct.unpack("<2I", binary) | |
| 85 | + | ||
| 86 | + | class RequestRankMode: | |
| 87 | + | PacketHead = 3 | |
| 88 | + | PacketType = 0x100000A | |
| 89 | + | ||
| 90 | + | def ToBinary(self): | |
| 91 | + | return struct.pack("<2I", self.PacketHead, self.PacketType) | |
| 92 | + | ||
| 93 | + | def FromBinary(self,binary): | |
| 94 | + | self.PacketHead, self.PacketType = struct.unpack("<2I", binary) | |
| 95 | + | ||
| 96 | + | ||
| 97 | + | class ACKPacket: | |
| 98 | + | PacketHead = 1 | |
| 99 | + | PacketType = 0x1000002 | |
| 100 | + | MachineID = 0xFFFFFFF | |
| 101 | + | ||
| 102 | + | def ToBinary(self): | |
| 103 | + | return struct.pack("<3I", self.PacketHead, self.PacketType, self.MachineID) | |
| 104 | + | ||
| 105 | + | def FromBinary(self,binary): | |
| 106 | + | self.PacketHead, self.PacketType, self.MachineID = struct.unpack("<3I", binary) | |
| 107 | + | ||
| 108 | + | class KeepAlivePacket(): | |
| 109 | + | PacketHead = 1 | |
| 110 | + | PacketType = 0x3000000 | |
| 111 | + | PacketTrail = 65535 | |
| 112 | + | ||
| 113 | + | def ToBinary(self): | |
| 114 | + | return struct.pack("<3I", self.PacketHead, self.PacketType, self.PacketTrail) | |
| 115 | + | ||
| 116 | + | def FromBinary(self,binary): | |
| 117 | + | self.PacketHead, self.PacketType, self.PacketTrail = struct.unpack("<3I", binary) | |
| 118 | + | ||
| 119 | + | class ByePacket: | |
| 120 | + | PacketHead = 1 | |
| 121 | + | PacketType = 0x1000010 | |
| 122 | + | ProfileID = 3029 | |
| 123 | + | ||
| 124 | + | def ToBinary(self): | |
| 125 | + | return struct.pack("<3I", self.PacketHead, self.PacketType, self.ProfileID) | |
| 126 | + | ||
| 127 | + | def FromBinary(self,binary): | |
| 128 | + | self.PacketHead, self.PacketType, self.ProfileID = struct.unpack("<3I", binary) | |
| 129 | + | ||
| 130 | + | ||
| 131 | + | class ProfileBusyPacket(): | |
| 132 | + | PacketHead = 1 | |
| 133 | + | PacketType = 0x1000005 | |
| 134 | + | unk0 = 0 | |
| 135 | + | ||
| 136 | + | def ToBinary(self): | |
| 137 | + | return struct.pack("<3I", self.PacketHead, self.PacketType, self.unk0) | |
| 138 | + | ||
| 139 | + | def FromBinary(self,binary): | |
| 140 | + | self.PacketHead, self.PacketType, self.unk0 = struct.unpack("<3I", binary) | |
| 141 | + | ||
| 142 | + | class RankModePacket: | |
| 143 | + | PacketHead = 3 | |
| 144 | + | PacketType = 0x100000B | |
| 145 | + | rankdata = {} | |
| 146 | + | ||
| 147 | + | _TOTAL_SIZE = 16008 | |
| 148 | + | ||
| 149 | + | def ToBinary(self): | |
| 150 | + | packet = struct.pack("<2I", self.PacketHeader, self.PacketType) | |
| 151 | + | for key in self.rankdata.keys(): | |
| 152 | + | packet += struct.pack("<I12s12s12s",key,self.rankdata[key][0],self.rankdata[key][1],self.rankdata[key][2]) | |
| 153 | + | packet += "\x00" * (self._TOTAL_SIZE - len(packet)) | |
| 154 | + | return packet | |
| 155 | + | ||
| 156 | + | def FromBinary(self, binary): | |
| 157 | + | self.PacketHead, self.PacketType = struct.unpack("<2I", binary[:8]) | |
| 158 | + | data = binary[8:] | |
| 159 | + | i = 0 | |
| 160 | + | while i < len(data): | |
| 161 | + | songid, first, second, third = struct.unpack("<I12s12s12s",data[i:i+40]) | |
| 162 | + | if songid == 0x00: | |
| 163 | + | break | |
| 164 | + | i+= 40 | |
| 165 | + | first = first.split("\x00")[0] | |
| 166 | + | second = second.split("\x00")[0] | |
| 167 | + | third = third.split("\x00")[0] | |
| 168 | + | self.rankdata[songid] = [first,second,third] | |
| 169 | + | ||
| 170 | + | def Print(self): | |
| 171 | + | print "RankModePacket" | |
| 172 | + | for key in self.rankdata.keys(): | |
| 173 | + | print "0x%04x: %s -> %s -> %s" % (key,self.rankdata[key][0],self.rankdata[key][1],self.rankdata[key][2]) | |
| 174 | + | ||
| 175 | + | ||
| 176 | + | class MachineInfoPacket: | |
| 177 | + | ''' | |
| 178 | + | Send from client when game starts | |
| 179 | + | ''' | |
| 180 | + | PacketHead = 1 | |
| 181 | + | PacketType = 0x1000001 | |
| 182 | + | unk0 = 0 | |
| 183 | + | unk1 = 0 | |
| 184 | + | unk2 = 0 | |
| 185 | + | MacAddress = "" # 20 bytes | |
| 186 | + | Version = "" # 12 bytes | |
| 187 | + | Processor = "" # 128 bytes | |
| 188 | + | MotherBoard = "" # 128 bytes | |
| 189 | + | GraphicsCard = "" # 128 bytes | |
| 190 | + | HDDSerial = "" # 32 bytes | |
| 191 | + | USBMode = "" # 128 bytes | |
| 192 | + | Memory = 0 | |
| 193 | + | unk6 = 0 | |
| 194 | + | unk7 = 0 | |
| 195 | + | unk8 = 0 | |
| 196 | + | unk9 = 0 | |
| 197 | + | unk10 = 0 | |
| 198 | + | unk11 = 0 | |
| 199 | + | unk12 = 0 | |
| 200 | + | unk13 = 0 | |
| 201 | + | unk14 = 0 | |
| 202 | + | unk15 = "" # 104 bytes | |
| 203 | + | PacketTrail = 0xFFFFFFFF | |
| 204 | + | ||
| 205 | + | def ToBinary(self): | |
| 206 | + | return struct.pack("<5I20s12s128s128s128s32s128s10I104sI", self.PacketHead, self.PacketType, self.unk0, self.DongleID, self.unk2, self.MacAddress, self.Version, self.Processor, self.MotherBoard, self.GraphicsCard, self.HDDSerial, self.USBMode, self.Memory, self.unk6, self.unk7, self.unk8, self.unk9, self.unk10, self.unk11, self.unk12, self.unk13, self.unk14, self.unk15, self.PacketTrail) | |
| 207 | + | ||
| 208 | + | def FromBinary(self,binary): | |
| 209 | + | self.PacketHead, self.PacketType, self.unk0, self.DongleID, self.unk2, self.MacAddress, self.Version, self.Processor, self.MotherBoard, self.GraphicsCard, self.HDDSerial, self.USBMode, self.Memory, self.unk6, self.unk7, self.unk8, self.unk9, self.unk10, self.unk11, self.unk12, self.unk13, self.unk14, self.unk15, self.PacketTrail = struct.unpack("<5I20s12s128s128s128s32s128s10I104sI", binary) | |
| 210 | + | self.MacAddress = self.MacAddress.split("\x00")[0] | |
| 211 | + | self.Version = self.Version.split("\x00")[0] | |
| 212 | + | self.Processor = self.Processor.split("\x00")[0] | |
| 213 | + | self.MotherBoard = self.MotherBoard.split("\x00")[0] | |
| 214 | + | self.GraphicsCard = self.GraphicsCard.split("\x00")[0] | |
| 215 | + | self.HDDSerial = self.HDDSerial.split("\x00")[0] | |
| 216 | + | self.USBMode = self.USBMode.split("\x00")[0] | |
| 217 | + | ||
| 218 | + | def Print(self): | |
| 219 | + | print "Machine Packet" | |
| 220 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 221 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 222 | + | print "\tUnknown uint32_t 0: %s (0x%x)" %(self.unk0,self.unk0) | |
| 223 | + | print "\tDongle ID: %s (0x%x)" %(self.DongleID,self.DongleID) | |
| 224 | + | print "\tUnknown uint32_t 2: %s (0x%x)" %(self.unk2,self.unk2) | |
| 225 | + | print "\tMac Address: %s" %self.MacAddress | |
| 226 | + | print "\tVersion: %s" %self.Version | |
| 227 | + | print "\tProcessor: %s" %self.Processor | |
| 228 | + | print "\tMother Board: %s" %self.MotherBoard | |
| 229 | + | print "\tGraphics Card: %s" %self.GraphicsCard | |
| 230 | + | print "\tHDD Serial: %s" %self.HDDSerial | |
| 231 | + | print "\tUSB Mode: %s" %self.USBMode | |
| 232 | + | print "\tMemory: %s" %self.Memory | |
| 233 | + | print "\tUnknown uint32_t 6: %s (0x%x)" %(self.unk6,self.unk6) | |
| 234 | + | print "\tUnknown uint32_t 7: %s (0x%x)" %(self.unk7,self.unk7) | |
| 235 | + | print "\tUnknown uint32_t 8: %s (0x%x)" %(self.unk8,self.unk8) | |
| 236 | + | print "\tUnknown uint32_t 9: %s (0x%x)" %(self.unk9,self.unk9) | |
| 237 | + | print "\tUnknown uint32_t 10: %s (0x%x)" %(self.unk10,self.unk10) | |
| 238 | + | print "\tUnknown uint32_t 11: %s (0x%x)" %(self.unk11,self.unk11) | |
| 239 | + | print "\tUnknown uint32_t 12: %s (0x%x)" %(self.unk12,self.unk12) | |
| 240 | + | print "\tUnknown uint32_t 13: %s (0x%x)" %(self.unk13,self.unk13) | |
| 241 | + | print "\tUnknown uint32_t 14: %s (0x%x)" %(self.unk14,self.unk14) | |
| 242 | + | print "\tUnknown String: %s" %(binascii.hexlify(self.unk15)) | |
| 243 | + | print "\tPacket Trail: %s (0x%x)" %(self.PacketTrail, self.PacketTrail); | |
| 244 | + | ||
| 245 | + | class MachineInfoPacket_v2: | |
| 246 | + | ''' | |
| 247 | + | Send from client when game starts | |
| 248 | + | ''' | |
| 249 | + | PacketHead = 1 | |
| 250 | + | PacketType = 0x1000011 | |
| 251 | + | MachineID = 1130 | |
| 252 | + | DongleID = 0xC0FEBABE | |
| 253 | + | CountryID = 24 | |
| 254 | + | MacAddress = "" # 20 bytes | |
| 255 | + | Version = "" # 12 bytes | |
| 256 | + | Processor = "" # 128 bytes | |
| 257 | + | MotherBoard = "" # 128 bytes | |
| 258 | + | GraphicsCard = "" # 128 bytes | |
| 259 | + | HDDSerial = "" # 32 bytes | |
| 260 | + | USBMode = "" # 128 bytes | |
| 261 | + | Memory = 0 | |
| 262 | + | ConfigMagic = 345396 | |
| 263 | + | unk7 = 0xFFFFFFFF | |
| 264 | + | unk8 = 0xFFFFFF | |
| 265 | + | unk9 = 516 | |
| 266 | + | unk10 = 0 | |
| 267 | + | unk11 = 262144 | |
| 268 | + | unk12 = 16777216 | |
| 269 | + | unk13 = 256 | |
| 270 | + | unk14 = 16777217 | |
| 271 | + | unk15 = 1052672 | |
| 272 | + | unk16 = 0 | |
| 273 | + | unk17 = 0 | |
| 274 | + | unk18 = 0 | |
| 275 | + | unk19 = 0 | |
| 276 | + | unk20 = 0 | |
| 277 | + | unk21 = 0 | |
| 278 | + | unk22 = 145840 | |
| 279 | + | unk23 = "" # 76 bytes | |
| 280 | + | netaddr = "" # 16 bytes | |
| 281 | + | def ToBinary(self): | |
| 282 | + | return struct.pack("<5I20s12s128s128s128s32s128s18I76s16s", self.PacketHead, self.PacketType, self.MachineID, self.DongleID, self.CountryID, self.MacAddress, self.Version, self.Processor, self.MotherBoard, self.GraphicsCard, self.HDDSerial, self.USBMode, self.Memory, self.ConfigMagic, self.unk7, self.unk8, self.unk9, self.unk10, self.unk11, self.unk12, self.unk13, self.unk14, self.unk15, self.unk16, self.unk17, self.unk18, self.unk19, self.unk20, self.unk21, self.unk22, self.unk23, self.netaddr) | |
| 283 | + | ||
| 284 | + | def FromBinary(self,binary): | |
| 285 | + | self.PacketHead, self.PacketType, self.MachineID, self.DongleID, self.CountryID, self.MacAddress, self.Version, self.Processor, self.MotherBoard, self.GraphicsCard, self.HDDSerial, self.USBMode, self.Memory, self.ConfigMagic, self.unk7, self.unk8, self.unk9, self.unk10, self.unk11, self.unk12, self.unk13, self.unk14, self.unk15, self.unk16, self.unk17, self.unk18, self.unk19, self.unk20, self.unk21, self.unk22, self.unk23, self.netaddr = struct.unpack("<5I20s12s128s128s128s32s128s18I76s16s", binary) | |
| 286 | + | self.MacAddress = self.MacAddress.split("\x00")[0] | |
| 287 | + | self.Version = self.Version.split("\x00")[0] | |
| 288 | + | self.Processor = self.Processor.split("\x00")[0] | |
| 289 | + | self.MotherBoard = self.MotherBoard.split("\x00")[0] | |
| 290 | + | self.GraphicsCard = self.GraphicsCard.split("\x00")[0] | |
| 291 | + | self.HDDSerial = self.HDDSerial.split("\x00")[0] | |
| 292 | + | self.USBMode = self.USBMode.split("\x00")[0] | |
| 293 | + | ||
| 294 | + | def Print(self): | |
| 295 | + | print "Machine Packet" | |
| 296 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 297 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 298 | + | print "\tMachineID: %s (0x%x)" %(self.MachineID,self.MachineID) | |
| 299 | + | print "\tDongle ID: %s (0x%x)" %(self.DongleID,self.DongleID) | |
| 300 | + | print "\tCountry ID: %s (0x%x)" %(self.CountryID,self.CountryID) | |
| 301 | + | print "\tMac Address: %s" %self.MacAddress | |
| 302 | + | print "\tVersion: %s" %self.Version | |
| 303 | + | print "\tProcessor: %s" %self.Processor | |
| 304 | + | print "\tMother Board: %s" %self.MotherBoard | |
| 305 | + | print "\tGraphics Card: %s" %self.GraphicsCard | |
| 306 | + | print "\tHDD Serial: %s" %self.HDDSerial | |
| 307 | + | print "\tUSB Mode: %s" %self.USBMode | |
| 308 | + | print "\tMemory: %s" %self.Memory | |
| 309 | + | print "\tConfig Magic: %s (0x%x)" %(self.ConfigMagic,self.ConfigMagic) | |
| 310 | + | print "\tUnknown uint32_t 7: %s (0x%x)" %(self.unk7,self.unk7) | |
| 311 | + | print "\tUnknown uint32_t 8: %s (0x%x)" %(self.unk8,self.unk8) | |
| 312 | + | print "\tUnknown uint32_t 9: %s (0x%x)" %(self.unk9,self.unk9) | |
| 313 | + | print "\tUnknown uint32_t 10: %s (0x%x)" %(self.unk10,self.unk10) | |
| 314 | + | print "\tUnknown uint32_t 11: %s (0x%x)" %(self.unk11,self.unk11) | |
| 315 | + | print "\tUnknown uint32_t 12: %s (0x%x)" %(self.unk12,self.unk12) | |
| 316 | + | print "\tUnknown uint32_t 13: %s (0x%x)" %(self.unk13,self.unk13) | |
| 317 | + | print "\tUnknown uint32_t 14: %s (0x%x)" %(self.unk14,self.unk14) | |
| 318 | + | print "\tUnknown uint32_t 15: %s (0x%x)" %(self.unk14,self.unk15) | |
| 319 | + | print "\tUnknown uint32_t 16: %s (0x%x)" %(self.unk14,self.unk16) | |
| 320 | + | print "\tUnknown uint32_t 17: %s (0x%x)" %(self.unk14,self.unk17) | |
| 321 | + | print "\tUnknown uint32_t 18: %s (0x%x)" %(self.unk14,self.unk18) | |
| 322 | + | print "\tUnknown uint32_t 19: %s (0x%x)" %(self.unk14,self.unk19) | |
| 323 | + | print "\tUnknown uint32_t 20: %s (0x%x)" %(self.unk14,self.unk20) | |
| 324 | + | print "\tUnknown uint32_t 21: %s (0x%x)" %(self.unk14,self.unk21) | |
| 325 | + | print "\tUnknown uint32_t 22: %s (0x%x)" %(self.unk14,self.unk22) | |
| 326 | + | print "\tUnknown String: %s" %(binascii.hexlify(self.unk23)) | |
| 327 | + | print "\tNet Address: %s" %(self.netaddr); | |
| 328 | + | ||
| 329 | + | class ScoreBoardPacket(): | |
| 330 | + | ''' | |
| 331 | + | Send from client when finishes a Song | |
| 332 | + | ''' | |
| 333 | + | PacketHead = 0x0000001 | |
| 334 | + | PacketType = 0x100000E | |
| 335 | + | ||
| 336 | + | SongID = 0 | |
| 337 | + | ChartLevel = 0 | |
| 338 | + | Type = 0 | |
| 339 | + | Flag = 0 | |
| 340 | + | Score = 0 | |
| 341 | + | RealScore0 = 0 | |
| 342 | + | ||
| 343 | + | unk0 = "" # 16 bytes | |
| 344 | + | ||
| 345 | + | RealScore1 = 0 | |
| 346 | + | Grade = 0 | |
| 347 | + | Kcal = 0 | |
| 348 | + | ||
| 349 | + | Perfect = 0 | |
| 350 | + | Great = 0 | |
| 351 | + | Good = 0 | |
| 352 | + | Bad = 0 | |
| 353 | + | Miss = 0 | |
| 354 | + | MaxCombo = 0 | |
| 355 | + | EXP = 0 | |
| 356 | + | PP = 0 | |
| 357 | + | ||
| 358 | + | RunningStep = 0 | |
| 359 | + | unk2 = 0 | |
| 360 | + | unk3 = 0 | |
| 361 | + | unk4 = 0 | |
| 362 | + | unk5 = 0 | |
| 363 | + | RushSpeed = 0 | |
| 364 | + | ||
| 365 | + | GameVersion = "" # 12 Bytes | |
| 366 | + | ||
| 367 | + | MachineID = 0xFFFFFFFF | |
| 368 | + | ProfileID = 0x00 | |
| 369 | + | ||
| 370 | + | def ToBinary(self): | |
| 371 | + | return struct.pack("<3IH2B2I16s2If6I4H3If12s2I", self.PacketHead, self.PacketType, self.SongID, self.ChartLevel, self.Type, self.Flag, self.Score, self.RealScore0, self.unk0, self.RealScore1, self.Grade, self.Kcal, self.Perfect, self.Great, self.Good, self.Bad, self.Miss, self.MaxCombo, self.EXP, self.PP, self.RunningStep, self.unk2, self.unk3, self.unk4, self.unk5, self.RushSpeed, self.GameVersion, self.MachineID, self.ProfileID) | |
| 372 | + | ||
| 373 | + | def FromBinary(self,binary): | |
| 374 | + | self.PacketHead, self.PacketType, self.SongID, self.ChartLevel, self.Type, self.Flag, self.Score, self.RealScore0, self.unk0, self.RealScore1, self.Grade, self.Kcal, self.Perfect, self.Great, self.Good, self.Bad, self.Miss, self.MaxCombo, self.EXP, self.PP, self.RunningStep, self.unk2, self.unk3, self.unk4, self.unk5, self.RushSpeed, self.GameVersion, self.MachineID, self.ProfileID = struct.unpack("<3IH2B2I16s2If6I4h3If12s2I", binary) | |
| 375 | + | ||
| 376 | + | def Print(self): | |
| 377 | + | print "Score Board Packet" | |
| 378 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 379 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 380 | + | print "\tSongID: %s (0x%x)" %(self.SongID,self.SongID) | |
| 381 | + | print "\tChart Level: %s" %self.ChartLevel | |
| 382 | + | print "\tType: %s (0x%x)" %(self.Type,self.Type) | |
| 383 | + | print "\tFlag: %s (0x%x)" %(self.Flag, self.Flag) | |
| 384 | + | print "\tScore: %s" %self.Score | |
| 385 | + | print "\tRealScore0: %s" %self.RealScore0 | |
| 386 | + | print "\tUnknown String 0: %s" %binascii.hexlify(self.unk0) | |
| 387 | + | print "\tRealScore1: %s" %self.RealScore1 | |
| 388 | + | print "\t\tGrade: %s (0x%x)" %(self.Grade, self.Grade) | |
| 389 | + | print "\t\tKcal: %s" %self.Kcal | |
| 390 | + | print "\t\tPerfect: %s" %self.Perfect | |
| 391 | + | print "\t\tGreat: %s" %self.Great | |
| 392 | + | print "\t\tGood: %s" %self.Good | |
| 393 | + | print "\t\tBad: %s" %self.Bad | |
| 394 | + | print "\t\tMiss: %s" %self.Miss | |
| 395 | + | print "\t\tMaxCombo: %s" %self.MaxCombo | |
| 396 | + | print "\t\tEXP: %s" %self.EXP | |
| 397 | + | print "\t\tPP: %s" %self.PP | |
| 398 | + | print "" | |
| 399 | + | print "\tRunning Step: %s" %(self.RunningStep) | |
| 400 | + | print "\tUnknown uint16_t 2: %s (0x%x)" %(self.unk2,self.unk2) | |
| 401 | + | print "\tUnknown uint32_t 3: %s (0x%x)" %(self.unk3,self.unk3) | |
| 402 | + | print "\tUnknown uint32_t 4: %s (0x%x)" %(self.unk4,self.unk4) | |
| 403 | + | print "\tUnknown uint32_t 5: %s (0x%x)" %(self.unk5,self.unk5) | |
| 404 | + | print "\tRushSpeed: %s" %(self.RushSpeed) | |
| 405 | + | print "\tMachineID: %s (0x%x)" %(self.MachineID, self.MachineID); | |
| 406 | + | print "\tProfileID: %s (0x%x)" %(self.ProfileID, self.ProfileID); | |
| 407 | + | ||
| 408 | + | ||
| 409 | + | class LoginPacket(): | |
| 410 | + | ''' | |
| 411 | + | Packet that Client sends to Server to Receive Login Stuff | |
| 412 | + | ''' | |
| 413 | + | PacketHead = 1 | |
| 414 | + | PacketType = 0x1000003 | |
| 415 | + | PlayerID = 0 | |
| 416 | + | MachineID = 1130 | |
| 417 | + | AccessCode = "" # 32 bytes | |
| 418 | + | PacketTrail = 0x0 | |
| 419 | + | ||
| 420 | + | def ToBinary(self): | |
| 421 | + | return struct.pack("<4I32sI", self.PacketHead, self.PacketType, self.PlayerID, self.MachineID, self.AccessCode, self.PacketTrail) | |
| 422 | + | ||
| 423 | + | def FromBinary(self,binary): | |
| 424 | + | self.PacketHead, self.PacketType, self.PlayerID, self.MachineID, self.AccessCode, self.PacketTrail = struct.unpack("<4I32sI", binary) | |
| 425 | + | ||
| 426 | + | def Print(self): | |
| 427 | + | print "LoginPacket" | |
| 428 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 429 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 430 | + | print "\tPlayerID: %s (0x%x)" %(self.PlayerID, self.PlayerID) | |
| 431 | + | print "\tMachineID: %s (0x%x)" %(self.MachineID, self.MachineID) | |
| 432 | + | print "\tAccessCode: %s" %self.AccessCode | |
| 433 | + | print "\tPacketTrail: %s (0x%x)" %(self.PacketTrail,self.PacketTrail) | |
| 434 | + | ||
| 435 | + | class uScore(): | |
| 436 | + | ''' | |
| 437 | + | Song Score Entry on Profile Data | |
| 438 | + | ''' | |
| 439 | + | SongID = 0 | |
| 440 | + | ChartLevel = 0 | |
| 441 | + | unk0 = 0 | |
| 442 | + | unk1 = 0 | |
| 443 | + | Score = 0 | |
| 444 | + | RealScore = 0 | |
| 445 | + | unk2 = 0 | |
| 446 | + | ||
| 447 | + | def ToBinary(self): | |
| 448 | + | return struct.pack("<I2BH3I", self.SongID, self.ChartLevel, self.unk0, self.unk1, self.Score, self.RealScore, self.unk2) | |
| 449 | + | ||
| 450 | + | def FromBinary(self,binary): | |
| 451 | + | self.SongID, self.ChartLevel, self.unk0, self.unk1, self.Score, self.RealScore, self.unk2 = struct.unpack("<I2BH3I", binary) | |
| 452 | + | ||
| 453 | + | def Print(self): | |
| 454 | + | print "\t\tSongID: %s (0x%x) at level %s - Score: %s - RealScore: %s - [Unk0: %s(0x%x), Unk1: %s(0x%x), Unk2: %s(0x%x)]" %(self.SongID, self.SongID, self.ChartLevel, self.Score, self.RealScore, self.unk0, self.unk0, self.unk1, self.unk1, self.unk2, self.unk2) | |
| 455 | + | ||
| 456 | + | class EnterProfilePacket(): | |
| 457 | + | ''' | |
| 458 | + | Packet Received when Someone enters ingame | |
| 459 | + | ''' | |
| 460 | + | PacketHead = 2 | |
| 461 | + | PacketType = 0x100000F | |
| 462 | + | PlayerID = 0 | |
| 463 | + | MachineID = 1130 | |
| 464 | + | ProfileID = 0 | |
| 465 | + | def ToBinary(self): | |
| 466 | + | return struct.pack("<5I", self.PacketHead, self.PacketType, self.PlayerID, self.MachineID, self.ProfileID) | |
| 467 | + | ||
| 468 | + | def FromBinary(self,binary): | |
| 469 | + | self.PacketHead, self.PacketType, self.PlayerID, self.MachineID, self.ProfileID = struct.unpack("<5I", binary) | |
| 470 | + | ||
| 471 | + | def Print(self): | |
| 472 | + | print "EnterProfilePacket: " | |
| 473 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 474 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 475 | + | print "\tPlayerID: %s (0x%x)" %(self.PlayerID, self.PlayerID) | |
| 476 | + | print "\tMachineID: %s (0x%x)" %(self.MachineID, self.MachineID) | |
| 477 | + | print "\tProfileID: %s (0x%x)" %(self.ProfileID, self.ProfileID) | |
| 478 | + | ||
| 479 | + | class ProfilePacket(): | |
| 480 | + | ''' | |
| 481 | + | Packet send by server to client after LoginPacket | |
| 482 | + | ''' | |
| 483 | + | __USCORE_PACK_LENGTH = 20 # Used for packing/unpacking uScore packets | |
| 484 | + | ||
| 485 | + | PacketHead = 1 | |
| 486 | + | PacketType = 0x1000004 | |
| 487 | + | PlayerID = 0 # 32 bit | |
| 488 | + | AccessCode = "" # 36 bytes | |
| 489 | + | Nickname = "" # 12 Bytes | |
| 490 | + | ProfileID = 0 # 32 bit | |
| 491 | + | CountryID = 0 # 8 bit | |
| 492 | + | Avatar = 0 # 8 bit | |
| 493 | + | Level = 0 # 8 bit | |
| 494 | + | unk2 = 0 # 8 bit | |
| 495 | + | EXP = 0 # 64 bit | |
| 496 | + | PP = 0 # 64 bit | |
| 497 | + | RankSingle = 0 # 64 bit | |
| 498 | + | RankDouble = 0 # 64 bit | |
| 499 | + | RunningStep = 0 # 64 bit | |
| 500 | + | PlayCount = 0 # 32 bit | |
| 501 | + | Kcal = 0 # Float | |
| 502 | + | Modifiers = 0 # 64 bit | |
| 503 | + | unk3 = 0 # 32 bit | |
| 504 | + | RushSpeed = 0 # Float | |
| 505 | + | unk4 = 0 # 32 bit | |
| 506 | + | Scores = [] # 4384 uScore Items | |
| 507 | + | ||
| 508 | + | def ToBinary(self): | |
| 509 | + | data0 = struct.pack("<3I36s12sI4B5QIfQIfI", self.PacketHead, self.PacketType, self.PlayerID, self.AccessCode, self.Nickname, self.ProfileID, self.CountryID, self.Avatar, self.Level, self.unk2, self.EXP, self.PP, self.RankSingle, self.RankDouble, self.RunningStep, self.PlayCount, self.Kcal, self.Modifiers, self.unk3, self.RushSpeed, self.unk4) | |
| 510 | + | data1 = "" | |
| 511 | + | for i in self.Scores: | |
| 512 | + | data1 += i.ToBinary() | |
| 513 | + | ||
| 514 | + | data1 += "\x00" * (4384 - len(self.Scores)) * self.__USCORE_PACK_LENGTH | |
| 515 | + | return data0 + data1 | |
| 516 | + | ||
| 517 | + | def FromBinary(self,binary): | |
| 518 | + | data0 = binary[:0x88] | |
| 519 | + | data1 = binary[0x88:] | |
| 520 | + | self.PacketHead, self.PacketType, self.PlayerID, self.AccessCode, self.Nickname, self.ProfileID, self.CountryID, self.Avatar, self.Level, self.unk2, self.EXP, self.PP, self.RankSingle, self.RankDouble, self.RunningStep, self.PlayCount, self.Kcal, self.Modifiers, self.unk3, self.RushSpeed, self.unk4 = struct.unpack("<3I36s12sI4B5QIfQIfI", data0) | |
| 521 | + | i = 0 | |
| 522 | + | c = 0 | |
| 523 | + | self.Nickname = self.Nickname.split("\x00")[0] | |
| 524 | + | while i < len(data1): | |
| 525 | + | scoretmp = uScore() | |
| 526 | + | scoretmp.FromBinary(data1[i:i+self.__USCORE_PACK_LENGTH]) | |
| 527 | + | if scoretmp.SongID != 0: | |
| 528 | + | self.Scores.append(scoretmp) | |
| 529 | + | c += 1 | |
| 530 | + | i += self.__USCORE_PACK_LENGTH | |
| 531 | + | #print "Loaded %s uScores" %c | |
| 532 | + | ||
| 533 | + | def Print(self): | |
| 534 | + | print "Profile Packet" | |
| 535 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 536 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 537 | + | print "\tPlayerID: %s (0x%x)" %(self.PlayerID, self.PlayerID) | |
| 538 | + | print "\tAcessCode: %s" %self.AccessCode | |
| 539 | + | print "\tNickName: %s" %self.Nickname | |
| 540 | + | print "\tProfileID: %s (0x%x)" %(self.ProfileID, self.ProfileID) | |
| 541 | + | print "\tCountryID: %s (0x%x)" %(self.CountryID, self.CountryID) | |
| 542 | + | print "\tAvatar: %s (0x%x)" %(self.Avatar, self.Avatar) | |
| 543 | + | print "\tLevel: %s " %(self.Level) | |
| 544 | + | print "\tUnknown uint32_t 2: %s (0x%x)" %(self.unk2, self.unk2) | |
| 545 | + | print "\tExperience: %s" %self.EXP | |
| 546 | + | print "\tPP: %s" %self.PP | |
| 547 | + | print "\tRank Single: %s (0x%x)" %(self.RankSingle, self.RankSingle) | |
| 548 | + | print "\tRank Double: %s (0x%x)" %(self.RankDouble, self.RankDouble) | |
| 549 | + | print "\tRunning Steps: %s" % self.RunningStep | |
| 550 | + | print "\tPlay Count: %s" % self.PlayCount | |
| 551 | + | print "\tKcal: %s" % self.Kcal | |
| 552 | + | print "\tModifiers: %s (0x%x)" % (self.Modifiers, self.Modifiers) | |
| 553 | + | print "\tUnknown uint32_t 3: %s (0x%s)" % (self.unk3, self.unk3) | |
| 554 | + | print "\tRush Speed: %s" % self.RushSpeed | |
| 555 | + | print "\tUnknown uint32_t 3: %s (0x%s)" % (self.unk3, self.unk4) | |
| 556 | + | print "\tScore Board: " | |
| 557 | + | for i in self.Scores: | |
| 558 | + | i.Print() | |
| 559 | + | ||
| 560 | + | class RequestLevelUpInfoPacket(): | |
| 561 | + | ''' | |
| 562 | + | Packet send by client after all musics has been played. | |
| 563 | + | ''' | |
| 564 | + | ||
| 565 | + | PacketHead = 1 | |
| 566 | + | PacketType = 0x100000C | |
| 567 | + | ProfileID = 3029 | |
| 568 | + | ||
| 569 | + | def ToBinary(self): | |
| 570 | + | return struct.pack("<3I", self.PacketHead, self.PacketType, self.ProfileID) | |
| 571 | + | ||
| 572 | + | def FromBinary(self,binary): | |
| 573 | + | self.PacketHead, self.PacketType, self.ProfileID = struct.unpack("<3I", binary) | |
| 574 | + | ||
| 575 | + | def Print(self): | |
| 576 | + | print "RequestLevelUpInfoPacket: " | |
| 577 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 578 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 579 | + | print "\tProfileID: %s (0x%x)" %(self.ProfileID, self.ProfileID) | |
| 580 | + | ||
| 581 | + | class LevelUpInfoPacket(): | |
| 582 | + | ''' | |
| 583 | + | Packet send by server after receiving a RequestLevelUpInfoPacket | |
| 584 | + | ''' | |
| 585 | + | PacketHead = 1 | |
| 586 | + | PacketType = 0x100000D | |
| 587 | + | ProfileID = 3029 | |
| 588 | + | Level = 0 | |
| 589 | + | ||
| 590 | + | def ToBinary(self): | |
| 591 | + | return struct.pack("<4I", self.PacketHead, self.PacketType, self.ProfileID, self.Level) | |
| 592 | + | ||
| 593 | + | def FromBinary(self,binary): | |
| 594 | + | self.PacketHead, self.PacketType, self.ProfileID, self.Level = struct.unpack("<4I", binary) | |
| 595 | + | ||
| 596 | + | def Print(self): | |
| 597 | + | print "EnterProfilePacket: " | |
| 598 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 599 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 600 | + | print "\tProfileID: %s (0x%x)" %(self.ProfileID, self.ProfileID) | |
| 601 | + | print "\tLevel: %s" %(self.Level) | |
| 602 | + | ||
| 603 | + | ||
| 604 | + | class GameOverPacket(): | |
| 605 | + | ''' | |
| 606 | + | Packet send by client on GameOver | |
| 607 | + | ''' | |
| 608 | + | ||
| 609 | + | PacketHead = 1 | |
| 610 | + | PacketType = 0x1000001 | |
| 611 | + | ProfileID = 3029 | |
| 612 | + | ||
| 613 | + | def ToBinary(self): | |
| 614 | + | return struct.pack("<3I", self.PacketHead, self.PacketType, self.ProfileID) | |
| 615 | + | ||
| 616 | + | def FromBinary(self,binary): | |
| 617 | + | self.PacketHead, self.PacketType, self.ProfileID = struct.unpack("<3I", binary) | |
| 618 | + | ||
| 619 | + | def Print(self): | |
| 620 | + | print "EnterProfilePacket: " | |
| 621 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 622 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 623 | + | print "\tProfile ID: %s (0x%x)" %(self.ProfileID, self.ProfileID) | |
| 624 | + | ||
| 625 | + | class WorldBestScore(): | |
| 626 | + | ''' | |
| 627 | + | WorldBest Entry | |
| 628 | + | ''' | |
| 629 | + | SongID = 0 | |
| 630 | + | ChartLevel = 0 | |
| 631 | + | ChartMode = 0 | |
| 632 | + | Score = 0 | |
| 633 | + | unk0 = 0 | |
| 634 | + | unk1 = 0 | |
| 635 | + | Nickname = "" | |
| 636 | + | ||
| 637 | + | def ToBinary(self): | |
| 638 | + | return struct.pack("<I2H3I12s", self.SongID, self.ChartLevel, self.ChartMode, self.Score, self.unk0, self.unk1, self.Nickname) | |
| 639 | + | ||
| 640 | + | def FromBinary(self,binary): | |
| 641 | + | self.SongID, self.ChartLevel, self.ChartMode, self.Score, self.unk0, self.unk1, self.Nickname = struct.unpack("<I2H3I12s", binary) | |
| 642 | + | self.Nickname = self.Nickname.split("\x00")[0] | |
| 643 | + | ||
| 644 | + | def Print(self): | |
| 645 | + | print "\tNickname: %s - SongID: %x (lvl %s mode 0x%x) - Score: %s - Unk(%s[0x%x],%s[0x%x])" %(self.Nickname, self.SongID, self.ChartLevel, self.ChartMode, self.Score, self.unk0, self.unk0, self.unk1, self.unk1) | |
| 646 | + | ||
| 647 | + | class WorldBestPacket(): | |
| 648 | + | ''' | |
| 649 | + | World Best Packet | |
| 650 | + | ''' | |
| 651 | + | __WORLDBESTSCORE_PACK_LENGTH = 32 | |
| 652 | + | ||
| 653 | + | PacketHead = 2 | |
| 654 | + | PacketType = 0x1000009 | |
| 655 | + | Scores = [] # 4096 | |
| 656 | + | ||
| 657 | + | def ToBinary(self): | |
| 658 | + | data0 = struct.pack("<2I", self.PacketHead, self.PacketType) | |
| 659 | + | data1 = "" | |
| 660 | + | for i in self.Scores: | |
| 661 | + | data1 += i.ToBinary() | |
| 662 | + | ||
| 663 | + | data1 += "\x00" * (4096 - len(self.Scores)) * self.__USCORE_PACK_LENGTH | |
| 664 | + | return data0 + data1 | |
| 665 | + | ||
| 666 | + | def FromBinary(self,binary): | |
| 667 | + | data0 = binary[:0x8] | |
| 668 | + | data1 = binary[0x8:] | |
| 669 | + | self.PacketHead, self.PacketType = struct.unpack("<2I", data0) | |
| 670 | + | i = 0 | |
| 671 | + | c = 0 | |
| 672 | + | while i < len(data1): | |
| 673 | + | scoretmp = WorldBestScore() | |
| 674 | + | scoretmp.FromBinary(data1[i:i+self.__WORLDBESTSCORE_PACK_LENGTH ]) | |
| 675 | + | if scoretmp.SongID != 0: | |
| 676 | + | self.Scores.append(scoretmp) | |
| 677 | + | c += 1 | |
| 678 | + | i += self.__WORLDBESTSCORE_PACK_LENGTH | |
| 679 | + | print "Loaded %s World Best Scores" %c | |
| 680 | + | ||
| 681 | + | def Print(self): | |
| 682 | + | print "World Best Score Packet" | |
| 683 | + | print "\tPacketHead: %s (0x%x)" %(self.PacketHead,self.PacketHead) | |
| 684 | + | print "\tPacketType: %s (0x%x)" %(self.PacketType,self.PacketType) | |
| 685 | + | print "\tScores: " | |
| 686 | + | for i in self.Scores: | |
| 687 | + | i.Print() | |
Lucas Teske ревизий этого фрагмента 8 years ago. К ревизии
1 file changed, 116 insertions
geprofile.py(файл создан)
| @@ -0,0 +1,116 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | ||
| 3 | + | import socket | |
| 4 | + | import struct | |
| 5 | + | import time | |
| 6 | + | import sys | |
| 7 | + | import os | |
| 8 | + | import binascii | |
| 9 | + | from prime import * | |
| 10 | + | ||
| 11 | + | import struct | |
| 12 | + | import pysodium | |
| 13 | + | ||
| 14 | + | LAST_NOUNCE = "\x00" * 24 | |
| 15 | + | ||
| 16 | + | # Just run sudo pip install pysodium | |
| 17 | + | # And then python getprofile.py profile.bin | |
| 18 | + | # With the file that you put on the USB drive | |
| 19 | + | ||
| 20 | + | # Prime Server Public Key | |
| 21 | + | pk = "\xB0\xEB\x81\x47\x51\x0A\x2E\x20\x32\xED\x2F\xC0\xF9\xD4\xEB\x88\xB0\xCA\x2D\xBD\xE7\xD6\x4E\xE2\xD0\x83\x4C\x3B\xB6\xFB\x31\x55" | |
| 22 | + | # Prime Server Private Key | |
| 23 | + | sk = "\x93\xB2\xF8\xA0\xE0\x95\x49\xDF\xAF\xFE\x36\x56\xE6\xAD\x9C\x9A\x53\x9B\xF6\x63\xD3\x7C\x08\xF0\xA4\xE6\x29\x3C\xBF\xFA\x64\x56" | |
| 24 | + | ||
| 25 | + | try: | |
| 26 | + | os.mkdir('profiles') | |
| 27 | + | except: | |
| 28 | + | pass | |
| 29 | + | ||
| 30 | + | if len(sys.argv) == 2: | |
| 31 | + | ||
| 32 | + | if ".bin" in sys.argv[1]: | |
| 33 | + | print "File Access Key Mode" | |
| 34 | + | f = open(sys.argv[1], "rb") | |
| 35 | + | data = f.read() | |
| 36 | + | f.close() | |
| 37 | + | ACCESS_KEY = binascii.hexlify(data) | |
| 38 | + | if len(ACCESS_KEY) != 32: | |
| 39 | + | print "Invalid Access Key!" | |
| 40 | + | exit(1) | |
| 41 | + | print "Read access key from %s is %s" %(sys.argv[1],ACCESS_KEY) | |
| 42 | + | else: | |
| 43 | + | ACCESS_KEY = sys.argv[1].lower().replace(" ","") | |
| 44 | + | if len(ACCESS_KEY) != 32: | |
| 45 | + | print "Invalid Access Key: %s (parsed to: %s)" %(sys.argv[1], ACCESS_KEY) | |
| 46 | + | exit(1) | |
| 47 | + | ||
| 48 | + | IP = "115.68.108.183" | |
| 49 | + | #IP = "127.0.0.1" | |
| 50 | + | PORT = 60000 | |
| 51 | + | ||
| 52 | + | accesscode = ACCESS_KEY.lower().replace(" ","") | |
| 53 | + | ||
| 54 | + | ||
| 55 | + | ProfileID = 0 | |
| 56 | + | MachineID = 1154 | |
| 57 | + | ||
| 58 | + | login = LoginPacket() | |
| 59 | + | login.AccessCode = accesscode | |
| 60 | + | login.MachineID = MachineID | |
| 61 | + | login.PlayerID = 0 | |
| 62 | + | ||
| 63 | + | tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| 64 | + | dest = (OFICIAL_SERVER_IP, 60000) | |
| 65 | + | tcp.connect(dest) | |
| 66 | + | data = EncryptPacket(login.ToBinary(), pk, sk) | |
| 67 | + | tcp.send (data) | |
| 68 | + | time.sleep(0.01) | |
| 69 | + | ||
| 70 | + | gprof = None | |
| 71 | + | ||
| 72 | + | msg = "" | |
| 73 | + | profile = "" | |
| 74 | + | while True: | |
| 75 | + | msg += tcp.recv(4) | |
| 76 | + | if len(msg) > 0: | |
| 77 | + | size = struct.unpack("<I", msg[:4])[0] | |
| 78 | + | msg = msg[4:] | |
| 79 | + | msg += tcp.recv(size-4-len(msg)) | |
| 80 | + | while len(msg) < size-4: | |
| 81 | + | msg += tcp.recv((size-4) - len(msg)) | |
| 82 | + | ||
| 83 | + | data = DecryptPacket(msg, pk, sk) | |
| 84 | + | msg = "" | |
| 85 | + | try: | |
| 86 | + | packtype = struct.unpack("<I",data[4:8])[0] | |
| 87 | + | if packtype == ProfilePacket.PacketType: | |
| 88 | + | profile = ProfilePacket() | |
| 89 | + | profile.FromBinary(data) | |
| 90 | + | f = open ("profiles/%s" %accesscode, "wb") | |
| 91 | + | f.write(data) | |
| 92 | + | f.close() | |
| 93 | + | gprof = profile | |
| 94 | + | break | |
| 95 | + | ||
| 96 | + | elif packtype == KeepAlivePacket.PacketType: | |
| 97 | + | #print "Received KeepAlive" | |
| 98 | + | pass | |
| 99 | + | ||
| 100 | + | elif packtype == ProfileBusyPacket.PacketType: | |
| 101 | + | break | |
| 102 | + | ||
| 103 | + | else: | |
| 104 | + | #print "PacketType: %s (%x)" %(packtype, packtype) | |
| 105 | + | f = open("pack-%s-%x.bin"%(packtype,packtype),"wb") | |
| 106 | + | f.write(data) | |
| 107 | + | f.close() | |
| 108 | + | except Exception,e: | |
| 109 | + | print "Error: %s" %e | |
| 110 | + | tcp.close() | |
| 111 | + | if gprof == None: | |
| 112 | + | print '{}' | |
| 113 | + | else: | |
| 114 | + | print '{"avatar":"%s","name":"%s"}' % (gprof.Avatar, gprof.Nickname) | |
| 115 | + | else: | |
| 116 | + | print "{}" | |