mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 15:44:00 +08:00
(PakOpener): sanity checks.
This commit is contained in:
parent
1fc106c51a
commit
ea245a054d
@ -50,7 +50,7 @@ namespace GameRes.Formats.Elf
|
|||||||
public override ArcFile TryOpen (ArcView file)
|
public override ArcFile TryOpen (ArcView file)
|
||||||
{
|
{
|
||||||
string pak_name = Path.ChangeExtension (file.Name, "pak");
|
string pak_name = Path.ChangeExtension (file.Name, "pak");
|
||||||
if (!File.Exists (pak_name))
|
if (pak_name == file.Name || !File.Exists (pak_name))
|
||||||
return null;
|
return null;
|
||||||
var file_map = GetFileMap (pak_name);
|
var file_map = GetFileMap (pak_name);
|
||||||
if (null == file_map)
|
if (null == file_map)
|
||||||
@ -66,16 +66,16 @@ namespace GameRes.Formats.Elf
|
|||||||
return null;
|
return null;
|
||||||
List<Entry> dir;
|
List<Entry> dir;
|
||||||
if ("cg" == base_name)
|
if ("cg" == base_name)
|
||||||
dir = ReadCgPak (pak, file_map);
|
dir = ReadCgPak (pak, file, file_map);
|
||||||
else
|
else
|
||||||
dir = ReadVoicePak (pak, file_map);
|
dir = ReadVoicePak (pak, file, file_map);
|
||||||
if (null == dir)
|
if (null == dir)
|
||||||
return null;
|
return null;
|
||||||
return new ArcFile (file, this, dir);
|
return new ArcFile (file, this, dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Entry> ReadCgPak (ArcView pak, List<string> file_map)
|
List<Entry> ReadCgPak (ArcView pak, ArcView bin, List<string> file_map)
|
||||||
{
|
{
|
||||||
uint index_offset = 8;
|
uint index_offset = 8;
|
||||||
uint index_size = (uint)file_map.Count * 8u;
|
uint index_size = (uint)file_map.Count * 8u;
|
||||||
@ -87,13 +87,15 @@ namespace GameRes.Formats.Elf
|
|||||||
var entry = FormatCatalog.Instance.CreateEntry (file_map[i]);
|
var entry = FormatCatalog.Instance.CreateEntry (file_map[i]);
|
||||||
entry.Offset = pak.View.ReadUInt32 (index_offset);
|
entry.Offset = pak.View.ReadUInt32 (index_offset);
|
||||||
entry.Size = pak.View.ReadUInt32 (index_offset + 4);
|
entry.Size = pak.View.ReadUInt32 (index_offset + 4);
|
||||||
|
if (!entry.CheckPlacement (bin.MaxOffset))
|
||||||
|
return null;
|
||||||
dir.Add (entry);
|
dir.Add (entry);
|
||||||
index_offset += 8;
|
index_offset += 8;
|
||||||
}
|
}
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Entry> ReadVoicePak (ArcView pak, List<string> file_map)
|
List<Entry> ReadVoicePak (ArcView pak, ArcView bin, List<string> file_map)
|
||||||
{
|
{
|
||||||
uint index_offset = 8;
|
uint index_offset = 8;
|
||||||
uint index_size = (uint)file_map.Count * 0x18u;
|
uint index_size = (uint)file_map.Count * 0x18u;
|
||||||
@ -105,6 +107,8 @@ namespace GameRes.Formats.Elf
|
|||||||
var entry = FormatCatalog.Instance.CreateEntry (file_map[i]);
|
var entry = FormatCatalog.Instance.CreateEntry (file_map[i]);
|
||||||
entry.Offset = pak.View.ReadUInt32 (index_offset);
|
entry.Offset = pak.View.ReadUInt32 (index_offset);
|
||||||
entry.Size = pak.View.ReadUInt32 (index_offset + 4);
|
entry.Size = pak.View.ReadUInt32 (index_offset + 4);
|
||||||
|
if (!entry.CheckPlacement (bin.MaxOffset))
|
||||||
|
return null;
|
||||||
dir.Add (entry);
|
dir.Add (entry);
|
||||||
index_offset += 0x18;
|
index_offset += 0x18;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user