internal static void SanityCheckEntry(Big.Entry entry, Big.Target platform) { if (entry.CompressionScheme == Big.CompressionScheme.None) { if (platform != Big.Target.Xbox360 && entry.UncompressedSize != 0) { throw new FormatException("got entry with no compression with a non-zero uncompressed size"); } } else if (entry.CompressionScheme == Big.CompressionScheme.LZO1x || entry.CompressionScheme == Big.CompressionScheme.Zlib) { if (entry.CompressedSize == 0 && entry.UncompressedSize > 0) { throw new FormatException( "got entry with compression with a zero compressed size and a non-zero uncompressed size"); } } else if (entry.CompressionScheme == Big.CompressionScheme.Xbox) { if (entry.CompressedSize == 0 && entry.UncompressedSize > 0) { throw new FormatException( "got entry with compression with a zero compressed size and a non-zero uncompressed size"); } } else { throw new FormatException("got entry with unsupported compression scheme"); } }
private static bool IsValidTargetPlatform(Big.Target target, Big.Platform platform, byte unknown70) { if (target == Big.Target.Any) { if (platform != Big.Platform.Any) { return(false); } if (unknown70 != 0x32) { return(false); } } else if (target == Big.Target.Win64) { if (platform != (Big.Platform) 5) { return(false); } if (unknown70 != 0x32) { return(false); } } else if (target == Big.Target.Xbox360) { if (platform != (Big.Platform) 5) { return(false); } if (unknown70 != 0x37) { return(false); } } else { return(false); } return(true); }
public void Deserialize(Stream input) { var magic = input.ReadValueU32(Endian.Little); if (magic != _Signature) { throw new FormatException("bad magic"); } var version = input.ReadValueS32(Endian.Little); if (version < 7 || version > 8) { throw new FormatException("unsupported version"); } var flags = input.ReadValueU32(Endian.Little); var target = (Big.Target)(flags & 0xFF); var platform = (Big.Platform)((flags >> 8) & 0xFF); var flags02 = (byte)((flags >> 16) & 0xFF); if ((flags & ~0xFFFFFFu) != 0) { throw new FormatException("unknown flags"); } if (target != Big.Target.Any && target != Big.Target.Win32 && target != Big.Target.Xbox360 && target != Big.Target.PS3 && target != Big.Target.Win64 && target != Big.Target.WiiU) { throw new FormatException("unsupported or invalid platform"); } if (IsValidTargetPlatform(target, platform, flags02) == false) { throw new FormatException("invalid flags"); } this._Version = version; this._Target = target; this._Platform = platform; this._Unknown70 = flags02; var endian = this.Endian; var entrySerializer = this.GetEntrySerializer(); this._Entries.Clear(); uint entryCount = input.ReadValueU32(Endian.Little); for (uint i = 0; i < entryCount; i++) { Big.Entry entry; entrySerializer.Deserialize(input, Endian.Little, out entry); this._Entries.Add(entry); } uint localizationCount = input.ReadValueU32(Endian.Little); for (uint i = 0; i < localizationCount; i++) { var nameLength = input.ReadValueU32(Endian.Little); if (nameLength > 32) { throw new FormatException("bad length for localization name"); } var nameBytes = input.ReadBytes((int)nameLength); var unknownValue = input.ReadValueU64(Endian.Little); } foreach (var entry in this.Entries) { SanityCheckEntry(entry, target); } }