This commit is contained in:
Razmoth
2023-08-21 21:45:57 +04:00
parent 6da2387c8c
commit 0bd3fa6db2
48 changed files with 967 additions and 510 deletions

View File

@@ -27,12 +27,14 @@ namespace AssetStudio
FullPath = Path.GetFullPath(path);
FileName = Path.GetFileName(path);
FileType = CheckFileType();
Logger.Verbose($"File {path} type is {FileType}");
}
private FileType CheckFileType()
{
var signature = this.ReadStringToNull(20);
Position = 0;
Logger.Verbose($"Parsed signature is {signature}");
switch (signature)
{
case "ENCR":
@@ -47,46 +49,59 @@ namespace AssetStudio
return FileType.BlkFile;
default:
{
Logger.Verbose("signature does not match any of the supported string signatures, attempting to check bytes signatures");
byte[] magic = ReadBytes(2);
Position = 0;
Logger.Verbose($"Parsed signature is {Convert.ToHexString(magic)}");
if (gzipMagic.SequenceEqual(magic))
{
return FileType.GZipFile;
}
Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(gzipMagic)}");
Position = 0x20;
magic = ReadBytes(6);
Position = 0;
Logger.Verbose($"Parsed signature is {Convert.ToHexString(magic)}");
if (brotliMagic.SequenceEqual(magic))
{
return FileType.BrotliFile;
}
Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(brotliMagic)}");
if (IsSerializedFile())
{
return FileType.AssetsFile;
}
magic = ReadBytes(4);
Position = 0;
Logger.Verbose($"Parsed signature is {Convert.ToHexString(magic)}");
if (zipMagic.SequenceEqual(magic) || zipSpannedMagic.SequenceEqual(magic))
{
return FileType.ZipFile;
}
Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(zipMagic)} or {Convert.ToHexString(zipSpannedMagic)}");
if (mhy0Magic.SequenceEqual(magic))
{
return FileType.Mhy0File;
}
Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(mhy0Magic)}");
magic = ReadBytes(7);
Position = 0;
Logger.Verbose($"Parsed signature is {Convert.ToHexString(magic)}");
if (narakaMagic.SequenceEqual(magic))
{
return FileType.BundleFile;
}
Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(narakaMagic)}");
magic = ReadBytes(9);
Position = 0;
Logger.Verbose($"Parsed signature is {Convert.ToHexString(magic)}");
if (gunfireMagic.SequenceEqual(magic))
{
Position = 0x32;
return FileType.BundleFile;
}
Logger.Verbose($"Parsed signature does not match with expected signature {Convert.ToHexString(gunfireMagic)}");
Logger.Verbose($"Parsed signature does not match any of the supported signatures, assuming resource file");
return FileType.ResourceFile;
}
}
@@ -94,9 +109,12 @@ namespace AssetStudio
private bool IsSerializedFile()
{
Logger.Verbose($"Attempting to check if the file is serialized file...");
var fileSize = BaseStream.Length;
if (fileSize < 20)
{
Logger.Verbose($"File size 0x{fileSize:X8} is too small, minimal acceptable size is 0x14, aborting...");
return false;
}
var m_MetadataSize = ReadUInt32();
@@ -109,6 +127,7 @@ namespace AssetStudio
{
if (fileSize < 48)
{
Logger.Verbose($"File size 0x{fileSize:X8} for version {m_Version} is too small, minimal acceptable size is 0x30, aborting...");
Position = 0;
return false;
}
@@ -119,12 +138,15 @@ namespace AssetStudio
Position = 0;
if (m_FileSize != fileSize)
{
Logger.Verbose($"Parsed file size 0x{m_FileSize:X8} does not match stream size {fileSize}, file might be corrupted, aborting...");
return false;
}
if (m_DataOffset > fileSize)
{
Logger.Verbose($"Parsed data offset 0x{m_DataOffset:X8} is outside the stream of the size {fileSize}, file might be corrupted, aborting...");
return false;
}
Logger.Verbose($"Valid serialized file !!");
return true;
}
}
@@ -133,8 +155,10 @@ namespace AssetStudio
{
public static FileReader PreProcessing(this FileReader reader, Game game)
{
Logger.Verbose($"Applying preprocessing to file {reader.FileName}");
if (reader.FileType == FileType.ResourceFile || !game.Type.IsNormal())
{
Logger.Verbose("File is encrypted !!");
switch (game.Type)
{
case GameType.GI_Pack:
@@ -147,16 +171,13 @@ namespace AssetStudio
reader = DecryptEnsembleStar(reader);
break;
case GameType.OPFP:
reader = ParseOPFP(reader);
break;
case GameType.FakeHeader:
case GameType.ShiningNikki:
reader = ParseFakeHeader(reader);
break;
case GameType.FantasyOfWind:
reader = DecryptFantasyOfWind(reader);
break;
case GameType.ShiningNikki:
reader = ParseShiningNikki(reader);
break;
case GameType.HelixWaltz2:
reader = ParseHelixWaltz2(reader);
@@ -174,6 +195,7 @@ namespace AssetStudio
}
if (reader.FileType == FileType.BundleFile && game.Type.IsBlockFile())
{
Logger.Verbose("File might have multiple bundles !!");
try
{
var signature = reader.ReadStringToNull();
@@ -183,6 +205,8 @@ namespace AssetStudio
var size = reader.ReadInt64();
if (!(signature == "UnityFS" && size == reader.BaseStream.Length))
{
Logger.Verbose($"Found signature UnityFS, expected bundle size is 0x{size:X8}, found 0x{reader.BaseStream.Length} instead !!");
Logger.Verbose("Loading as block file !!");
reader.FileType = FileType.BlockFile;
}
}
@@ -190,6 +214,7 @@ namespace AssetStudio
reader.Position = 0;
}
Logger.Verbose("No preprocessing is needed");
return reader;
}
}