public static byte[] MakeHeader(FSARInfo Header) { byte[] OutHeader = new byte[0x20] { (byte)'F', (byte)'S', (byte)'A', (byte)'R', // Magic word 0x00, 0x00, 0x00, 0x02, // Compressed flag? 0x00, 0x00, 0x00, 0x00, // FileTable end 0x00, 0x00, 0x00, 0x00, // Number of files (byte)'x', (byte)'x', (byte)'x', (byte)'x', // 0x10 bytes long padding (byte)'x', (byte)'x', (byte)'x', (byte)'x', // 0x10 bytes long padding (byte)'x', (byte)'x', (byte)'x', (byte)'x', // 0x10 bytes long padding (byte)'x', (byte)'x', (byte)'x', (byte)'x', // 0x10 bytes long padding }; OutHeader.WriteInt32BE(0x08, Header.FileTableEnd); OutHeader.WriteInt32BE(0x0C, Header.FileTableObjects); return(OutHeader); }
public static FSARInfo ParseHeader(Byte[] Header) { FSARInfo CurHeader = new FSARInfo(); String MagicWord = "FSAR"; if (Header.Length == 0x20 || Header.Length == 0x10) // Verify the lenght of the given header (lenght it 0x20 if it includes the 0x10 bytes of padding) { if (Encoding.UTF8.GetString(Header, 0, 4) == MagicWord) // Verify if the magic word is right { CurHeader.FileTableEnd = Header.ReadInt32BE(0x08); CurHeader.FileTableObjects = Header.ReadInt32BE(0x0C); } else { throw new Exception(string.Format("Error: expected 'FSAR' as magic word, got '{0}' instead", Encoding.UTF8.GetString(Header, 0, 4))); } } return(CurHeader); }