Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- # Tool to decode the internal Nintendo mails.
- #
- # Some of the emails are encoded using XOR. Use the -k option to give the tool an XOR key.
- #
- # Keys for all the emails in the leak:
- # /usr01/eng/Mail/inbox/1 - nishi\0
- # /usr01/eng/Mail/inbox/2 - is\0
- # /usr01/eng/Mail/inbox/3 - isw\0
- # /usr01/eng/Mail/inbox/4 - is\0
- # /usr01/eng/Mail/inbox/5 - newscad\0
- #
- # /usr01/noa/Mail/inbox/1 - angry\0
- # /usr01/noa/Mail/inbox/#2 - antepaenultima\0
- #
- # /usr01/rd1/Mail/inbox/1 - izushi\0
- #
- # /usr01/uji/Mail/inbox/#1 - pmdawn\0
- # /usr01/uji/Mail/inbox/1 - sickboy\0
- # /usr01/uji/Mail/inbox/2 - starwing\0
- # /usr01/uji/Mail/inbox/3 - toomanygames\0
- #
- # How it works:
- # The emails created using a Unix tool called "tarmail".
- # It accepts a number of files, archives them in a .tar file and compresses it using the Unix tool "compress".
- # The resulting .tar.Z file is then Ascii85 encoded after being optionally XOR encoded.
- # Finally, the Ascii85 encoded blob is added to the email between "xbtoa Begin" and "xbtoa End" guards.
- #
- # Sidenote:
- # The "N 1069052 104ffc E bf S 5a188d9 R 40799495" junk after "xbtoa End" is just some checksums.
- # You can find a btoa implementation which generates the checksum here:
- # https://github.com/geoffmcl/compressW/blob/master/src/btoa.c
- #
- # Example usage:
- # python decode.py -i 'other/NEWS/テープリストア/NEWS_02/usr01/uji/Mail/inbox/1' -k 'sickboy\0'
- #
- #
- import sys, os, getopt, base64
- def printHelp():
- print('decode.py -i <inputfile> -o <outputfile> -k <keyword>')
- def main(argv):
- inputfilename = ''
- outputfilename = ''
- keyword = ''
- infile = ''
- try:
- opts, args = getopt.getopt(argv,'hi:o:k:')
- except getopt.GetoptError:
- printHelp()
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-h':
- printHelp()
- sys.exit()
- elif opt == '-i':
- inputfilename = arg
- elif opt == '-o':
- outputfilename = arg
- elif opt == '-k':
- keyword = arg
- if inputfilename == '':
- printHelp()
- sys.exit(2)
- # Read
- infile = open(inputfilename, 'r')
- data = infile.read()
- infile.close()
- # Extract encoded section of the email
- xbtoaBeginStr = 'xbtoa Begin\n'
- xbtoaEndStr = 'xbtoa End'
- xbtoaBegin = data.find(xbtoaBeginStr)
- xbtoaEnd = data.find(xbtoaEndStr)
- if xbtoaBegin == -1 or xbtoaEnd == -1:
- print('Not a valid tarmail')
- sys.exit(1)
- # Ascii85 decode
- xbtoa = data[(xbtoaBegin+len(xbtoaBeginStr)):xbtoaEnd]
- binary = bytearray(base64.a85decode(xbtoa))
- # XOR decode the file, if key was given
- if keyword != '':
- keyword = keyword.replace('\\0', '\x00') # Replace \0 in the key with 0x00
- keyword = keyword.encode()
- klen = len(keyword)
- for i in range(len(binary)):
- binary[i] ^= keyword[i % klen]
- # Make output filename if non was given
- if outputfilename == '':
- inbasename = os.path.basename(inputfilename)
- outputfilename = inbasename+'.tar.Z'
- # Output
- outfile = open(outputfilename, 'wb')
- outfile.write(bytes(binary))
- outfile.close()
- if __name__ == "__main__":
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement