NDS FTN and FAT

Discussion in 'NDS - ROM Hacking and Translations' started by KazoWAR, Aug 30, 2011.

Aug 30, 2011

NDS FTN and FAT by KazoWAR at 9:19 AM (888 Views / 0 Likes) 4 replies

  1. KazoWAR
    OP

    Member KazoWAR GBAtemp Advanced Maniac

    Joined:
    Aug 12, 2008
    Messages:
    1,749
    Location:
    Winter Haven
    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.
     
  2. KiC

    Newcomer KiC Member

    Joined:
    Jul 22, 2007
    Messages:
    43
    Country:
    Germany
    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.
     
  3. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,711
    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.
     
  4. pleonex

    Member pleonex GBAtemp Regular

    Joined:
    Jan 16, 2009
    Messages:
    197
    Location:
    South of Spain
    Country:
    Spain
  5. KazoWAR
    OP

    Member KazoWAR GBAtemp Advanced Maniac

    Joined:
    Aug 12, 2008
    Messages:
    1,749
    Location:
    Winter Haven
    Country:
    United States
    Thanks guys, this should help me out.
     

Share This Page