Last active
June 28, 2018 08:49
-
-
Save bakugo/e7e5316c98bde8f1d7126628dfd9544f to your computer and use it in GitHub Desktop.
Python script to dump eshop tickets from Nintendo Switch system save archives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import os | |
| # arg1 should be the path to a "save" folder from nand's system partition | |
| # arg2 should be the path where the extracted tickets will be saved | |
| def main(argv): | |
| if len(argv) < 3: | |
| return 1 | |
| path_in = argv[1] | |
| path_out = argv[2] | |
| if not os.path.isdir(path_in): | |
| return 1 | |
| os.makedirs(name=path_out, exist_ok=True) | |
| if not os.path.isdir(path_out): | |
| return 1 | |
| for file in os.listdir(path_in): | |
| if file[0:4] != "8000": | |
| continue | |
| if not file[-2:] in ["e1", "e2"]: | |
| continue | |
| file_in_p = os.path.join(path_in, file) | |
| file_in_o = open(file_in_p, "rb") | |
| while True: | |
| tmp = file_in_o.read(0x20) | |
| if tmp == b"": | |
| break | |
| if tmp[0:25] == b"Root-CA00000003-XS0000002": | |
| file_in_o.seek(-0x160, os.SEEK_CUR) | |
| ticket = file_in_o.read(0x400) | |
| titleid = ticket[0x2A0:(0x2A0+0x8)] | |
| if titleid[0] == 0x01: | |
| file_out_p = "ticket.{}.bin".format(titleid.hex().upper()) | |
| file_out_p = os.path.join(path_out, file_out_p) | |
| file_out_o = open(file_out_p, "wb") | |
| file_out_o.write(ticket) | |
| file_out_o.close() | |
| continue | |
| file_in_o.close() | |
| continue | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment