#!/usr/bin/env python3 import urllib.parse, urllib.request import base64 import binascii def decode(in_str): # parse data into array of key,value pairs data = urllib.parse.parse_qsl(in_str) decoded = [] # replace afterfisks with equals, base64-decode values, add to new array for pair in data: key = pair[0] value = pair[1] value = value.replace('*', '=') decoded.append((key, base64.b64decode(value))) # also create a hex version for convenience in working with binary fields # hexed = [(key, binascii.hexlify(value)) for (key, value) in decoded] return (data, decoded) def format_decode(in_str): # remove newlines previously added for editing convenience in_str = in_str.replace('\n', '') out = '' # decode the string decoded = decode(in_str) # format everything, one pair per line out += 'Decoded\n' for pair in decoded[1]: if pair[0] == 'ingamesn': value = pair[1] out += "('ingamesn', '" + value.decode('utf-16be') + "'.encode('utf-16be'))\n" else: out += str(pair) + '\n' return out def print_decode(in_str): # possible side effects may include nausea, vomiting, # diarrhea, fainting, death, and console output print(format_decode(in_str)) ##f = open('C:\\Users\\jimbo1qaz\\Documents\\Dolphin Emulator\\wifi\\uneek_dolphin_good_decode.txt', 'w') ##f.write(format_decode('')) ##f.close() def make_request(in_arr): url_arr = [] for key, value in in_arr: ## #unhexlify if needed ## if value[0:2] == '0x' or value[0:2] == '0X' or \ ## value[0:2] == b'0x' or value[0:2] == b'0X': ## value = binascii.unhexlify(value) # base64 encode, replace equals with astronauts encoded = base64.b64encode(value) encoded = encoded.replace(b'=', b'*') url_arr.append((key, encoded)) return urllib.parse.urlencode(url_arr)