def makepkm(bytes): ar = array('B') # Byte array to hold encrypted data ar.fromstring(bytes) ar = ar[12:232].tostring() pkm = decode(ar) return pkm
def gts_do_GET(self): path, query = self.path.split("?", 1) path = path.split("/")[3:] query = [q.split("=", 1) for q in query.split("&")] querydata = dict(query) print path print query if len( query ) == 1: # only pid= was set, so we havent been asked to do anything self.send(GTS_TOKEN) elif path[0] == 'common': if path[1] == 'setProfile.asp': self.send_encoded('\x00' * 8) else: print "UNKNOWN REQUEST:", path, query self.send_error(404) elif path[0] == 'worldexchange': if path[1] == 'info.asp': self.send_encoded('\x01\x00') elif path[1] == 'result.asp': global SEND_QUEUE if len(SEND_QUEUE) == 0: self.send_encoded('\x05\x00') else: rowid = SEND_QUEUE.pop() c = CONN.execute( "select pkm_struct from pokemon where rowid=?", (rowid, )) pkm = c.fetchone()[0] c.close() self.send_encoded(pkmtogts(pkm)) elif path[1] == 'delete.asp': self.send_encoded('\x01\x00') #elif path[1] == 'search.asp': # self.send_encoded('\x01\x00') elif path[1] == 'post.asp': data = querydata['data'] bytes = urlsafe_b64decode(data) pkm = pkmlib.decode(bytes[12:232]) add_pokemon(pkm, querydata['pid']) self.send_encoded( '\x0c\x00' ) # reject it, kicking the pokemon back to the client else: print "UNKNOWN REQUEST:", path, query self.send_error(404) else: self.send_error(404) self.wfile.close()
def gts_do_GET(self): path, query = self.path.split("?", 1) path = path.split("/")[3:] query = [ q.split("=",1) for q in query.split("&") ] querydata = dict(query) print path print query if len(query) == 1: # only pid= was set, so we havent been asked to do anything self.send(GTS_TOKEN) elif path[0] == 'common': if path[1] == 'setProfile.asp': self.send_encoded('\x00' * 8) else: print "UNKNOWN REQUEST:", path, query self.send_error(404) elif path[0] == 'worldexchange': if path[1] == 'info.asp': self.send_encoded('\x01\x00') elif path[1] == 'result.asp': global SEND_QUEUE if len(SEND_QUEUE) == 0: self.send_encoded('\x05\x00') else: rowid = SEND_QUEUE.pop() c = CONN.execute("select pkm_struct from pokemon where rowid=?", (rowid,)) pkm = c.fetchone()[0] c.close() self.send_encoded(pkmtogts(pkm)) elif path[1] == 'delete.asp': self.send_encoded('\x01\x00') #elif path[1] == 'search.asp': # self.send_encoded('\x01\x00') elif path[1] == 'post.asp': data = querydata['data'] bytes = urlsafe_b64decode(data) pkm = pkmlib.decode(bytes[12:232]) add_pokemon(pkm, querydata['pid']) self.send_encoded('\x0c\x00') # reject it, kicking the pokemon back to the client else: print "UNKNOWN REQUEST:", path, query self.send_error(404) else: self.send_error(404) self.wfile.close()
def download(self, event): i = 0 self.submit.SetLabel('Start') while i < int(self.count.GetValue()): self.submit.SetLabel('Stop') i += 1 try: # File download webFile = urllib.urlopen('http://'+self.ip.GetValue()+'/worldexchange/result.asp?') localFile = open(self.path.GetValue()+self.filename.GetValue()+str(i)+'.pkm', 'w') localFile.write(webFile.read()) webFile.close() localFile.close() except: wx.MessageBox('Download failed.', 'Failed') self.submit.SetLabel('Start') continue # Jump to next iteration try: # Exception = File not exists f = open(self.path.GetValue()+self.filename.GetValue()+str(i)+'.pkm', 'r') pkm = f.read() f.close() except: wx.MessageBox('Download failed.\n'+self.filename.GetValue()+str(i)+'.pkm not exists.', 'Failed') self.submit.SetLabel('Start') continue # Jump to next iteration # Shifting f = open(self.path.GetValue()+self.filename.GetValue()+str(i)+'.pkm', 'r') pkm = f.read() f.close() pkm = decode(pkm) if len(pkm) != 136: pkm = pkm[0:136] #-- only take the top 136 bytes new_pkm_file_name = self.path.GetValue()+self.filename.GetValue()+str(i)+'.pkm' new_pkm_fh = open (new_pkm_file_name, 'w' ) new_pkm_fh.write(pkm) new_pkm_fh.close() if not((len(pkm) == 136) or (len(pkm) == 336)): wx.MessageBox('The Pokémon is not integer.', 'Failed') self.submit.SetLabel('Start') self.submit.SetLabel('Start')
def makepkm(bytes): ar = array('B') # Byte array to hold encrypted data ar.fromstring(bytes) # checksum is first four bytes of data, xor'd with 0x4a3b2c1d chksm = (eval('0x' + hexlify(ar[0:4]))) ^ 0x4a3b2c1d bin = ar[4:len(ar)] # Byte array for decrypt operations pkm = array('B') # ...and one for the output file # Running decryption algorithm GRNG = chksm | (chksm << 16) for i in range(len(bin)): GRNG = (GRNG * 0x45 + 0x1111) & 0x7fffffff keybyte = (GRNG >> 16) & 0xff pkm.append((bin[i] ^ keybyte) & 0xff) pkm = pkm[4:len(pkm)] pkm = pkm[0:236].tostring() pkm = decode(pkm) return pkm