示例#1
0
        public static sFolder MakeFolderStructure(List <MainFNT> tables, int idFolder, string nameFolder)
        {
            sFolder currFolder = new sFolder();

            currFolder.name  = nameFolder;
            currFolder.id    = (ushort)idFolder;
            currFolder.files = tables[idFolder & 0xFFF].subTable.files;

            if (tables[idFolder & 0xFFF].subTable.folders is List <sFolder> )
            {
                currFolder.folders = new List <sFolder>();

                foreach (sFolder subFolder in tables[idFolder & 0xFFF].subTable.folders)
                {
                    currFolder.folders.Add(MakeFolderStructure(tables, subFolder.id, subFolder.name));
                }
            }

            return(currFolder);
        }
示例#2
0
文件: NDS.cs 项目: benladen/Kuriimu
        public void FetchFiles(Stream input, sFolder fnt, string path="")
        {
            if (fnt.files is List<sFile>)
            {
                for (int i=0;i< fnt.files.Count;i++)
                {
                    Files.Add(new NDSFileInfo
                    {
                        State = ArchiveFileState.Archived,
                        FileName = path + fnt.files[i].name,
                        FileData = new SubStream(input, fnt.files[i].offset, fnt.files[i].size),
                        entry = fnt.files[i]
                    });
                }
            }

            if (fnt.folders is List<sFolder>)
            {
                for (int i=0;i< fnt.folders.Count;i++)
                {
                    FetchFiles(input, fnt.folders[i], path + "/" + fnt.folders[i].name);
                }
            }
        }
示例#3
0
文件: NDS.cs 项目: benladen/Kuriimu
        public NDS(Stream input)
        {
            _stream = input;
            using (BinaryReaderX br = new BinaryReaderX(input, true))
            {
                //Header
                header = new RomHeader(br.BaseStream);

                //Banner
                banner = new Banner(br.BaseStream, header.bannerOffset);

                //FAT
                fat = NDSSupport.ReadFAT(br.BaseStream, header.FAToffset, header.FATsize);

                //FNT
                fnt = NDSSupport.ReadFNT(br.BaseStream, header.fileNameTableOffset, header.fileNameTableSize, fat);

                //System files
                fnt.folders.Add(NDSSupport.AddSystemFiles(br.BaseStream, fat, fat.Length, fnt.id + 0xF000, header));

                //FileData
                FetchFiles(br.BaseStream, fnt);
            }
        }
示例#4
0
        public static sFolder ReadFNT(Stream input, uint fntOffset, uint fntSize, sFAT[] fat)
        {
            using (var br = new BinaryReaderX(input, true))
            {
                sFolder root = new sFolder();
                root.files = new List <sFile>();
                List <MainFNT> mains = new List <MainFNT>();

                br.BaseStream.Position = fntOffset;

                br.BaseStream.Position += 6;
                ushort number_directories = br.ReadUInt16();  // Get the total number of directories (mainTables)
                br.BaseStream.Position = fntOffset;

                for (int i = 0; i < number_directories; i++)
                {
                    MainFNT main = new MainFNT();
                    main.offset         = br.ReadUInt32();
                    main.idFirstFile    = br.ReadUInt16();
                    main.idParentFolder = br.ReadUInt16();

                    if (i != 0)
                    {
                        if (br.BaseStream.Position > fntOffset + mains[0].offset)
                        {                                      //  Error, in some cases the number of directories is wrong
                            number_directories--;              // Found in FF Four Heroes of Light, Tetris Party deluxe
                            i--;
                            continue;
                        }
                    }

                    long currOffset = br.BaseStream.Position;
                    br.BaseStream.Position = fntOffset + main.offset;

                    // SubTable
                    byte   id     = br.ReadByte();
                    ushort idFile = main.idFirstFile;

                    while (id != 0x0)   // identifies subTable end
                    {
                        if (id < 0x80)  // File
                        {
                            sFile currFile = new sFile();

                            if (!(main.subTable.files is List <sFile>))
                            {
                                main.subTable.files = new List <sFile>();
                            }

                            int lengthName = id;
                            currFile.name = new String(Encoding.GetEncoding("SJIS").GetChars(br.ReadBytes(lengthName)));
                            currFile.id   = idFile; idFile++;

                            // FAT part
                            currFile.offset = fat[currFile.id].offset;
                            currFile.size   = fat[currFile.id].size;

                            // Add to root
                            root.files.Add(currFile);

                            main.subTable.files.Add(currFile);
                        }
                        if (id > 0x80)  //Directory
                        {
                            sFolder currFolder = new sFolder();

                            if (!(main.subTable.folders is List <sFolder>))
                            {
                                main.subTable.folders = new List <sFolder>();
                            }

                            int lengthName = id - 0x80;
                            currFolder.name = new String(Encoding.GetEncoding("SJIS").GetChars(br.ReadBytes(lengthName))) + "/";
                            currFolder.id   = br.ReadUInt16();

                            main.subTable.folders.Add(currFolder);
                        }

                        id = br.ReadByte();
                    }

                    mains.Add(main);
                    br.BaseStream.Position = currOffset;
                }

                root    = MakeFolderStructure(mains, 0, "root");
                root.id = number_directories;

                return(root);
            }
        }
示例#5
0
        public static sFolder AddSystemFiles(Stream input, sFAT[] fatTable, int lastFileID, int lastFolderID, RomHeader header)
        {
            sFolder system = new sFolder();

            system.name = "fw_sys/";
            system.id   = (ushort)lastFolderID;
            lastFolderID++;
            system.files = new List <sFile>();
            system.files.AddRange(ReadBasicOverlays(input, header.ARM9overlayOffset, header.ARM9overlaySize, true, fatTable));
            system.files.AddRange(ReadBasicOverlays(input, header.ARM7overlayOffset, header.ARM7overlaySize, false, fatTable));

            sFile fnt = new sFile();

            fnt.name   = "fileNameTable.bin";
            fnt.offset = header.fileNameTableOffset;
            fnt.size   = header.fileNameTableSize;
            fnt.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(fnt);

            sFile fat = new sFile();

            fat.name   = "fileAccessTable.bin";
            fat.offset = header.FAToffset;
            fat.size   = header.FATsize;
            fat.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(fat);

            sFile banner = new sFile();

            banner.name   = "banner.bin";
            banner.offset = header.bannerOffset;
            banner.size   = 0x840;
            banner.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(banner);

            sFile arm9 = new sFile();

            arm9.name   = "arm9.bin";
            arm9.offset = header.ARM9romOffset;
            arm9.size   = header.ARM9size;
            arm9.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(arm9);

            sFile arm7 = new sFile();

            arm7.name   = "arm7.bin";
            arm7.offset = header.ARM7romOffset;
            arm7.size   = header.ARM7size;
            arm7.id     = (ushort)lastFolderID;
            lastFolderID++;
            system.files.Add(arm7);

            if (header.ARM9overlaySize != 0)
            {
                sFile y9 = new sFile();
                y9.name   = "y9.bin";
                y9.offset = header.ARM9overlayOffset;
                y9.size   = header.ARM9overlaySize;
                y9.id     = (ushort)lastFolderID;
                lastFolderID++;
                system.files.Add(y9);
            }

            if (header.ARM7overlaySize != 0)
            {
                sFile y7 = new sFile();
                y7.name   = "y7.bin";
                y7.offset = header.ARM7overlayOffset;
                y7.size   = header.ARM7overlaySize;
                y7.id     = (ushort)lastFolderID;
                lastFolderID++;
                system.files.Add(y7);
            }

            return(system);
        }