Homebrew [WIP] twlnf, DSi NAND File ... thing ... testers with hardmod wanted

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
source:
download:

twlnf mounts a NAND image from SD card and do file operations on that, if you don't have one, it will prompt to backup NAND to an image, you can write/test scripts and then test the resulting image on no$gba.

To easier the testing process, the NAND image twlnf creates contains no$gba footer, so it works directly in no$gba, BUT, it becomes incompatible with the fwtool restore fork, do not use that to restore NAND images created by twlnf.

Abandoned, Do not use.

Scripted operation
It's not a "file manager" in conventional meaning, you can NOT use menus and buttons to navigate through NAND file system, but instead, you run scripts(or more like batch files), I wrote it this way partially because of I suck at UI, and also scripted operations could prevent lots of human errors.

Code:
# example script to downgrade to 1.4.0U
# check for these directories so region match
dir_exist title/00030017/484e4145/
dir_exist title/00030015/484e4245/
# BEWARE it does NOT have any sanity check, if you write `rm sys/*`, it will do so
rm title/0003000f/484e4841/content/*
5b0a9602d12000c9a1fac5e8a3c75c172a62f793 *title/0003000f/484e4841/content/title.tmd
da5123e336d2ca147f03ffc2d1b10e27b7bf822e *title/0003000f/484e4841/content/00000001.app
rm title/00030017/484e4145/content/*
6c52561a047c8036f31f9d468570d50d36f7d988 *title/00030017/484e4145/content/title.tmd
1339bd7457484839f1d71f27de2f8da8098834b4 *title/00030017/484e4145/content/00000002.app
rm title/00030015/484e4245/content/*
759ab482b244d2abae4869a0263c005223bad3a0 *title/00030015/484e4245/content/title.tmd
431925e39e635df3d38e2c34152cb391ad8e4705 *title/00030015/484e4245/content/00000002.app
file path on SD should be relative to twlnf.nds itself, not relative to the script.

tmd install
basically you prepared the dsiware files like this:
Code:
some dsiware/
            ├content/
            │       ├title.tmd
            │       └0000000?.app
            └data/
                 ├public.sav (if any)
                 └private.sav (if any)
and select the tmd file in twlnf.

FAQ
  • Q: "most likely Console ID is wrong"
    A: currently it can't acquire Console ID on site, you need to provide it in a "console_id.txt" hex string file for now.

  • Q: it looks like it's frozen, should I panic now?
    A: copy big app files can cost a bit of time, just wait until it says it's copied and verified.
    update: since 0.3.1, it will show an I/O activity indicator on the lower right, you'll know it's busy.

  • Q: dsiware shows up fine, but save error
    A: you probably provided wrong public.sav and/or private.sav file(s), or didn't provide any.
    • you can use this tool to check if the sav files are of the correct size.
    • if you have a 3DS, install the dsiware on 3DS, copy the .sav files over.
    • there's a clean 16K sav file here you can use.
    • as a last resort, you can provide zero filled file with the correct size, after install, copy it to SD and back in data management, it will fix the save for you.
    • thanks @Lyrin for testing on this matter.
More about scripts
  • first, dry run mode:
    • runs check commands, if anyone fails, it will fail the dry run
      • currently only file_exist and dir_exist
    • sha1sum lines:
      • check if path is valid, example: "/sys/dev.kp/test.txt" is invalid, since "/sys/dev.kp" exists and it's a file, you can't create "/sys/dev.kp/"
      • checks source files against sha1
    • report missing/wrong files and irregular lines, if any, the dry run is considered fail
  • if dry run succeed, and size of all files < NAND free space - 5MB, it will prompt if you'd like to execute the script
  • execution:
    • check commands are ignored this time
    • execute regular commands, currently only rm
      • rm
        if the path doesn't end with /*, it removes it, whether it's a file or directory, so more like rm + rmdir. non-empty directories can't be removed.
        if the path ends with /*, it treat the path as a directory and remove all files in it, sub directories are not touched or descended into.
      • regular commands never fail and never stops the execution
    • sha1sum lines: copy source files and check target file against sha1
      • TODO: currently target directory must exist parent directories will be created if necessary.
  • designed to check as much as possible before the 1st write attempt.
  • there is no branching or any kind of flow control commands.
More about tmd install
  • fake ticket is forged on site
  • tmd signature is verified, and trimmed(only read the first 0x208 bytes).
  • app is verified against sha1 in tmd
    • so tmd and app version must match
    • it's cleaner, everything matches
    • and simpler, compared to verify app using hash tree
    • but might be unwanted behavior, since DSi actually allow unmatched tmd/app version, and I've seen people install old version of the sudoku app alongside a new tmd.
    • but again, is that old tmd really not available? or just too lazy to find the corresponding version? if later, I'd suggest you get that correct tmd instead, for example, the tmd for the old sudoku(U) is here: http://nus.cdn.t.shop.nintendowifi.net/ccs/download/000300044b344445/tmd.1
    • you can verify if the tmd and app matches on PC using this tool.
    • well, if some tmd really not available, let me know.
  • region is verified
  • whatever in [tmd directory]/../data/ is copied over
    • TODO: some checks on that?
  • this should be simpler and safer than the manual way

one more thing
There is an option in the start button menu to generate a sha1 file for all files on NAND, this could take some time and might be useful for http://gbatemp.net/threads/dsi-directory-trees-from-original-firmware-dumps-preservation.481532/

PR
PRs of new scripts are welcomed.

Thanks(no particular order)
As always, Thanks @nocash123 for GBATEK and no$gba and @realWinterMute for devKitPro and libnds and fwTool which this thing forked from.
And special thanks to a friend for giving me his DSi XL U to test.
Also special thanks to @WiiHomebrew+Snes.
Thanks @dsigamerxl for the new icon :)
@Ryccardo for his dsiware injection tutorial which the tmd install function based on.
 
Last edited by JimmyZ,

ADrowsyUser

Member
Newcomer
Joined
Sep 8, 2017
Messages
7
Trophies
0
XP
58
Country
United States
I have a dsi that is hardmodded. I can test for you. I just don't have L+R working on this one however.

Update: One of the wires came off when trying to create a backup, gonna have to wait a bit.

0000FE00 on boot, rip (maybe). Gonna search for the problem. Hardmod worked fine a month ago... The issue is not caused by the software, I have not even used it yet.
 
Last edited by ADrowsyUser,
  • Like
Reactions: JimmyZ

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
I have a dsi that is hardmodded. I can test for you. I just don't have L+R working on this one however.

Update: One of the wires came off when trying to create a backup, gonna have to wait a bit.

0000FE00 on boot, rip (maybe). Gonna search for the problem. Hardmod worked fine a month ago... The issue is not caused by the software, I have not even used it yet.
I'm sorry for your loss, the wire might ripped off some copper lines(I don't know what's the proper term) on the PCB when it came off.
 

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
dsiware install works now.

update: OP updated.

update again: I bite the bullet and installed two dsiware in direct NAND mount mode, it works. beware I'm not recommending this, but if you're already using fwtool(the rw fork) to restore modified NAND without hardmod, this thing should be less risky.
 
Last edited by JimmyZ,

Deleted member 424658

Annoying Weaboo Girl
Member
Joined
Jun 4, 2017
Messages
499
Trophies
0
Age
24
Website
www.reddit.com
XP
677
Country
United States
dsiware install works now.

update: OP updated.

update again: I bite the bullet and installed two dsiware in direct NAND mount mode, it works. beware I'm not recommending this, but if you're already using fwtool(the rw fork) to restore modified NAND without hardmod, this thing should be less risky.
I want to try installing a DSiWare using this, but it seems that the way to build it with direct nand access is changed. Mind helping out?
 

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
I want to try installing a DSiWare using this, but it seems that the way to build it with direct nand access is changed. Mind helping out?
There is no special build requirement but the way to enter direct mount mode is hidden. Press X instead of A when it prompt to mount the image.

Beware there is still a chance to brick and no way to recover except hardmod. Always test your payload on an image and no$gba beforehand.

And copy big app files takes a little time, the screen seems to be frozen, but it's not, don't panic and press the power button, just wait.
 
Last edited by JimmyZ,

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
I also wrote a pc utility to verify app against tmd, like this:
Code:
$ ./ticket0 tmd title.tmd
Title ID: 000300044b5a4c45(KZLE)
Issuer: Root-CA00000001-CP00000007
public save: 16384
private save: 0
Number of content: 1
=== Content ID: 00000000 ===
index: 0
type: 1
size: 15739904
size match
sha1 verified
source code is part of twlbf at https://github.com/Jimmy-Z/TWLbf/blob/master/ticket0.c
 

Attachments

  • ticket0.7z
    12.8 KB · Views: 336
Last edited by JimmyZ,

Deleted member 424658

Annoying Weaboo Girl
Member
Joined
Jun 4, 2017
Messages
499
Trophies
0
Age
24
Website
www.reddit.com
XP
677
Country
United States
For the ticket operation, is it using a system ticket?
I'm asking because I've injected like 3 games manually and those can copy to the SD fine while the two games I installed recently give an error saying "Could not copy. Please check SD Card." (in data management)
 

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
For the ticket operation, is it using a system ticket?
I'm asking because I've injected like 3 games manually and those can copy to the SD fine while the two games I installed recently give an error saying "Could not copy. Please check SD Card." (in data management)
It use the first one found in the 00030004 directory.

Related code is in tmd.c

00030004 tickets might not be all equal, like the 3ds migration tool can't be exported to SD.

Update: tried copy to SD myself, it works, so it should be the source ticket, anyway this should not be a big issue?
 
Last edited by JimmyZ,

Deleted member 424658

Annoying Weaboo Girl
Member
Joined
Jun 4, 2017
Messages
499
Trophies
0
Age
24
Website
www.reddit.com
XP
677
Country
United States
It use the first one found in the 00030004 directory.

Related code is in tmd.c

00030004 tickets might not be all equal, like the 3ds migration tool can't be exported to SD.

Update: tried copy to SD myself, it works, so it should be the source ticket, anyway this should not be a big issue?
The top ticket listed in a nand backup from about a month ago (haven't done nand stuff since then) is one that I faked myself, maybe that's got something to do with it?
Also moving games to the SD and back seemed to fix a save marked as corrupted for me, so I was attempting that to fix the save again.
 

JimmyZ

Sarcastic Troll
OP
Member
Joined
Apr 2, 2009
Messages
681
Trophies
0
XP
762
Country
Zimbabwe
The top ticket listed in a nand backup from about a month ago (haven't done nand stuff since then) is one that I faked myself, maybe that's got something to do with it?
Also moving games to the SD and back seemed to fix a save marked as corrupted for me, so I was attempting that to fix the save again.
"first" means the first item readdir() returns, it's not alphabetically sorted, so, might not be the one you think it is. you can generate a file list in the start menu, it should be in that order.

What's the "corrupted save" case? is it caused by this program? if true, this could be a serious problem, and I definitely need to look into that. or is the .sav corrupted already? then why do you inject that.... If you accidentally copied a bad .sav with tmd install, you could fix it by copy a correct .sav file over using the script feature.

BTW I'm also curious about how to generate a clean .sav file, getting one of them is easy, just install the dsiware on 3ds and copy that out, they're just blank FAT12 file systems so universal across different games, but, they have different sizes... as for 3rd party tools, mkfs.fat from dosfstools refuse to create FAT12 as small as 16KB.

Well the proper way should be just RTFM of FAT12, but maybe someone already had experience on this?
 
Last edited by JimmyZ,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: https://youtube.com/shorts/WOppJ92RgGU?si=KE79L6A_3jESsGQM