This python 2.7 script will try to decrypt eShop content files.


This python 2.7 script will try to decrypt eShop content files.
Tested with 'game', 'game manual' and 'download play' content files.
The output decrypted .cxi should be able to be played in Citra,
Just place put the output decrypted .cxi file in your roms folder.

Note: This is a work in progress... may have bugs or output file may not be decrypted properly.

Command Line:
python eshop_content_to_cxi.py <content_filename> <DECRYPTED_KEY!> <Content_Index> <Seed>

Command line args (All are required - except for seed if its not used)
arg1 = Filename of eShop content file (e.g '00000000')
arg2 = Decrypted_Key (Encrypted key would need TitleID too, its easier using decrypted key)
arg3 = Content Index, usually '0000' for main game, '0001' for game manual and '0002' for download play data)
arg4 = Seed (note: If a seed is used and not supplied, script will crash)

Example:
python eshop_content_to_cxi.py FILENAME DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 0000 66666666666666666666666666666666

---
You can extract the content files from an encrypted CIA with 'ctrtool'
e.g ctrtool --contents="game" --tik="game.cetk" --tmd="game.tmd" -p -x "game.cia"

for Windows users - Here is a batch file that will extract all CIAs:

for %%a in (*.cia) do ctrtool.exe --contents="%%~na" --tik="%%~na.cetk" --tmd="%%~na.tmd" -p -x "%%a"

Once finished, you should get files like "game.0000.0000002" and "game.0001.0000002"
where '0000' is the content index, and '00000002' is the content filename.

The decrypted key can be found in the 'dec_titleKeys.txt' file (search for Title ID) or on the 3ds titlekeys site.

The seed can be found in the 'seeddb.txt' files (search for the Title ID).
if its not there and you are sure the game uses one,
you can download it from the official eshop seed server below:

Note: The downloaded seed file is in a binary format, so you'll need to use
a hex editor so similar program to get the hex-encoded key the script needs.

Seed URL: (Replace %TITLEID% with the TitleID.
https://kagiya-ctr.cdn.nintendo.net/title/0x%TITLEID%/ext_key?country=US

Example:
https://kagiya-ctr.cdn.nintendo.net/title/0x0004000000123400/ext_key?country=US
