Esempio n. 1
0
File: NDS.cs Progetto: ww400/dspatch
        public void FromFileSystem(SFSDirectory Root)
        {
            int did = 0;
            int fid = MainOvt.Length + SubOvt.Length;

            Root.UpdateIDs(ref did, ref fid);
            //FATB.numFiles = (ushort)Root.TotalNrSubFiles;
            //List<byte> Data = new List<byte>();
            uint nrfiles = Root.TotalNrSubFiles;

            FileAllocationEntry[] overlays = new FileAllocationEntry[MainOvt.Length + SubOvt.Length];
            Array.Copy(Fat, overlays, MainOvt.Length + SubOvt.Length);
            Fat = new FileAllocationEntry[(MainOvt.Length + SubOvt.Length) + nrfiles];
            Array.Copy(overlays, Fat, MainOvt.Length + SubOvt.Length);
            byte[][] overlaydata = new byte[MainOvt.Length + SubOvt.Length][];
            Array.Copy(FileData, overlaydata, MainOvt.Length + SubOvt.Length);
            FileData = new byte[(MainOvt.Length + SubOvt.Length) + nrfiles][];
            Array.Copy(overlaydata, FileData, MainOvt.Length + SubOvt.Length);
            //FATB.allocationTable.Clear();
            for (ushort i = (ushort)(MainOvt.Length + SubOvt.Length); i < nrfiles + MainOvt.Length + SubOvt.Length; i++)
            {
                var f = Root.GetFileByID(i);
                Fat[i]      = new FileAllocationEntry(0, 0);
                FileData[i] = f.Data;
            }
            Fnt.DirectoryTable.Clear();
            NitroFSUtil.GenerateDirectoryTable(Fnt.DirectoryTable, Root);
            uint   offset2 = Fnt.DirectoryTable[0].dirEntryStart;
            ushort fileId  = (ushort)(MainOvt.Length + SubOvt.Length);           //0;

            Fnt.EntryNameTable.Clear();
            NitroFSUtil.GenerateEntryNameTable(Fnt.DirectoryTable, Fnt.EntryNameTable, Root, ref offset2, ref fileId);
        }
Esempio n. 2
0
File: NDS.cs Progetto: ww400/dspatch
        public NDS(byte[] data)
        {
            EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(data), Endianness.LittleEndian);

            Header = new RomHeader(er);

            er.BaseStream.Position = Header.MainRomOffset;
            MainRom = er.ReadBytes((int)Header.MainSize);
            if (er.ReadUInt32() == 0xDEC00621)            //Nitro Footer!
            {
                er.BaseStream.Position -= 4;
                StaticFooter            = new NitroFooter(er);
            }

            er.BaseStream.Position = Header.SubRomOffset;
            SubRom = er.ReadBytes((int)Header.SubSize);

            er.BaseStream.Position = Header.FntOffset;
            Fnt = new RomFNT(er);

            er.BaseStream.Position = Header.MainOvtOffset;
            MainOvt = new RomOVT[Header.MainOvtSize / 32];
            for (int i = 0; i < Header.MainOvtSize / 32; i++)
            {
                MainOvt[i] = new RomOVT(er);
            }

            er.BaseStream.Position = Header.SubOvtOffset;
            SubOvt = new RomOVT[Header.SubOvtSize / 32];
            for (int i = 0; i < Header.SubOvtSize / 32; i++)
            {
                SubOvt[i] = new RomOVT(er);
            }

            er.BaseStream.Position = Header.FatOffset;
            Fat = new FileAllocationEntry[Header.FatSize / 8];
            for (int i = 0; i < Header.FatSize / 8; i++)
            {
                Fat[i] = new FileAllocationEntry(er);
            }

            if (Header.BannerOffset != 0)
            {
                er.BaseStream.Position = Header.BannerOffset;
                Banner = new RomBanner(er);
            }

            FileData = new byte[Header.FatSize / 8][];
            for (int i = 0; i < Header.FatSize / 8; i++)
            {
                er.BaseStream.Position = Fat[i].fileTop;
                FileData[i]            = er.ReadBytes((int)Fat[i].fileSize);
            }
            //RSA Signature
            if (Header.RomSize + 0x88 <= er.BaseStream.Length)
            {
                er.BaseStream.Position = Header.RomSize;
                byte[] RSASig = er.ReadBytes(0x88);
                for (int i = 0; i < RSASig.Length; i++)
                {
                    //It could be padding, so check if there is something other than 0xFF or 0x00
                    if (RSASig[i] != 0xFF || RSASig[i] != 0x00)
                    {
                        RSASignature = RSASig;
                        break;
                    }
                }
            }
            er.Close();
        }