ROM Hack NDS FTN and FAT

KazoWAR

Well-Known Member
OP
Member
Joined
Aug 12, 2008
Messages
1,952
Trophies
1
Age
35
Location
Winter Haven
XP
2,131
Country
United States
I am trying to figure out how I can use the FNT and FAT to find a file in a ROM.

I done some searches but all I could really find was documentation on the NDS Header. From that I know how to find the FNT and the FAT but still not sure what I need to be doing with them to get the offset of a file in the filesystem.
 

KiC

Active Member
Newcomer
Joined
Jul 22, 2007
Messages
43
Trophies
0
Website
Visit site
XP
145
Country
Gambia, The
http://nocash.emubase.de/gbatek.htm#dscart...roromfilesystem

It's pretty simple. The FNT contains a list of each folder and then the names. The list has the offset of start of the name data (relative to the start of the FNT), the ID of the first file and the ID of the parent directory, or the number of total directories if it's the first folder in the list.
You then start parsing the names from the position given in the list. Every folder has one long string there, with several substrings. At the start of every substring is one byte. The lower 7 bit give the length of the following name of the entry. If it's a file, then you take the ID from the table to access the FAT table, and then increase the ID for the next file. If bit 7 is set, then it's a folder, and contains a 2 byte folder id in addition to the name. The string is terminated by a length of 0.

The FAT is even simpler. Every file has a start and an end position, the index is simply the file id from the FNT parsing.

File IDs can be 0-0xEFFF, folder IDs go from 0xF000-0xFFFF.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,373
Country
United Kingdom
First I will note crystaltile2 has some fair search abilities but learning how the thing pretty much the entirety of DS hacking relies upon works is also good.

Can I assume you saw
http://nocash.emubase.de/gbatek.htm#dscart...roromfilesystem
and
http://nocash.emubase.de/gbatek.htm#dscartridgeheader
Also http://crackerscrap.com/docs/dsromstructure.html is nice to have but
That is probably enough to get it sorted but gbatek is rarely one for guiding people through things so a few little run throughs.

You have the locations of the FNT and FAT. Between each name entry you have a hex value for the length of the coming name. I would not get too bogged down in directories at first unless you are building a tool to display it- the first named file is pointed at from the start of the FNT although it is relative- I have a couple open and one is A001 or 01A0 and sure enough 01A0 later is the first file name, one with fewer directories is 1000 or 0010 and sure enough 10 hex later is the first name entry.
Grab the names and line up the FAT entries (4 bytes for start location, 4 for end location)- simply read off your file location and length is but a simple subtraction.

Apologies for the not so hot readability but a sample of a quick spreadsheet I knocked together from Chibi Robo
Code:
00BenchA.nsbmdÂÂÂÂ0017ÂÂÂÂA800ÂÂÂÂ0017ÂÂÂÂBB60
00BenchB.nsbmdÂÂÂÂ0017ÂÂÂÂBC00ÂÂÂÂ0017ÂÂÂÂD178
00ClockTowerA.nsbmdÂÂÂÂ0017ÂÂÂÂD200ÂÂÂÂ0017ÂÂÂÂE0E0
00EnticeKuroA.nsbmdÂÂÂÂ0017ÂÂÂÂE200ÂÂÂÂ0017ÂÂÂÂF15C
00FUmbrellaA.nsbmdÂÂÂÂ0017ÂÂÂÂF200ÂÂÂÂ0017ÂÂÂÂF960
00FUmbrellaB.nsbmdÂÂÂÂ0017ÂÂÂÂFA00ÂÂÂÂ0018ÂÂÂÂ0160
00FUmbrellaC.nsbmdÂÂÂÂ0018ÂÂÂÂ0200ÂÂÂÂ0018ÂÂÂÂ0960
00FUmbrellaD.nsbmdÂÂÂÂ0018ÂÂÂÂ0A00ÂÂÂÂ0018ÂÂÂÂ11CC
00FUmbrellaE.nsbmdÂÂÂÂ0018ÂÂÂÂ1200ÂÂÂÂ0018ÂÂÂÂ19CC
00FUmbrellaF.nsbmdÂÂÂÂ0018ÂÂÂÂ1A00ÂÂÂÂ0018ÂÂÂÂ21B8
00LampA.nsbmdÂÂÂÂ0018ÂÂÂÂ2200ÂÂÂÂ0018ÂÂÂÂ3130
00LampB.nsbmdÂÂÂÂ0018ÂÂÂÂ3200ÂÂÂÂ0018ÂÂÂÂ430C
00ManholeA.nsbmdÂÂÂÂ0018ÂÂÂÂ4400ÂÂÂÂ0018ÂÂÂÂ4CC4
00ScareKuroA.nsbmdÂÂÂÂ0018ÂÂÂÂ4E00ÂÂÂÂ0018ÂÂÂÂ5CB0
00StatueBisonA.nsbmdÂÂÂÂ0018ÂÂÂÂ5E00ÂÂÂÂ0018ÂÂÂÂ7254
00StatueFlaridaA.nsbmdÂÂÂÂ0018ÂÂÂÂ7400ÂÂÂÂ0018ÂÂÂÂ8854
00StatueLibertyA.nsbmdÂÂÂÂ0018ÂÂÂÂ8A00ÂÂÂÂ0018ÂÂÂÂ9E54
00StatueMaccinaA.nsbmdÂÂÂÂ0018ÂÂÂÂA000ÂÂÂÂ0018ÂÂÂÂB454
00StatueMonkeyA.nsbmdÂÂÂÂ0018ÂÂÂÂB600ÂÂÂÂ0018ÂÂÂÂCA54
00StatuePenGuinA.nsbmdÂÂÂÂ0018ÂÂÂÂCC00ÂÂÂÂ0018ÂÂÂÂE054
00StatuePopularA.nsbmdÂÂÂÂ0018ÂÂÂÂE200ÂÂÂÂ0018ÂÂÂÂF654
00StopperA.nsbmdÂÂÂÂ0018ÂÂÂÂF800ÂÂÂÂ0019ÂÂÂÂ0340
00StopperB.nsbmdÂÂÂÂ0019ÂÂÂÂ0400ÂÂÂÂ0019ÂÂÂÂ0930
00TrashBoxA.nsbmdÂÂÂÂ0019ÂÂÂÂ0A00ÂÂÂÂ0019ÂÂÂÂ1B90

Granted this game is relatively simple and has most files in the initial directory and no subdirectories in directories. For one more complex you will have to start parsing directories although if you want you can ignore the subdirectory stuff as all files have numbers in order with no attention paid to directories.

Post back if you want something elaborated upon.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    AncientBoi @ AncientBoi: How Roms Try Helping? +1