示例#1
0
 internal static GAR analyzeGAR(string path)
 {
     GAR gar = new GAR
     {
         FileName = Path.GetFileNameWithoutExtension(path),
         FilePath = Path.GetDirectoryName(path),
         Extension = Path.GetExtension(path)
     };
     BinaryReader br = new BinaryReader(File.OpenRead(path));
     long len = br.BaseStream.Length;
     gar.Magic = br.ReadUInt32();
     gar.FileLength = br.ReadUInt32();
     if (gar.Magic != 0x02524147 || gar.FileLength != len)
     {
         gar.valid = false;
         return gar;
     }
     gar.valid = true;
     gar.Unknown = br.ReadUInt32();
     gar.HeaderLength = br.ReadUInt32();
     gar.FileMetaOffset = br.ReadUInt32();
     gar.FileOffsetsOffset = br.ReadUInt32();
     br.BaseStream.Seek(0x1C, SeekOrigin.Current);
     gar.FileCountOffset = br.ReadUInt32();
     gar.CTXBOffset = br.ReadUInt32();
     br.BaseStream.Seek(gar.FileOffsetsOffset, SeekOrigin.Begin);
     gar.DataOffset = br.ReadUInt32();
     gar.FileCount = (gar.DataOffset - gar.FileOffsetsOffset) / 4;
     br.BaseStream.Seek(gar.FileMetaOffset, SeekOrigin.Begin);
     gar.Files = new List<GARFile>();
     for (int i = 0; i < gar.FileCount; i++)
     {
         GARFile gf = new GARFile
         {
             Length = br.ReadUInt32(),
             NOffset = br.ReadUInt32(),
             NWEOffset = br.ReadUInt32()
         };
         gar.Files.Add(gf);
     }
     for (int i = 0; i < gar.FileCount; i++)
     {
         br.BaseStream.Seek(gar.Files[i].NOffset, SeekOrigin.Begin);
         StringBuilder sb = new StringBuilder();
         for (char c = br.ReadChar(); c != (char)0; c = br.ReadChar())
         {
             sb.Append(c);
         }
         gar.Files[i].Name = sb.ToString();
         br.BaseStream.Seek(gar.Files[i].NWEOffset, SeekOrigin.Begin);
         sb = new StringBuilder();
         for (char c = br.ReadChar(); c != (char)0; c = br.ReadChar())
         {
             sb.Append(c);
         }
         gar.Files[i].NameWithExtension = sb.ToString();
     }
     br.BaseStream.Seek(gar.FileOffsetsOffset, SeekOrigin.Begin);
     if (gar.Files.Count > 0)
     {
         gar.Files[0].Offset = gar.DataOffset;
         br.ReadUInt32();
     }
     for (int i = 1; i < gar.FileCount; i++)
     {
         gar.Files[i].Offset = br.ReadUInt32();
     }
     return gar;
 }
示例#2
0
        internal static GAR analyzeGAR(string path)
        {
            GAR gar = new GAR
            {
                FileName  = Path.GetFileNameWithoutExtension(path),
                FilePath  = Path.GetDirectoryName(path),
                Extension = Path.GetExtension(path)
            };
            BinaryReader br  = new BinaryReader(File.OpenRead(path));
            long         len = br.BaseStream.Length;

            gar.Magic      = br.ReadUInt32();
            gar.FileLength = br.ReadUInt32();
            if (gar.Magic != 0x02524147 || gar.FileLength != len)
            {
                gar.valid = false;
                return(gar);
            }
            gar.valid             = true;
            gar.Unknown           = br.ReadUInt32();
            gar.HeaderLength      = br.ReadUInt32();
            gar.FileMetaOffset    = br.ReadUInt32();
            gar.FileOffsetsOffset = br.ReadUInt32();
            br.BaseStream.Seek(0x1C, SeekOrigin.Current);
            gar.FileCountOffset = br.ReadUInt32();
            gar.CTXBOffset      = br.ReadUInt32();
            br.BaseStream.Seek(gar.FileOffsetsOffset, SeekOrigin.Begin);
            gar.DataOffset = br.ReadUInt32();
            gar.FileCount  = (gar.DataOffset - gar.FileOffsetsOffset) / 4;
            br.BaseStream.Seek(gar.FileMetaOffset, SeekOrigin.Begin);
            gar.Files = new List <GARFile>();
            for (int i = 0; i < gar.FileCount; i++)
            {
                GARFile gf = new GARFile
                {
                    Length    = br.ReadUInt32(),
                    NOffset   = br.ReadUInt32(),
                    NWEOffset = br.ReadUInt32()
                };
                gar.Files.Add(gf);
            }
            for (int i = 0; i < gar.FileCount; i++)
            {
                br.BaseStream.Seek(gar.Files[i].NOffset, SeekOrigin.Begin);
                StringBuilder sb = new StringBuilder();
                for (char c = br.ReadChar(); c != (char)0; c = br.ReadChar())
                {
                    sb.Append(c);
                }
                gar.Files[i].Name = sb.ToString();
                br.BaseStream.Seek(gar.Files[i].NWEOffset, SeekOrigin.Begin);
                sb = new StringBuilder();
                for (char c = br.ReadChar(); c != (char)0; c = br.ReadChar())
                {
                    sb.Append(c);
                }
                gar.Files[i].NameWithExtension = sb.ToString();
            }
            br.BaseStream.Seek(gar.FileOffsetsOffset, SeekOrigin.Begin);
            if (gar.Files.Count > 0)
            {
                gar.Files[0].Offset = gar.DataOffset;
                br.ReadUInt32();
            }
            for (int i = 1; i < gar.FileCount; i++)
            {
                gar.Files[i].Offset = br.ReadUInt32();
            }
            return(gar);
        }