Homebrew [RELEASE] NDSFactory - unpack and repack NDS roms

  • Thread starter Thread starter Luca91
  • Start date Start date
  • Views Views 17,186
  • Replies Replies 16
  • Likes Likes 6

Luca91

Well-Known Member
Newcomer
Joined
Sep 13, 2019
Messages
78
Reaction score
159
Trophies
1
Age
35
XP
1,018
Country
Italy
Hello,
I was interested in getting code execution before the game's own NitroMain(), but my final ARM9 binary was bigger than the original one, and eventually was overlapping with the ARM7 binary.
Instead to try all the funcky ways to compress my code (that anyway is not a viable solution in most of the cases since the padding between ARM9 and ARM7 binaries is extremely small), I decided to write a tool to help me (and maybe other roms hackers/reverse engineers) to unpack and repack nds roms.

So, this is NDSFactory. With this tool you can unpack every sections of nds roms (but be aware that roms with OVERLAYS aren't supported right now!!!) and then repack them back (after editing them if you want).
Using this tool, you can set custom address and size of your edited sections and then it will rebuild a new rom.
Be aware that some general rom layout knowlege is required before using it. For example if the fat_data.bin (the FAT files) address is different, you have to patch your fat.bin using the 3rd tab.

I'd like to post a pic, but sadly I haven't the right post counter :/

If you want to contribute, you are very welcome, there is still a lot of things to do (checks, fat contents decoding, fat rebuilding, overlay support, a nice icon, and ofc bugs to fix!)


GitHub repo: https://github.com/Luca1991/NDSFactory


Thank you, and I'll be watching this thread for any suggestions/questions :)
 
Last edited by Luca91,
This has so many posibilities!!!

On the wrong hands though... O_o

Can the NDS file be checked against an "official hash" to know they have been tampered with?

Thank you for this great tool!!!
 
This has so many posibilities!!!

On the wrong hands though... :wtf:

Can the NDS file be checked against an "official hash" to know they have been tampered with?

Thank you for this great tool!!!

I honestly don't think that this is useful to malware writers, if this is what you are thinking by "wrong hands". For at least three reasons:
1) NDS format is greatly documented (since 2005 IIRC)
2) A malware writer can easily write his/her own tools to unpack and repack nds roms (and also to apply patches to the fat)
3) I haven't done any research, but I think that there might be other tools like this one already released 14 years ago (I decided to write my own for fun)

Of course any nds roms can be checked against its official hash (the hash of a clean/untouched dump), you are welcome to write a function to calc and display the md5 of the final patched rom, and send me a PR on github. I'll be more than happy to merge your work :)


tl;dr: i don't think that malware writers have any advantages using this tool. Also, we have perfectly working emus nowadays: test your software using one of them, before running it on a real console.
 
Last edited by Luca91,
Hi all,
from time to time I update this project. Here is a list of features added in the last couple of months:
- New UI: new scrollable UI for both packer and unpacker view. You can resize the window now and use this app on smaller screens.
- maOS version released
- Tested and working on ARM64 CPU (Raspberry Pi with QTAnywhere)
- Build system changed: switched to CMake
- Various workflow updates: added a CI to autobuild, added build version on each release etc.
- Improved stability (TM)

Planned features:
- Fat files decoding
- Fat_data creation from a set of files
- Support roms with overlay
 
Hi all,
from time to time I update this project. Here is a list of features added in the last couple of months:
- New UI: new scrollable UI for both packer and unpacker view. You can resize the window now and use this app on smaller screens.
- maOS version released
- Tested and working on ARM64 CPU (Raspberry Pi with QTAnywhere)
- Build system changed: switched to CMake
- Various workflow updates: added a CI to autobuild, added build version on each release etc.
- Improved stability (TM)

Planned features:
- Fat files decoding
- Fat_data creation from a set of files
- Support roms with overlay
Nice work!
 
  • Like
Reactions: banjo2
In this **HOT** summer Sunday evening...

NDSFactory v1.1 is available for download!

While this may seem like a minor release (in a way it is), it includes many quality of life improvements and many bug fixes. But more importantly, it paves the way for the implementation of all the missing features (support for ROMs with overlay and FAT rebuilding).

Further quality of life improvements are planned in the next release.
 
Works pretty well, and honestly I find it more convinent than DeSmuME's Nitro FS explorer.

Question - What exactly doesn't work right now with overlay ROMs? I got an error when using "extract everything", but upon checking the folder I extracted to, many of the files were there, and the FAT decode also worked fine on an overlay ROM.
 
  • Like
Reactions: Luca91
Works pretty well, and honestly I find it more convinent than DeSmuME's Nitro FS explorer.
Thanks a lot for your feedback!

Question - What exactly doesn't work right now with overlay ROMs? I got an error when using "extract everything", but upon checking the folder I extracted to, many of the files were there, and the FAT decode also worked fine on an overlay ROM.
It will not extract the overlay(s). I’m working adding the logic to parse the overlay(s) data and extract the binary(ies). Other than that, rebuilding FAT is currently missing.
 
Well, it seems to have spit out a9ovr.bin with the exact contents and size specified by the header. Unless there's more to it than that, seems to be working

Hey, sorry for the confusion, you are right that overlays extraction code is already in place, but files contained in overlays aren’t extracted yet.
 
Last edited by Luca91,
Hey, sorry for the confusion, you are right that overlays extraction code is already in place, but files contained in overlays aren’t extracted yet.
I see. The ROM I tested it on only has a 224 byte overlay. And looking at the data, I'm not sure there's any files contained in it

Regardless, definitely a project I'll keep an eye on
 
NDSFactory v1.2 is available for download!

This release FINALLY adds support to ROMs with overlays!! (this feature has been on my TODO list for at least 5 years!). Even though it's experimental, it should work!

Please report any bugs so I can fix them. Thanks.
 
NDSFactory v1.3 is available for download!

Finally, in this version the FAT rebuild feature is now available: you can create a new FAT (fat.bin and fat_data.bin) from a previously decoded FAT.

Now, NDSFactory has all the features I had initially planned to add. Obviosuly, it can still be improved (for example regarding fat patching in ROMs with overlay).

NOTE: The Linux version will be coming later tonight (hopefully), as I have some issues with the latest GCC release in GitHub CI.
Post automatically merged:

NDSFactory v1.3.1 is available for download!

Linux build is now fixed :)
 
Last edited by Luca91,
Any plans for a command line version?

The project is divided into two parts:
  • UI directory: this is the GUI, written in Qt6
  • ndsfactory directory: this directory contains ndsfactory.cpp with all the program functions, in pure C++.
Now, you can easily write a command-line version by simply parsing user input and calling the relevant functions from ndsfactory.cpp.

I'm not interested in a command line version at the moment, but if anyone wants to do so, I'd definitely accept the PR.

This is also a good task for anyone learning to code.
 
Made a command line version.

It's VERY WIP, but everything should work.

Source code: https://github.com/master801/NDSFactory
Warning: (Probably) unsafe spaghetti code and only compiles on Windows with Visual Studio (2022).

Uses https://github.com/p-ranav/argparse as a dependency (Boost's program_options was incredibly restrictive.) The CMake script will automatically download and link it to the project.
 

Attachments

Site & Scene News

Popular threads in this forum