def pcsearch(): print '\nWill search Pokecheck.org for PID and level, might\nbe multiple results with different species.\n\n' while True: print 'Enter pkm file' print '(Type Back to go back)' path = raw_input().strip() if path == "Back" or path == "back": return path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path.startswith('"') or path.startswith("'"): path = path[1:] if path.endswith('"') or path.endswith("'"): path = path[:-1] if os.path.exists(path) and path.lower().endswith('.pkm'): break else: print 'Invalid file name, try again' continue with open(path, 'rb') as f: pkm = f.read() if len(pkm) != 220 and len(pkm) != 136: print 'Invalid filesize: %d bytes. Needs to be either 136 or 220 bytes.' % len( pkm) return if len(pkm) == 136: print 'Pokemon is in PC format; adding party information now... ', pkm = makeparty(pkm) print 'Done.' p = array('B') p.fromstring(pkm) pid = hex(struct.unpack('<0s4L', open(path, 'rb').read(16))[1])[:-1] lvl = str(p[0x8c]) print 'Opening new browser window with search results...' sleep(5) url = 'https://www.pokecheck.org/?p=search&pid=%s&lvf=1&lvl=%s' % (pid, lvl) open_new(url)
def pcsearch(): print '\nWill search Pokecheck.org for PID and level, might\nbe multiple results with different species.\n\n' while True: print 'Enter pkm file' print '(Type Back to go back)' path = raw_input().strip() if path == "Back" or path == "back": return path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path.startswith('"') or path.startswith("'"): path = path[1:] if path.endswith('"') or path.endswith("'"): path = path[:-1] if os.path.exists(path) and path.lower().endswith('.pkm'): break else: print 'Invalid file name, try again' continue with open(path, 'rb') as f: pkm = f.read() if len(pkm) != 220 and len(pkm) != 136: print 'Invalid filesize: %d bytes. Needs to be either 136 or 220 bytes.' % len(pkm) return if len(pkm) == 136: print 'Pokemon is in PC format; adding party information now... ', pkm = makeparty(pkm) print 'Done.' p = array('B') p.fromstring(pkm) pid = hex(struct.unpack('<0s4L', open(path, 'rb').read(16))[1])[:-1] lvl = str(p[0x8c]) print 'Opening new browser window with search results...' sleep(5) url = 'https://www.pokecheck.org/?p=search&pid=%s&lvf=1&lvl=%s' % (pid, lvl) open_new(url)
def sendpkm(): print 'Note: you must exit the GTS before sending a pkm' print '4th Gen Pokemon files are currently unsupported.' print 'Enter the path or drag the pkm file here' path = raw_input().strip() path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path.startswith('"') or path.startswith("'"): path = path[1:] if path.endswith('"') or path.endswith("'"): path = path[:-1] if path.lower().endswith('.pkm'): with open(path, 'rb') as f: pkm = f.read() # Adding extra 100 bytes of party data if len(pkm) != 220 and len(pkm) != 136: print 'Invalid filesize: %d bytes.' % len(pkm) return if len(pkm) == 136: print 'PC-Boxed Pokemon! Adding party data...', pkm = makeparty(pkm) print 'done.' print 'Encoding!' bin = encode(pkm) ### # Support for .3gpkm files. Currently unfinished. ### # elif path.lower().endswith('.3gpkm'): # print 'Converting GBA file to NDS format...', # with open(path, 'rb') as f: # pkm = f.read() # # if len(pkm) != 80 and len(pkm) != 100: # print 'Invalid filesize.' # return # pkm = makends(pkm) # print 'done.' # # print 'Encoding!' # bin = encode(pkm) ### # ### else: print 'Filename must end in .pkm' return # Adding GTS data to end of file bin += '\x00' * 16 bin += pkm[0x08:0x0a] # id if ord(pkm[0x40]) & 0x04: bin += '\x03' # Gender else: bin += chr((ord(pkm[0x40]) & 2) + 1) bin += pkm[0x8c] # Level bin += '\x01\x00\x03\x00\x00\x00\x00\x00' # Requesting bulba, either, any bin += '\xdb\x07\x03\x0a\x00\x00\x00\x00' # Date deposited (10 Mar 2011) bin += '\xdb\x07\x03\x16\x01\x30\x00\x00' # Date traded (?) bin += pkm[0x00:0x04] # PID bin += pkm[0x0c:0x0e] # OT ID bin += pkm[0x0e:0x10] # OT Secret ID bin += pkm[0x68:0x78] # OT Name bin += '\xDB\x02' # Country, City bin += '\x46\x01\x15\x02' # Sprite, Exchanged (?), Version, Lang bin += '\x01\x00' # Unknown sent = False response = '' print 'Ready to send; you can now enter the GTS...' while not sent: sock, req = getReq() a = req.action if len(req.getvars) == 1: sendResp(sock, gtsvar.token) continue elif a == 'info': response = '\x01\x00' print 'Connection Established.' elif a == 'setProfile': response = '\x00' * 8 elif a == 'post': response = '\x0c\x00' elif a == 'search': response = '\x01\x00' elif a == 'result': response = bin elif a == 'delete': response = '\x01\x00' sent = True m = hashlib.sha1() m.update(gtsvar.salt + urlsafe_b64encode(response) + gtsvar.salt) response += m.hexdigest() sendResp(sock, response) print 'Pokemon sent successfully.',
def makends(gba): # Deconstructing GBA .3gpkm file pid = gba[0:4] otid = gba[4:8] nickname = convertname(gba[8:18]) nickname = extendname(nickname, False) lang = gba[18] otname = convertname(gba[20:27]) species = ord(gba[32]) + (ord(gba[33]) << 8) species = pokemonindex.get(species) gend = genderbyte(species, pid) forme = form(species, gend, pid) nicknamed = namegen.namegen(nickname) != stats.species.get(species).upper() ability = abilities.get(species) species = chr(species & 0xff) + chr((species >> 8) & 0xff) item = gba[34:36] exp = gba[36:40] ppup = ord(gba[40]) ppupa = chr(ppup & 3) ppupb = chr((ppup >> 2) & 3) ppupc = chr((ppup >> 4) & 3) ppupd = chr((ppup >> 6) & 3) happy = gba[41] atk1 = gba[44:46] atk2 = gba[46:48] atk3 = gba[48:50] atk4 = gba[50:52] pp1 = gba[52] pp2 = gba[53] pp3 = gba[54] pp4 = gba[55] hpev = gba[56] atkev = gba[57] defev = gba[58] speev = gba[59] spaev = gba[60] spdev = gba[61] pkrs = gba[68] lvmet = ord(gba[70]) & 0x7f fmlot = ord(gba[71]) & 0x80 ivs = gba[72:76] ribbons = gba[76:80] # Generating NDS .pkm file pkm = species + item + otid + exp + happy pkm += ability[ord(pid[0]) % 2] pkm += '\x00' # Markings pkm += lang + hpev + atkev + defev + speev + spaev + spdev pkm += '\x00' * 10 # Contest values, Sinnoh ribbons pkm += atk1 + atk2 + atk3 + atk4 + pp1 + pp2 + pp3 + pp4 pkm += ppupa + ppupb + ppupc + ppupd pkm += ivbytes(ivs, nicknamed) pkm += ribbons # Hoenn ribbons pkm += chr(forme) pkm += '\x00' * 5 + '\x37\x00' # Shiny leaves, padding, egg from, met at pkm += nickname pkm += '\x00\x03' # Padding, hometown (Hoenn, Emerald) pkm += '\x00' * 8 # Sinnoh Ribbons, Padding pkm += extendname(otname, True, pkm[0x40:0x50]) pkm += '\x00' * 3 # Date egg received pkm += datemet() pkm += '\x00' * 2 # Egg location pkm += '\x37\x00' # Location met (Migrated from Emerald) pkm += pkrs pkm += '\x04' # Poke ball pkm += chr(lvmet | fmlot) pkm += '\x00' # Encounter type pkm += '\x04' # Poke ball pkm += '\x00' # Padding chksm = getsum(pkm) pkm = pid + '\x00\x00' + chksm + pkm return makeparty(pkm)
def statana(): while True: print 'Enter .PKM file path' print '(Type Back to go back)' path = raw_input().strip() if path == 'Back' or path == 'back': return path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path.startswith('"') or path.startswith("'"): path = path[1:] if path.endswith('"') or path.endswith("'"): path = path[:-1] if os.path.exists(path) and path.lower().endswith('.pkm'): break else: print 'Invalid file name, try again' continue with open(path, 'rb') as f: pkm = f.read() if len(pkm) != 220 and len(pkm) != 136: print 'Invalid filesize: %d bytes. Needs to be either 136 or 220 bytes.' % len(pkm) return if len(pkm) == 136: print 'Pokemon is in PC format; adding party information now... ', pkm = makeparty(pkm) print 'Done.' p = array('B') p.fromstring(pkm) s = statsetup(p, pkm, path) print '\nBeginning analysis:\n' print s csum = struct.unpack('<6s1H', open(path, 'rb').read(8))[1] fcsum = struct.unpack(">I", struct.pack("<I", csum))[0] fcsum = ("%02x" % fcsum)[:-4] csum = struct.unpack(">I", struct.pack(">I", csum))[0] words = struct.unpack('<8s64H', open(path, 'rb').read(136))[1:] lilesum = sum(words) & 65535 bigesum = struct.unpack(">I", struct.pack("<I", lilesum))[0] calcsum = ("%02x" % bigesum)[:-4] if lilesum != csum: print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" print "File's checksum is incorrect(%s), should be %s." % (fcsum, calcsum) print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" b = (p[0x38:0x3c]) ivs = b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24) hp = (ivs & 0x0000001f) atk = (ivs & 0x000003e0) >> 5 df = (ivs & 0x00007c00) >> 10 spe = (ivs & 0x000f8000) >> 15 spa = (ivs & 0x01f00000) >> 20 spd = (ivs & 0x3e000000) >> 25 total = hp + atk + df + spe + spa + spd if total == 186: print "\n! IVs are perfect, could be RNG abused or hacked. !" elif total >= 187: print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" print "IVs are too high, none can exceed 31." print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" evs = p[0x18:0x1e] total = evs[0] + evs[1] + evs[2] + evs[3] + evs[4] + evs[5] if total == 508: print "\n! Total EVs exactly 508. !" elif total == 510: print "\n! Total EVs exactly 510. !" elif total >= 511: print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" print "Total EVs over 510, too high." print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" if p[0x40] & 4: gender = 0 #Genderless elif p[0x40] & 2: gender = 1 #Female else: gender = 2 #Male pid = struct.unpack('<0s4L', open(path, 'rb').read(16))[1] rgender = p[0x00] if rgender <= 128: cgender = 1 #Female if rgender >= 128: cgender = 2 #Male genratio = rgender / 2.56 if gender != cgender and gender == 1: print "\n! Probably female, check gender ratio (file's ratio is %d%%). !" % (genratio) if gender != cgender and gender == 2: print "\n! Probably male, check gender ratio (file's ratio is %d%%). !" % (genratio) if p[0x5f] == 0: print '\n!!!!!!!!!!!!!!!!!!!!!!!' print 'Game of origin not set.' print '!!!!!!!!!!!!!!!!!!!!!!!' elif p[0x5f] == 24 or p[0x5f] == 25: print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' print 'Game of origin too new (X/Y gen 6).' print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' secid = (p[0x0f] << 8) + p[0x0e] if secid == 0: print "\n!!!!! Secret ID is 0 (could be an event). !!!!!" print '\n========End of analysis========\n' statread(pkm, path) print '\n'
def sendingpkm(path): with open(path, 'rb') as f: pkm = f.read() # Adding extra 100 bytes of party data if len(pkm) != 220 and len(pkm) != 136: print 'Invalid filesize: %d bytes. Needs to be either 136 or 220 bytes.' % len(pkm) return if len(pkm) == 136: print 'Pokemon is in PC format; adding party information now... ', pkm = makeparty(pkm) print 'Done.' print 'Encoding!' bin = encode(pkm) ### # Support for .3gpkm files. Currently unfinished. ### # elif path.lower().endswith('.3gpkm'): # print 'Converting GBA file to NDS format...', # with open(path, 'rb') as f: # pkm = f.read() # # if len(pkm) != 80 and len(pkm) != 100: # print 'Invalid filesize.' # return # pkm = makends(pkm) # print 'done.' # # print 'Encoding!' # bin = encode(pkm) ### # ### # Adding GTS data to end of file print 'Adding GTS data... ' bin += '\x00' * 16 bin += pkm[0x08:0x0a] # id if ord(pkm[0x40]) & 0x04: bin += '\x03' # Gender else: bin += chr((ord(pkm[0x40]) & 2) + 1) bin += pkm[0x8c] # Level bin += '\x01\x00\x03\x00\x00\x00\x00\x00' # Requesting bulba, either, any bin += '\xdb\x07\x03\x0a\x00\x00\x00\x00' # Date deposited (10 Mar 2011) bin += '\xdb\x07\x03\x16\x01\x30\x00\x00' # Date traded (?) bin += pkm[0x00:0x04] # PID bin += pkm[0x0c:0x0e] # OT ID bin += pkm[0x0e:0x10] # OT Secret ID bin += pkm[0x68:0x78] # OT Name bin += '\xDB\x02' # Country, City bin += '\x46\x01\x15\x02' # Sprite, Exchanged (?), Version, Lang bin += '\x01\x00' # Unknown print 'Done.' sent = False response = '' print 'Ready to send; you can now enter the GTS.' while not sent: sock, req = getReq() a = req.action if len(req.getvars) == 1: sendResp(sock, gtsvar.token) continue elif a == 'info': response = '\x01\x00' print 'Connection established.' elif a == 'setProfile': response = '\x00' * 8 elif a == 'post': response = '\x0c\x00' elif a == 'search': response = '\x01\x00' elif a == 'result': response = bin elif a == 'delete': response = '\x01\x00' sent = True m = hashlib.sha1() m.update(gtsvar.salt + urlsafe_b64encode(response) + gtsvar.salt) response += m.hexdigest() sendResp(sock, response) print 'Pokemon sent successfully.',
def sendpkm(): token = 'c9KcX1Cry3QKS2Ai7yxL6QiQGeBGeQKR' print 'Note: you must exit the GTS before sending a pkm' print 'Enter the path or drag the pkm file here' path = raw_input().strip() path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if path.lower().endswith('.pkm'): with open(path, 'rb') as f: pkm = f.read() # Adding extra 100 bytes of party data if len(pkm) != 236 and len(pkm) != 136: print 'Invalid filesize.' return if len(pkm) == 136: print 'PC-Boxed Pokemon! Adding party data...', pkm = makeparty(pkm) print 'done.' print 'Encoding!' bin = encode(pkm) elif path.lower().endswith('.3gpkm'): print 'Converting GBA file to NDS format...', with open(path, 'rb') as f: pkm = f.read() if len(pkm) != 80 and len(pkm) != 100: print 'Invalid filesize.' return pkm = makends(pkm) print 'done.' print 'Encoding!' bin = encode(pkm) else: print 'Filename must end in .pkm or .3gpkm' return # Adding GTS data to end of file bin += pkm[0x08:0x0a] # id if ord(pkm[0x40]) & 0x04: bin += '\x03' # Gender else: bin += chr((ord(pkm[0x40]) & 2) + 1) bin += pkm[0x8c] # Level bin += '\x01\x00\x03\x00\x00\x00\x00\x00' # Requesting bulba, either, any bin += '\x00' * 20 # Timestamps and PID bin += pkm[0x68:0x78] # OT Name bin += pkm[0x0c:0x0e] # OT ID bin += '\xDB\x02' # Country, City bin += '\x46\x00\x07\x02' # Sprite, Exchanged (?), Version, Lang sent = False delete = False print 'Ready to send; you can now enter the GTS...' while not sent: sock, req = getReq() a = req.action if len(req.getvars) == 1: sendResp(sock, token) elif a == 'info': sendResp(sock, '\x01\x00') print 'Connection Established.' elif a == 'setProfile': sendResp(sock, '\x00' * 8) elif a == 'post': sendResp(sock, '\x0c\x00') elif a == 'search': sendResp(sock, '') elif a == 'result': sendResp(sock, bin) elif a == 'delete': sendResp(sock, '\x01\x00') sent = True print 'Pokemon sent successfully.',
def sendpkm(): print 'Enter (or simply drag&drop) the path of the directory which contains the Pokémon:' path = raw_input().strip() if path.startswith('\'') or path.endswith('\''): path = path.replace('\'', '') path = os.path.normpath(path) if system() != 'Windows': path = path.replace('\\', '') if not path.endswith('/'): path = path + '/' else: if not path.endswith('\\'): path = path + '\\' while True: dirs = [ ] # Just you add/remove a file from your Pokémon directory, isn't a good thing killing the software :( for i in os.listdir(path): if i.lower().endswith('.pkm'): dirs.append(i) fileName = dirs[random.randint(0, len(dirs) - 1)] pokeyman = path + fileName # Shifting f = open(pokeyman, '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() f = open(pokeyman, 'r') pkm = f.read() f.close() # Adding extra 100 bytes of party data if len(pkm) != 220 and len(pkm) != 136: print 'Invalid filesize: %d bytes.' % len(pkm) return if len(pkm) == 136: print 'PC-Boxed Pokemon! Adding party data...', pkm = makeparty(pkm) print 'done.' print 'Encoding!' bin = encode(pkm) else: print 'Filename must end in .pkm' return # Adding GTS data to end of file bin += '\x00' * 16 bin += pkm[0x08:0x0a] # id if ord(pkm[0x40]) & 0x04: bin += '\x03' # Gender else: bin += chr((ord(pkm[0x40]) & 2) + 1) bin += pkm[0x8c] # Level bin += '\x01\x00\x03\x00\x00\x00\x00\x00' # Requesting bulba, either, any bin += '\xdb\x07\x03\x0a\x00\x00\x00\x00' # Date deposited (10 Mar 2011) bin += '\xdb\x07\x03\x16\x01\x30\x00\x00' # Date traded (?) bin += pkm[0x00:0x04] # PID bin += pkm[0x0c:0x0e] # OT ID bin += pkm[0x0e:0x10] # OT Secret ID bin += pkm[0x68:0x78] # OT Name bin += '\xDB\x02' # Country, City bin += '\x46\x01\x15\x02' # Sprite, Exchanged (?), Version, Lang bin += '\x01\x00' # Unknown sent = False response = '' print 'Ready to send; you can now enter the GTS...' while not sent: sock, req = getReq() a = req.action if len(req.getvars) == 1: sendResp(sock, gtsvar.token) continue elif a == 'info': response = '\x01\x00' print 'Connection Established.' elif a == 'setProfile': response = '\x00' * 8 elif a == 'post': response = '\x0c\x00' elif a == 'search': response = '\x01\x00' elif a == 'result': response = bin elif a == 'delete': response = '\x01\x00' sent = True m = hashlib.sha1() m.update(gtsvar.salt + urlsafe_b64encode(response) + gtsvar.salt) response += m.hexdigest() sendResp(sock, response) print fileName + ' sent successfully.'