コード例 #1
0
        public Dictionary <string, byte[]> unpackRam(Stream src)
        {
            Dictionary <string, byte[]> res = new Dictionary <string, byte[]>();
            BinaryDataReader            br  = new BinaryDataReader(src, false);

            br.ByteOrder = ByteOrder.BigEndian;

            br.BaseStream.Position = 0;
            br.ReadUInt32();               // Header
            br.ReadUInt16();               // Chunk length
            if (br.ReadUInt16() == 0xFFFE) // BOM
            {
                br.ByteOrder = ByteOrder.LittleEndian;
            }
            else
            {
                br.ByteOrder = ByteOrder.BigEndian;
            }
            br.ReadUInt32(); // File size
            UInt32 startingOff = br.ReadUInt32();

            br.ReadUInt32(); // Unknown;
            SFAT sfat = new SFAT();

            sfat.parse(br, (int)br.BaseStream.Position);
            SFNT sfnt = new SFNT();

            sfnt.parse(br, (int)br.BaseStream.Position, sfat, (int)startingOff);

            for (int m = 0; m < sfat.nodeCount; m++)
            {
                br.Seek(sfat.nodes[m].nodeOffset + startingOff, 0);
                byte[] temp;
                if (m == 0)
                {
                    temp = br.ReadBytes((int)sfat.nodes[m].EON);
                }
                else
                {
                    int tempInt = (int)sfat.nodes[m].EON - (int)sfat.nodes[m].nodeOffset;
                    temp = br.ReadBytes(tempInt);
                }
                res.Add(sfnt.fileNames[m], temp);
            }
            new SARC();
            return(res);
        }
コード例 #2
0
        public SARC(byte[] Data)
        {
            EndianBinaryReaderEx er = new EndianBinaryReaderEx(new MemoryStream(Data), Endianness.LittleEndian);

            try
            {
                Header = new SARCHeader(er);
                SFat   = new SFAT(er);
                SFnt   = new SFNT(er);
                er.BaseStream.Position = Header.FileDataOffset;
                this.Data = er.ReadBytes((int)(Header.FileSize - Header.FileDataOffset));
            }
            finally
            {
                er.Close();
            }
        }
コード例 #3
0
        public void FromFileSystem(SFSDirectory Root)
        {
            Header         = new SARCHeader();
            SFat           = new SFAT();
            SFat.NrEntries = (ushort)Root.Files.Count;
            uint DataStart = 0;

            foreach (var v in Root.Files)
            {
                while ((DataStart % 128) != 0)
                {
                    DataStart++;
                }
                uint hash;
                if (v.FileName == string.Format("0x{0:X8}", v.FileID))
                {
                    hash = (uint)v.FileID;
                }
                else
                {
                    hash = GetHashFromName(v.FileName);
                }
                SFat.Entries.Add(new SFAT.SFATEntry()
                {
                    FileDataStart = DataStart, FileDataEnd = (uint)(DataStart + v.Data.Length), FileNameHash = hash, FileNameOffset = 0
                });
                DataStart += (uint)v.Data.Length;
            }
            Data = new byte[DataStart];
            int i = 0;

            foreach (var v in Root.Files)
            {
                Array.Copy(v.Data, 0, Data, SFat.Entries[i].FileDataStart, v.Data.Length);
                i++;
            }
            SFnt            = new SFNT();
            Header.FileSize = (uint)(0x14 + 0xC + SFat.NrEntries * 0x10 + 0x8);
            while ((Header.FileSize % 128) != 0)
            {
                Header.FileSize++;
            }
            Header.FileDataOffset = Header.FileSize;
            Header.FileSize      += (uint)Data.Length;
        }
コード例 #4
0
            public void Parse(BinaryStream bs, int pos, SFAT sfat, int start)
            {
                chunkID   = bs.ReadUInt32();
                chunkSize = bs.ReadUInt16();
                unknown1  = bs.ReadUInt16();

                string temp = bs.ReadString(start - (int)bs.BaseStream.Position);

                char[]   splitter = { (char)0x00 };
                string[] names    = temp.Split(splitter);
                for (int j = 0; j < names.Length; j++)
                {
                    if (names[j] != "")
                    {
                        fileNames.Add(names[j]);
                    }
                }
            }
コード例 #5
0
ファイル: SARC.cs プロジェクト: vpn-001/SwitchThemeInjector
            public void parse(BinaryDataReader br, int pos, SFAT sfat, int start)
            {
                chunkID   = br.ReadUInt32();
                chunkSize = br.ReadUInt16();
                unknown1  = br.ReadUInt16();

                char[] temp  = br.ReadChars(start - (int)br.BaseStream.Position);
                string temp2 = new string(temp);

                char[]   splitter = { (char)0x00 };
                string[] names    = temp2.Split(splitter);
                for (int j = 0; j < names.Length; j++)
                {
                    if (names[j] != "")
                    {
                        fileNames.Add(names[j]);
                    }
                }
            }
コード例 #6
0
        public void FromFileSystem(SFSDirectory Root)
        {
            Header         = new SARCHeader();
            SFat           = new SFAT();
            SFat.NrEntries = (ushort)Root.Files.Count;
            uint DataStart = 0;

            Root.Files.Sort(delegate(SFSFile a, SFSFile b) {
                uint hasha = (uint)a.FileID;
                uint hashb = (uint)b.FileID;
                return(hasha.CompareTo(hashb));
            });
            foreach (var v in Root.Files)
            {
                while ((DataStart % 128) != 0)
                {
                    DataStart++;
                }
                uint hash = (uint)v.FileID;
                SFat.Entries.Add(new SFAT.SFATEntry()
                {
                    FileDataStart = DataStart, FileDataEnd = (uint)(DataStart + v.Data.Length), FileNameHash = hash, FileNameOffset = 0
                });
                DataStart += (uint)v.Data.Length;
            }
            Data = new byte[DataStart];
            int i = 0;

            foreach (var v in Root.Files)
            {
                Array.Copy(v.Data, 0, Data, SFat.Entries[i].FileDataStart, v.Data.Length);
                i++;
            }
            SFnt            = new SFNT();
            Header.FileSize = (uint)(0x14 + 0xC + SFat.NrEntries * 0x10 + 0x8);
            while ((Header.FileSize % 128) != 0)
            {
                Header.FileSize++;
            }
            Header.FileDataOffset = Header.FileSize;
            Header.FileSize      += (uint)Data.Length;
        }
コード例 #7
0
        public static SarcData UnpackRamN(Stream src)
        {
            Dictionary <string, byte[]> res = new Dictionary <string, byte[]>();
            BinaryStream bs = new BinaryStream(src, ByteConverter.Little, leaveOpen: false);

            bs.BaseStream.Position = 6;
            if (bs.ReadUInt16() == 0xFFFE)
            {
                bs.ByteConverter = ByteConverter.Big;
            }
            bs.BaseStream.Position = 0;
            if (bs.ReadString(4) != "SARC")
            {
                throw new Exception("Wrong magic");
            }

            bs.ReadUInt16(); // Chunk length
            bs.ReadUInt16(); // BOM
            bs.ReadUInt32(); // File size
            UInt32 startingOff = bs.ReadUInt32();

            bs.ReadUInt32(); // Unknown;
            SFAT sfat = new SFAT();

            sfat.Parse(bs, (int)bs.BaseStream.Position);
            SFNT sfnt = new SFNT();

            sfnt.Parse(bs, (int)bs.BaseStream.Position, sfat, (int)startingOff);

            bool HashOnly = false;

            if (sfat.nodeCount > 0)
            {
                if (sfat.nodes[0].fileBool != 1)
                {
                    HashOnly = true;
                }
            }

            for (int m = 0; m < sfat.nodeCount; m++)
            {
                bs.Seek(sfat.nodes[m].nodeOffset + startingOff, 0);
                byte[] temp;
                if (m == 0)
                {
                    temp = bs.ReadBytes((int)sfat.nodes[m].EON);
                }
                else
                {
                    int tempInt = (int)sfat.nodes[m].EON - (int)sfat.nodes[m].nodeOffset;
                    temp = bs.ReadBytes(tempInt);
                }
                if (sfat.nodes[m].fileBool == 1)
                {
                    res.Add(sfnt.fileNames[m], temp);
                }
                else
                {
                    res.Add(sfat.nodes[m].hash.ToString("X8") + GuessFileExtension(temp), temp);
                }
            }

            return(new SarcData()
            {
                endianness = bs.ByteConverter.Endian, HashOnly = HashOnly, Files = res
            });
        }
コード例 #8
0
        public static SarcData UnpackRamN(Stream src)
        {
            Dictionary <string, Stream> res = new Dictionary <string, Stream>();
            BinaryDataReader            br  = new BinaryDataReader(src, Encoding.UTF8, true);

            br.ByteOrder           = ByteOrder.LittleEndian;
            br.BaseStream.Position = 6;
            if (br.ReadUInt16() == 0xFFFE)
            {
                br.ByteOrder = ByteOrder.BigEndian;
            }
            br.BaseStream.Position = 0;
            if (br.ReadString(4) != "SARC")
            {
                throw new Exception("Wrong magic");
            }

            br.ReadUInt16(); // Chunk length
            br.ReadUInt16(); // BOM
            br.ReadUInt32(); // File size
            UInt32 startingOff = br.ReadUInt32();

            br.ReadUInt32(); // Unknown;
            SFAT sfat = new SFAT();

            sfat.parse(br, (int)br.BaseStream.Position);
            SFNT sfnt = new SFNT();

            sfnt.parse(br, (int)br.BaseStream.Position, sfat, (int)startingOff);

            bool HashOnly = false;

            if (sfat.nodeCount > 0)
            {
                if (sfat.nodes[0].fileBool != 1)
                {
                    HashOnly = true;
                }
            }

            for (int m = 0; m < sfat.nodeCount; m++)
            {
                br.Seek(sfat.nodes[m].nodeOffset + startingOff, 0);
                uint size = 0;
                if (m == 0)
                {
                    size = sfat.nodes[m].EON;
                }
                else
                {
                    size = sfat.nodes[m].EON - sfat.nodes[m].nodeOffset;
                }

                var temp = new SubStream(br.BaseStream, br.Position, size);

                if (sfat.nodes[m].fileBool == 1)
                {
                    res.Add(sfnt.fileNames[m], temp);
                }
                else
                {
                    res.Add(sfat.nodes[m].hash.ToString("X8") + GuessFileExtension(temp.ToArray()), temp);
                }
            }

            return(new SarcData()
            {
                endianness = br.ByteOrder, HashOnly = HashOnly, Files = res
            });
        }