C# - 真封神游戏 pak 文件解密代码

        public bool ReadZfsFile(string ZfsFile)
{
try
{
FileStream fs
= new FileStream(ZfsFile, FileMode.Open, FileAccess.Read);
BinaryReader r
= new BinaryReader(fs);
//文件头
r.ReadBytes(0x1d);
int mapoffset = r.ReadInt32();
r.ReadInt32();
int cnt = r.ReadInt32();
mapoffset
+= 23;
for (int i = 0; i < cnt; i++)
{
//文件表
fs.Seek(mapoffset, SeekOrigin.Begin);
int namelen = r.ReadInt32();
char[] name = r.ReadChars(namelen);
int fileoffset = r.ReadInt32();
int filesize = r.ReadInt32();
mapoffset
+= namelen + 44;
//文件
fs.Seek(fileoffset, SeekOrigin.Begin);
string file = new string(name);
string dir = Path.GetDirectoryName(file);
if (dir.Length > 0) Directory.CreateDirectory(dir);
FileStream fw
= new FileStream(file, FileMode.CreateNew);
BinaryWriter w
= new BinaryWriter(fw);
byte[] con = r.ReadBytes(filesize);
w.Write(con);
w.Close();
fw.Close();
}
fs.Close();
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}


//用法:

if (ReadZfsFile("gameworld_server.pak"))
{
MessageBox.Show(
"成功");
}
 

posted on 2008-11-27 14:42  jxgxy  阅读(2473)  评论(3编辑  收藏  举报

导航