Пример #1
0
        public override void load()
        {
            headerFile = new HeaderFile(this, mainDir);

            fntFile = new PhysicalFile(this, mainDir, -1, "fnt.bin", headerFile, 0x40, 0x44, true);
            fatFile = new PhysicalFile(this, mainDir, -2, "fat.bin", headerFile, 0x48, 0x4C, true);

            base.load();

            arm9ovFile = new PhysicalFile(this, mainDir, -3, "arm9ovt.bin", headerFile, 0x50, 0x54, true);
            arm7ovFile = new PhysicalFile(this, mainDir, -4, "arm7ovt.bin", headerFile, 0x58, 0x5C, true);
            //            arm9binFile = new Arm9BinFile(this, mainDir, headerFile);
            //            File arm9binFile2 = new PhysicalFile(this, mainDir, true, -2, "arm9.bin", headerFile, 0x20, 0xC, true);
            arm9binFile                 = new PhysicalFile(this, mainDir, -5, "arm9.bin", headerFile, 0x20, 0x2C, true);
            arm9binFile.alignment       = 0x1000;
            arm9binFile.canChangeOffset = false;
            arm7binFile                 = new PhysicalFile(this, mainDir, -6, "arm7.bin", headerFile, 0x30, 0x3C, true);
            arm7binFile.alignment       = 0x200; //Not sure what should be used here...
            bannerFile           = new BannerFile(this, mainDir, headerFile);
            bannerFile.alignment = 0x200;        //Not sure what should be used here...

            uint rsaOffs = headerFile.getUintAt(0x1000);

            if (rsaOffs == 0)
            {
                rsaOffs = headerFile.getUintAt(0x80);
                headerFile.setUintAt(0x1000, rsaOffs);
            }

            rsaSigFile = new PhysicalFile(this, mainDir, -7, "rsasig.bin", (int)rsaOffs, 136);
            rsaSigFile.canChangeOffset = false;

            addFile(headerFile);
            mainDir.childrenFiles.Add(headerFile);
            addFile(arm9ovFile);
            mainDir.childrenFiles.Add(arm9ovFile);
            addFile(arm7ovFile);
            mainDir.childrenFiles.Add(arm7ovFile);
            addFile(arm9binFile);
            mainDir.childrenFiles.Add(arm9binFile);
            addFile(arm7binFile);
            mainDir.childrenFiles.Add(arm7binFile);
            addFile(bannerFile);
            mainDir.childrenFiles.Add(bannerFile);
            addFile(rsaSigFile);
            mainDir.childrenFiles.Add(rsaSigFile);

            loadOvTable("overlay7", -99, mainDir, arm7ovFile);
            loadOvTable("overlay9", -98, mainDir, arm9ovFile);
            loadNamelessFiles(mainDir);
            checkForOverlaps(true);
        }
Пример #2
0
        public override void load()
        {
            //I have to do some tricky offset calculations here ...
            fatOffset = 0x1C;
            s.Seek(0x18, SeekOrigin.Begin); //number of files
            fatSize = (int)readUInt(s) * 8;

            s.Seek(fatSize + fatOffset + 4, SeekOrigin.Begin); //size of FNTB
            fntSize   = (int)readUInt(s) - 8;                  //do not include header
            fntOffset = fatSize + fatOffset + 8;

            fileDataOffsetP = fntSize + fntOffset + 8;
            fntFile         = new PhysicalFile(this, mainDir, -2, "fnt.bin", fntOffset, fntSize);
            fatFile         = new PhysicalFile(this, mainDir, -3, "fat.bin", fatOffset, fatSize);

            base.load();
            loadNamelessFiles(mainDir);
        }
Пример #3
0
        public void moveAllFiles(PhysicalFile first, int firstOffs)
        {
            this.allFiles.Sort();
            Console.Out.WriteLine("Moving file " + first.name);
            Console.Out.WriteLine("Into " + firstOffs.ToString("X"));
            int fileBegin = first.fileBegin;
            int num1      = firstOffs - fileBegin;

            Console.Out.WriteLine("DIFF " + num1.ToString("X"));
            int num2 = 4;

            for (int index = this.allFiles.IndexOf((File)first); index < this.allFiles.Count; ++index)
            {
                int alignment = ((PhysicalFile)this.allFiles[index]).alignment;
                if (alignment > num2)
                {
                    num2 = alignment;
                }
            }
            if (num1 % num2 != 0)
            {
                num1 += num2 - num1 % num2;
            }
            int count = this.getFilesystemEnd() - fileBegin;

            byte[] buffer = new byte[count];
            this.s.Seek((long)fileBegin, SeekOrigin.Begin);
            this.s.Read(buffer, 0, count);
            this.s.Seek((long)(fileBegin + num1), SeekOrigin.Begin);
            this.s.Write(buffer, 0, count);
            for (int index = this.allFiles.IndexOf((File)first); index < this.allFiles.Count; ++index)
            {
                ((PhysicalFile)this.allFiles[index]).fileBeginP += num1;
            }
            for (int index = this.allFiles.IndexOf((File)first); index < this.allFiles.Count; ++index)
            {
                ((PhysicalFile)this.allFiles[index]).saveOffsets();
            }
        }
Пример #4
0
        //TODO: Clean up this mess.
        public override void replace(byte[] newFile, object editor)
        {
            if (!isAGoodEditor(editor))
            {
                throw new Exception("NOT CORRECT EDITOR " + name);
            }

            if (newFile.Length != fileSize && !canChangeSize)
            {
                throw new Exception("TRYING TO RESIZE CONSTANT-SIZE FILE: " + name);
            }

            int newStart = fileBegin;

            //if we insert a bigger file it might not fit in the current place
            if (newFile.Length > fileSize)
            {
                if (canChangeOffset && !(parent is NarcFilesystem))
                {
                    newStart = ((PhysicalFilesystem)parent).findFreeSpace(newFile.Length, alignment);
                    if (newStart % alignment != 0)
                    {
                        newStart += alignment - newStart % alignment;
                    }
                }
                else
                {
                    //TODO: Keep the list always sorted in order to avoid stupid useless sorts.
                    parent.allFiles.Sort();
                    if (!(parent.allFiles.IndexOf(this) == parent.allFiles.Count - 1))
                    {
                        PhysicalFile nextFile = (PhysicalFile)parent.allFiles[parent.allFiles.IndexOf(this) + 1];
                        ((PhysicalFilesystem)parent).moveAllFiles(nextFile, fileBegin + newFile.Length);
                    }
                }
            }
            //This is for keeping NARC filesystems compact. Sucks.
            else if (parent is NarcFilesystem)
            {
                parent.allFiles.Sort();
                if (!(parent.allFiles.IndexOf(this) == parent.allFiles.Count - 1))
                {
                    PhysicalFile nextFile = (PhysicalFile)parent.allFiles[parent.allFiles.IndexOf(this) + 1];
                    ((PhysicalFilesystem)parent).moveAllFiles(nextFile, fileBegin + newFile.Length);
                }
            }

            //Stupid check.
            if (newStart % alignment != 0)
            {
                Console.Out.Write("Warning: File is not being aligned: " + name + ", at " + newStart.ToString("X"));
            }

            //write the file
            filesystemStream.Seek(newStart, SeekOrigin.Begin);
            filesystemStream.Write(newFile, 0, newFile.Length);

            //This should be handled in NarcFilesystem instead, in fileMoved (?)
            if (parent is NarcFilesystem)
            {
                PhysicalFile lastFile = (PhysicalFile)parent.allFiles[parent.allFiles.Count - 1];
                filesystemStream.SetLength(lastFile.fileBegin + lastFile.fileSize + 16);
            }

            //update ending pos
            fileBeginP = newStart;
            fileSizeP  = newFile.Length;
            saveOffsets();

            //Updates total used rom size in header, and/or other stuff.
            parent.fileMoved(this);
        }