Пример #1
0
        public static void unpack(string input)
        {
            StreamEx s = new StreamEx(input, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            string unpackdir = Path.GetFullPath(input) + "_unpack";

            if (!Directory.Exists(unpackdir))
            {
                Directory.CreateDirectory(unpackdir);
            }

            Int64 fixedHeaderRead = s.ReadInt64BigEndian();

            if (fixedHeaderRead != fixHeaderPS3FS_V1 &&
                fixedHeaderRead != fixHeaderDSARCFL)
            {
                throw new Exception("文件头不能识别");
            }

            Int32 fileCount = s.ReadInt32BigEndian();

            s.Position += 4;


            List <headerNode> headers = new List <headerNode>();

            if (fixedHeaderRead == fixHeaderPS3FS_V1)
            {
                Console.WriteLine("PS3FS_V1格式");
                for (int i = 0; i < fileCount; i++)
                {
                    headerNode h = new headerNode();
                    h.fileName   = s.ReadSimpleString(0x30);
                    s.Position  += 4;
                    h.fileLength = s.ReadInt32BigEndian();
                    s.Position  += 4;
                    h.fileOffset = s.ReadInt32BigEndian();
                    headers.Add(h);
                }
            }
            else if (fixedHeaderRead == fixHeaderDSARCFL)
            {
                Console.WriteLine("DSARC FL格式");
                for (int i = 0; i < fileCount; i++)
                {
                    headerNode h = new headerNode();
                    h.fileName   = s.ReadSimpleString(0x28);
                    h.fileLength = s.ReadInt32BigEndian();
                    h.fileOffset = s.ReadInt32BigEndian();
                    headers.Add(h);
                }
            }

            Console.WriteLine("文件头解析:共有{0}个文件", fileCount);

            for (int i = 0; i < headers.Count; i++)
            {
                StreamEx sNew = new StreamEx(unpackdir + "\\" + headers[i].fileName, FileMode.Create, FileAccess.Write);

                Console.WriteLine("正在解包文件{0}/{1}:{2} ({3}->{4})", i + 1, headers.Count, headers[i].fileName, headers[i].fileOffset, headers[i].fileLength);
                s.Position = headers[i].fileOffset;

                sNew.WriteFromStream(s, headers[i].fileLength);
                sNew.Close();
            }
        }
Пример #2
0
        public static void unpack(string input)
        {
            StreamEx s = new StreamEx(input, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            string unpackdir = Path.GetFullPath(input) + "_unpack";

            if (!Directory.Exists(unpackdir))
            {
                Directory.CreateDirectory(unpackdir);
            }

            Int64 fixedHeaderRead = s.ReadInt64BigEndian();

            if (fixedHeaderRead != fixHeaderFilename)
            {
                throw new Exception("文件头不能识别");
            }

            Int32 fileNameBlockEnd = s.ReadInt32BigEndian();

            List <Int32> fileNameOffset = new List <Int32>();

            fileNameOffset.Add(s.ReadInt32BigEndian() + 0xc);
            while (s.Position < fileNameOffset[0])
            {
                fileNameOffset.Add(s.ReadInt32BigEndian() + 0xc);
            }

            Console.WriteLine("共读取{0}个文件名索引", fileNameOffset.Count);
            fileNameOffset.Add(fileNameBlockEnd);
            List <string> fileNames = new List <string>();

            for (int i = 0; i < fileNameOffset.Count - 1; i++)
            {
                s.Position = fileNameOffset[i];
                fileNames.Add(s.ReadSimpleString(fileNameOffset[i + 1] - fileNameOffset[i]));
            }

            Console.WriteLine("共读取{0}个文件名索引", fileNames.Count);
            s.Position = align(s.Position);
            List <Int32> fileOffset = new List <Int32>();
            List <Int32> fileLength = new List <Int32>();

            Int64 packHeader = s.ReadInt64BigEndian();

            if (packHeader != fixHeaderPack)
            {
                throw new Exception("包块开头不能识别");
            }
            Int32 dataOffset = (Int32)s.Position + s.ReadInt32BigEndian();
            Int32 packCount  = s.ReadInt32BigEndian();

            for (int i = 0; i < packCount; i++)
            {
                fileOffset.Add(s.ReadInt32BigEndian());
                fileLength.Add(s.ReadInt32BigEndian());
            }

            for (int i = 0; i < packCount; i++)
            {
                StreamEx sNew = new StreamEx(unpackdir + "\\" + fileNames[i], FileMode.Create, FileAccess.Write);

                Console.WriteLine("正在解包文件{0}/{1}:{2} ({3}->{4})", i + 1, packCount, fileNames[i], fileOffset[i], fileLength[i]);
                s.Position = fileOffset[i];

                sNew.WriteFromStream(s, fileLength[i]);
                sNew.Close();
            }
        }