Advertisement
Guest User

Untitled

a guest
Jul 26th, 2020
6,823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. # Tool to decode the internal Nintendo mails.
  4. #
  5. # Some of the emails are encoded using XOR. Use the -k option to give the tool an XOR key.
  6. #
  7. # Keys for all the emails in the leak:
  8. # /usr01/eng/Mail/inbox/1 - nishi\0
  9. # /usr01/eng/Mail/inbox/2 - is\0
  10. # /usr01/eng/Mail/inbox/3 - isw\0
  11. # /usr01/eng/Mail/inbox/4 - is\0
  12. # /usr01/eng/Mail/inbox/5 - newscad\0
  13. #
  14. # /usr01/noa/Mail/inbox/1 - angry\0
  15. # /usr01/noa/Mail/inbox/#2 - antepaenultima\0
  16. #
  17. # /usr01/rd1/Mail/inbox/1 - izushi\0
  18. #
  19. # /usr01/uji/Mail/inbox/#1 - pmdawn\0
  20. # /usr01/uji/Mail/inbox/1 - sickboy\0
  21. # /usr01/uji/Mail/inbox/2 - starwing\0
  22. # /usr01/uji/Mail/inbox/3 - toomanygames\0
  23. #
  24. # How it works:
  25. # The emails created using a Unix tool called "tarmail".
  26. # It accepts a number of files, archives them in a .tar file and compresses it using the Unix tool "compress".
  27. # The resulting .tar.Z file is then Ascii85 encoded after being optionally XOR encoded.
  28. # Finally, the Ascii85 encoded blob is added to the email between "xbtoa Begin" and "xbtoa End" guards.
  29. #
  30. # Sidenote:
  31. # The "N 1069052 104ffc E bf S 5a188d9 R 40799495" junk after "xbtoa End" is just some checksums.
  32. # You can find a btoa implementation which generates the checksum here:
  33. # https://github.com/geoffmcl/compressW/blob/master/src/btoa.c
  34. #
  35. # Example usage:
  36. # python decode.py -i 'other/NEWS/テープリストア/NEWS_02/usr01/uji/Mail/inbox/1' -k 'sickboy\0'
  37. #
  38. #
  39. import sys, os, getopt, base64
  40.  
  41. def printHelp():
  42. print('decode.py -i <inputfile> -o <outputfile> -k <keyword>')
  43.  
  44. def main(argv):
  45. inputfilename = ''
  46. outputfilename = ''
  47. keyword = ''
  48. infile = ''
  49.  
  50. try:
  51. opts, args = getopt.getopt(argv,'hi:o:k:')
  52. except getopt.GetoptError:
  53. printHelp()
  54. sys.exit(2)
  55. for opt, arg in opts:
  56. if opt == '-h':
  57. printHelp()
  58. sys.exit()
  59. elif opt == '-i':
  60. inputfilename = arg
  61. elif opt == '-o':
  62. outputfilename = arg
  63. elif opt == '-k':
  64. keyword = arg
  65. if inputfilename == '':
  66. printHelp()
  67. sys.exit(2)
  68.  
  69. # Read
  70. infile = open(inputfilename, 'r')
  71. data = infile.read()
  72. infile.close()
  73.  
  74. # Extract encoded section of the email
  75. xbtoaBeginStr = 'xbtoa Begin\n'
  76. xbtoaEndStr = 'xbtoa End'
  77. xbtoaBegin = data.find(xbtoaBeginStr)
  78. xbtoaEnd = data.find(xbtoaEndStr)
  79. if xbtoaBegin == -1 or xbtoaEnd == -1:
  80. print('Not a valid tarmail')
  81. sys.exit(1)
  82.  
  83. # Ascii85 decode
  84. xbtoa = data[(xbtoaBegin+len(xbtoaBeginStr)):xbtoaEnd]
  85. binary = bytearray(base64.a85decode(xbtoa))
  86.  
  87. # XOR decode the file, if key was given
  88. if keyword != '':
  89. keyword = keyword.replace('\\0', '\x00') # Replace \0 in the key with 0x00
  90. keyword = keyword.encode()
  91. klen = len(keyword)
  92. for i in range(len(binary)):
  93. binary[i] ^= keyword[i % klen]
  94.  
  95. # Make output filename if non was given
  96. if outputfilename == '':
  97. inbasename = os.path.basename(inputfilename)
  98. outputfilename = inbasename+'.tar.Z'
  99.  
  100. # Output
  101. outfile = open(outputfilename, 'wb')
  102. outfile.write(bytes(binary))
  103. outfile.close()
  104.  
  105. if __name__ == "__main__":
  106. main(sys.argv[1:])
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement