Converting .3DS to .CIA for Hackers!

Hello, and welcome to the great guide on how to convert your games to work on CFW/Gateway yourself, without ever having to read a "user-friendly" script to ever know what the hell went wrong.
At the end of this tutorial you will know how to convert your games by using tools made by others, and if you're going to repeat this process often, you will probably want to hack a script together yourself to automate this (Protip: it's actually not that difficult to copypasta some commands into your favorite text editor).
This guide is geared towards linux users, but in contrast to pre-made scripts, these commands can be used almost anywhere as long as you have the tools on said platform.
Some games are really big, and because they are stored about 2 or 3 times their size in ram during some operations, you may need a 64bit computer and/or some swap space.

So, without further ado, let's begin:

First, we need the tools. Create a directory somewhere to put them.
Let's make a list:

* The game you want to convert
* On linux, you will compile the tools yourself, as there are no prebuilt binaries. You need at least gcc, g++ and make (search in your repositories), though installing the development tools package of your distribution isn't a bad idea.
* Python 2.7 (Again, search your repositories)
* A 3DS on 4.x with the mset exploit, or a 9.0-9.2.

* slot0x25KeyX.bin (Search the interwebz, because rulez disallow me from linking)
Put the hex number you found on the webz in a file called slot0x25KeyX.bin with your favorite hex editor. Copy the file to the tools directory.

* 3DS_Multi_Decryptor (or Decrypt9 if you're on 9.x) [thread]
The former contains prebuilt binaries in the github repo, the latter has a download link for prebuilt binaries in the thread.
To compile any of both yourself, grab devkitPRO (Just grab the perl updater and set variable, it's not difficult to install), and run "make" in the source directory.
Copy Launcher.dat and ctrKeyGen.py (or ncchinfo_gen.py if using Decrypt9) to your tools directory.
Optional (For firmware >=7.x roms): Copy MEX.py from 3DS_Multi_Decryptor to your tools directory.

* ctrtool and makerom (There are several versions on github, this is the most recently updated)
On linux, for makerom comment line 130 in ncch.c as it causes a segfault (details).
Run "make" in both directories, copy the binaries (named the same as their respective directories) to your tools directory.

* padxorer
Run "gcc -O3 padxorer.c -o padxorer" and copy the binary to the tools directory.

* Optional (for manual and download play): rom_tool [thread]
Just run "make" in the rom_tool directory and copy the resulting binary to the tools directory.

* Optional (If you don't want to create the rsf file yourself): rsfgen [post]
Also get dummy.rsf.
Just put rsfgen.py and dummy.rsf in the tools directory.
NOTE: It's inportant for dummy.rsf to use dos line endings. If you copy/pasted it instead of downloading it you may have problems. If the generated file by rsfgen.py looks weird, this may be the problem.

* Optional (To reinject the original headers into the rom): ExInjector [post]
Just put the file in the tools directory.


Now you should be ready for the action.
Create a new directory, place the tools directory inside and put your game there.

First, create ncchinfo.bin (Use ncchinfo_gen.py instead if you're using Decrypt9):
Code:
python2 tools/ctrKeyGen.py game.3ds && mv tools/ncchinfo.bin .

Now, grab a working Fat32-partitioned SD card (At least 2gb, but depends on game size).
Make sure slot0x25KeyX.bin has the right contents. If it doesn't, no program will tell you about it, and will continue generating your .cia happily.
Copy tools/Launcher.dat, tools/slot0x25KeyX.bin and ncchinfo.bin to the root of your SD card.
Pop it into your 3DS and launch the mset exploit (Or go to http://dukesrg.no-ip.org/3ds/go with the browser if using Decrypt9).
Choose "NCCH padgen" from the menu (I'm not sure about Decrypt9), and wait. This should take a while.
Pop the SD back into your PC, and copy all the *.Main.*.xorpad to some directory (I'll use "xorpads").

Now, extract the encrypted contents of your game:
Code:
tools/ctrtool -p --exheader=exheader.bin --romfs=romfs.bin --exefs=exefs.bin game.3ds
It may complain about the exheader hash, but you shouldn't care.

Optional: If you have a *.Main.exefs_7x.xorpad, the game is for formware 7.x or higher. You need to merge dem xorpads.
Code:
python2 tools/MEX.py exefs.bin xorpads/*.Main.exefs_norm.xorpad xorpads/*.Main.exefs_7x.xorpad xorpads/Main.exefs_norm.xorpad && rm xorpads/*.Main.exefs*.xorpad
NOTE: I haven't tested this, because I haven't encountered a 7.x game, yet.

Now, we have to decrypt the contents of the game:
Code:
array=(exheader exefs romfs); for item in ${array[@]}; do tools/padxorer $item.bin xorpads/*Main.$item*.xorpad; done
rm *.bin
rename .bin.out .bin *.out

Now, extract the exefs to obtain the icon and banner:
Code:
tools/ctrtool --exefsdir=exefs --decompresscode -t exefs exefs.bin

Now, create the rsf:
Code:
cp tools/dummy.rsf game.rsf
python2 tools/rsfgen.py --rsf game.rsf --rom game.3ds --exheader exheader.bin --regionfree exefs/icon.bin --spoof
The --spoof option is optional if you want to enable firmware spoofing.
The --regionfree option is optional if you want to patch regionfree.
NOTE: Check the generated game.rsf file. If it looks weird, your dummy.rsf probably doesn't use dos line endings. Download it with git (or zip download), or convert it with unix2dos or similar.

Optional: If you want the manual/download play, you need to extract the .cfa:
Code:
tools/rom_tool --extract=. game.3ds
rm -f *APPDATA.cxi *UPDATEDATA.cfa

Now, create the cxi:
Code:
tools/makerom -f cxi -o game.cxi -target t -rsf game.rsf -icon exefs/icon.bin -banner exefs/banner.bin -exefslogo -code exefs/code.bin -exheader exheader.bin -romfs romfs.bin

Optional: Inject original exheader
Code:
python2 tools/ExInjector.py -rom game.cxi -exheader exheader.bin -sd -fwspoof
The -fwspoof option is optional if you want to enable firmware spoofing.
NOTE: I've tried to use this with two roms, and it stuck on the 3ds logo. You may have a different experience, though.

Now, create the final cia:
Code:
tools/makerom -f cia -o game.cia -content game.cxi:0:0 -content $(echo *MANUAL.cfa):1:1 -content $(echo *DLP.cfa):2:2
You can remove any of the -content if your game doesn't have it, or you don't want it.
It may warn you about the cia not going to be encrypted, but we want it unencrypted.

That's it! Copy, install, and play!

If you're having problems, or there's something wrong with this guide, please post it in this thread.

Appendix

How to use rxTools to make this process a bit faster when bulking:
Okay, so recently, this thing got released, called rxTools.
It's a toolkit with a lot of different functions, and one of them is bulk-decrypting .3ds games, thus making it unnecessary to screw around with xorpads.
I'm going to explain how to bulk this stuff, my style.

First of all, you're going to need all the requirements of the original tutorial, except for 3DS_Multi_Decryptor, MEX.py and padxorer.

Now, get rxTools from here, and put rxTools.dat on the root of your SD card, along with slot0x25KeyX.bin, and copy your 3ds games anywhere except inside the "Nintendo 3DS" directory.
Launch rxTools with the web exploit, and press the "Decrypt CTR Titles" option. This can take a while.
Turn off your 3DS, and copy the (now decrypted) .3ds file(s) to your working directory.

Now, follow the appendix on how to convert decrypted .3ds files.

The next step would be throwing a script together to bulk the conversion.
How to convert decrypted .3ds files:
These kinds of files can be aquired in multiple ways, like rxTools, or converted CIAs you want to edit it's romfs. It's useful to be able to convert them.

You're going to need all the requirements of the original tutorial, except for 3DS_Multi_Decryptor, MEX.py and padxorer.

To convert a game, extract the (now decrypted) contents of your game like in the original tutorial (IMPORTANT: don't use the -p flag, this won't work), and follow the rest of it from the step where I show how to extract the exefs.
Common problems:
Problem: When you get this error when trying to build a cxi:
Code:
[EXHEADER ERROR] ExtSaveDataId is unavailable if AccessibleSaveDataIds is specified.
[EXHEADER ERROR] Failed to create ExHeader
Solution: Comment ExtSaveDataId in game.rsf

Like, subscribe, comment, share, shill, give it as a present to your mom and feed it to your dog!
 

mid-kid

GBAtemp spamBOT
OP
Member
Joined
Aug 2, 2012
Messages
879
Trophies
0
Age
25
XP
1,163
Country
I'm on 9.x firmware trying to compile the stuff with DevKitpro and I'm utterly confused

In the OP of the decryptor thread there appears to be a precompiled download for Decrypt9.
This guide doesn't go into compiling things yourself, though it isn't much more than setting up devkitPRO (There's a whole guide on that), adding $DEVKITARM/bin to your $PATH variable, installing make, and running "make".
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
This worked for Animal Crossing, but Bravely Default gives me this error when I try to build the cxi:

Code:
[EXHEADER ERROR] ExtSaveDataId is unavailable if AccessibleSaveDataIds is specified.
[EXHEADER ERROR] Failed to create ExHeader

Just commenting ExtSaveDataId in game.rsf allows the cxi to build. However, I have no idea what I am doing so I thought I'd ask.

Had to rename game.rsf to game.txt to get it uploaded.
 

Attachments

  • game.txt
    6.3 KB · Views: 680

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
Ok, I'll test the cia in the morning. It's 3.4 GB and probably gonna take a few hours for BBM to install it.
Animal Crossing took about at least half an hour, so this is gonna be a long one.
I've got emunand set up on a 16GB sdhc10 card.

Was worried that commenting one line or the other would break game saving if I guess wrong. Installing this two times in a row is not something I want to do.
 

Thomas12345

Well-Known Member
Member
Joined
Dec 1, 2014
Messages
551
Trophies
0
Age
37
XP
291
Country
Canada
Thanks for this guide! I've been dual booting into windows repeatedly just to run makerom, maybe now I can always stay in Linux :) I'll try this guide out later with mario kart 7 and smash bros (don't want to get banned...)
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
Thanks for this guide! I've been dual booting into windows repeatedly just to run makerom, maybe now I can always stay in Linux :) I'll try this guide out later with mario kart 7 and smash bros (don't want to get banned...)


I have built all the tools on Ubuntu 14.10. No problems compiling, except for having to do this:
On linux, for makerom comment line 130 in ncch.c as it causes a segfault

You can also run rom_tool.exe on the command line with wine:
wine rom_tool.exe

The only linux-specific problem I've had is that exfat support is not great. Writing massive files to an exfat card involves some buffering someplace: even when your filemanager/nautilus/whatever says its done copying, the card will not unmount for ages, probably because the OS is still syncing the filesystem. If you have one of those card readers that blink an LED when there is activity, you might be able to find out just how long it takes. Anyway, I don't really understand what's going on and just use OS X or Windows to write exfat cards.

The gateway manual says to format the Red cart microSD exfat, but if I can convert all my games to cia and put them on SD, I hope not to use the red cart much.
 

mid-kid

GBAtemp spamBOT
OP
Member
Joined
Aug 2, 2012
Messages
879
Trophies
0
Age
25
XP
1,163
Country
I have built all the tools on Ubuntu 14.10. No problems compiling, except for having to do this:
On linux, for makerom comment line 130 in ncch.c as it causes a segfault

You can also run rom_tool.exe on the command line with wine:
wine rom_tool.exe

It's not so hard to comment a line, and the creator of said program said on IRC he was going to fix it.
The problem I had with wine is I have only the 32bit version of wine (And I'm too lazy to compile it myself), and 4gb of RAM is not enough when you need 3 times the game size.
Also, native > wine.

The only linux-specific problem I've had is that exfat support is not great. Writing massive files to an exfat card involves some buffering someplace: even when your filemanager/nautilus/whatever says its done copying, the card will not unmount for ages, probably because the OS is still syncing the filesystem. If you have one of those card readers that blink an LED when there is activity, you might be able to find out just how long it takes. Anyway, I don't really understand what's going on and just use OS X or Windows to write exfat cards.

Exactly. You can also run "sync" in the command line to force syncing (It's usually the latest command that is run when shutting down, to make sure everything is written right). There's no way your card could get corrupted, unless you take it out of your pc while syncing.
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
It's not so hard to comment a line, and the creator of said program said on IRC he was going to fix it.
The problem I had with wine is I have only the 32bit version of wine (And I'm too lazy to compile it myself), and 4gb of RAM is not enough when you need 3 times the game size.
Also, native > wine.



Exactly. You can also run "sync" in the command line to force syncing (It's usually the latest command that is run when shutting down, to make sure everything is written right). There's no way your card could get corrupted, unless you take it out of your pc while syncing.

I don't know. I let it sit there for an hour, with the terminal hanging and the umount command going zombie. OS X took about 5 minutes to write a large file to card and no problems unmounting. Not saying Linux is bad, just that it might be better to use the proprietary driver for exfat. But this is all academic. I don't have a single game that is over 4GB. Bravely Default trimmed down to 3.5 and works just fine, so I really have no reason to mess with exfat.

Now hang on a minute. I only have 8GB and romtool (native or wine rom_tool.exe) worked just fine with bravely default which is 3.4GB. I don't think romtool needs much RAM.

Both the 32 and 64- bit windows versions of rom_tool.exe are included in the archive.

You might want to add to the guide how to use cat to join 3d0, 3d1, 3dn files split by Gateway. I don't know about most people, but I forgot all about this, having only used cat as quick text viewer.

Code:
cat game.3d0 game.3d1 > game.3ds
 

mid-kid

GBAtemp spamBOT
OP
Member
Joined
Aug 2, 2012
Messages
879
Trophies
0
Age
25
XP
1,163
Country
I don't know. I let it sit there for an hour, with the terminal hanging and the umount command going zombie. OS X took about 5 minutes to write a large file to card and no problems unmounting. Not saying Linux is bad, just that it might be better to use the proprietary driver for exfat. But this is all academic. I don't have a single game that is over 4GB. Bravely Default trimmed down to 3.5 and works just fine, so I really have no reason to mess with exfat.

I have never used exFAT, because I've never really needed it. I just used ext4 for USB hard drives, because that's the best supported on linux, or NTFS if I wanted it to be portable. On my CFW I'm just using FAT32.
The lag may be because of linux support for exFAT not being in-kernel, but through FUSE instead.
Then again, I barely know the structure of a FAT, so I just don't know.

Now hang on a minute. I only have 8GB and romtool (native or wine rom_tool.exe) worked just fine with bravely default which is 3.4GB. I don't think romtool needs much RAM.

Wait, I was confusing rom_tool with makerom. rom_tool works fine in wine.

You might want to add to the guide how to use cat to join 3d0, 3d1, 3dn files split by Gateway. I don't know about most people, but I forgot all about this, having only used cat as quick text viewer.

Code:
cat game.3d0 game.3d1 > game.3ds

How to create valid .3ds files with a gateway is not really in the scope of this tutorial. :/
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
Well, I've been having fun testing my CIA games. I got interested in making CIAs because I read that Animal Crossing and other games that save inside the "ROM" (It isn't a ROM anymore if you write to it.) will quickly fragment the microsd in the gateway redcart.

For some reason, my Animal Crossing CIA-installed game will not load its own saves. It does not produce an error when you save game, just when you load. Maybe it still thinks it's a cartridge? Was some special step required in the conversion from 3DS to CIA? There were no funny errors when converting the 3ds to cia and I used gateway to extract the 3ds from the cartridge.

It also crashes to the black screen telling you to turn off the power if you say no when the game prompts to enable streetpass. This is in emunand 9.5. I think my emunand is not linked to sysnand: my icons do not turn into little gift boxes when I reboot.

It seems to play and save fine when I loaded loaded the 3DS in the redcart. I tested it under sysnand 4.5 because I had not yet set up emunand.

Bravely Default loads and saves fine, so I'm reasonably sure I'm doing the 3DS to CIA conversion right.
 

cearp

瓜老外
Developer
Joined
May 26, 2008
Messages
8,721
Trophies
2
XP
8,471
Country
Tuvalu
Thanks for this guide! I've been dual booting into windows repeatedly just to run makerom, maybe now I can always stay in Linux :) I'll try this guide out later with mario kart 7 and smash bros (don't want to get banned...)

the source to makerom is public... you could have just compiled it, right?
i'm on mac and i compiled so many 3ds tools, i would hate having to boot up windows just to use some little command line tool!
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
Now, we have to decrypt the contents of the game:
Code:
rename .bin.out .bin *.out

This line is supposed to rename files ending in .bin.out to .bin, but it does not work. You get this error:
Code:
syntax error at (eval 1) line 1, near "."

This will do it:

Code:
rename 's/\.out//' *.bin.out
 

mid-kid

GBAtemp spamBOT
OP
Member
Joined
Aug 2, 2012
Messages
879
Trophies
0
Age
25
XP
1,163
Country
For some reason, my Animal Crossing CIA-installed game will not load its own saves. It does not produce an error when you save game, just when you load. Maybe it still thinks it's a cartridge? Was some special step required in the conversion from 3DS to CIA? There were no funny errors when converting the 3ds to cia and I used gateway to extract the 3ds from the cartridge.

If you import the save from another ROM (say, gateway's .3ds), some games will not work with it, as they contain a checksum somewhere in the ROM, and somewhere in the save file, which is compared. (I got this problem when making my own animal crossing .cia, and tried to import a save made with another .cia)
 

mid-kid

GBAtemp spamBOT
OP
Member
Joined
Aug 2, 2012
Messages
879
Trophies
0
Age
25
XP
1,163
Country
This line is supposed to rename files ending in .bin.out to .bin, but it does not work. You get this error:
Code:
syntax error at (eval 1) line 1, near "."

This will do it:

Code:
rename 's/\.out//' *.bin.out

This depends on your implementation. "rename" from util-linux works only this way (That page is a bit outdated though).
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
If you import the save from another ROM (say, gateway's .3ds), some games will not work with it, as they contain a checksum somewhere in the ROM, and somewhere in the save file, which is compared. (I got this problem when making my own animal crossing .cia, and tried to import a save made with another .cia)

I'm not trying to import anything; that whole business is way too confusing for me.

It is not the Anti Savegame restore problem. It says that the save is corrupted and it askes to reformat it. If you say yes and then save again, you get the same error.

CIA-installed Animal Crossing will not read its own saves and I don't understand why. I did not have to mess with game.rsf when converting it from 3DS and there were no errors building the cxi or cia.
 

romanaOne

Well-Known Member
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
I'm not trying to import anything; that whole business is way too confusing for me.

It is not the Anti Savegame restore problem. It says that the save is corrupted and it askes to reformat it. If you say yes and then save again, you get the same error.

CIA-installed Animal Crossing will not read its own saves and I don't understand why. I did not have to mess with game.rsf when converting it from 3DS and there were no errors building the cxi or cia.

I tried rebuilding the CIA using the Windows batch file. It would not produce a CIA until I tried "alternative 3" in the 3DS to CIA converters menu. I uninstalled the old CIA using BBM. This CIA installs and gave saves are working. Perhaps it is a hint as to what the problem was: it appended (SDK 5) to the CIA file name? I'm not at all familiar with this stuff. Don't even know how many SDKs versions there have been.
 
  • Like
Reactions: mid-kid

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    LeoTCK @ LeoTCK: yes for nearly a month i was officially a wanted fugitive, until yesterday when it ended