From e862a3e3aa40a4c44e9b249b4e00fdfd536c8c8b Mon Sep 17 00:00:00 2001 From: Villermen Date: Mon, 24 Nov 2014 11:12:24 +0100 Subject: [PATCH] Compressed and first 5 bytes correlate So now it will always remove 5 bytes (and 4 more for compressed files). Closes #5. --- Program.cs | 53 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/Program.cs b/Program.cs index acb0f04..146c574 100644 --- a/Program.cs +++ b/Program.cs @@ -211,12 +211,17 @@ namespace RSCacheTool string outFileName = fileIndex.ToString(); byte[] tempBuffer; + //remove the first 5 bytes because they are not part of the file + tempBuffer = new byte[fileSize - 5]; + Array.Copy(buffer, 5, tempBuffer, 0, fileSize - 5); + buffer = tempBuffer; + //decompress gzip - if (buffer.Length > 10 && (buffer[9] << 8) + buffer[10] == 0x1f8b) //gzip + if (buffer.Length > 5 && (buffer[4] << 8) + buffer[5] == 0x1f8b) //gzip { - //remove the first 9 bytes cause they seem to be descriptors of sorts (no idea what they do but they are not part of the file) - tempBuffer = new byte[fileSize - 9]; - Array.Copy(buffer, 9, tempBuffer, 0, fileSize - 9); + //remove another 4 non-file bytes + tempBuffer = new byte[fileSize - 4]; + Array.Copy(buffer, 4, tempBuffer, 0, fileSize - 4); buffer = tempBuffer; GZipStream decompressionStream = new GZipStream(new MemoryStream(buffer), CompressionMode.Decompress); @@ -241,11 +246,11 @@ namespace RSCacheTool } //decompress bzip2 - if (buffer.Length > 14 && buffer[9] == 0x31 && buffer[10] == 0x41 && buffer[11] == 0x59 && buffer[12] == 0x26 && buffer[13] == 0x53 && buffer[14] == 0x59) //bzip2 + if (buffer.Length > 9 && buffer[4] == 0x31 && buffer[5] == 0x41 && buffer[6] == 0x59 && buffer[7] == 0x26 && buffer[8] == 0x53 && buffer[9] == 0x59) //bzip2 { - //remove the first 9 bytes cause they seem to be descriptors of sorts (no idea what they do but they are not part of the file) - tempBuffer = new byte[fileSize - 9]; - Array.Copy(buffer, 9, tempBuffer, 0, fileSize - 9); + //remove another 4 non-file bytes + tempBuffer = new byte[fileSize - 4]; + Array.Copy(buffer, 4, tempBuffer, 0, fileSize - 4); buffer = tempBuffer; //prepend file header @@ -285,44 +290,14 @@ namespace RSCacheTool if (buffer.Length > 3 && (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] == 0x4f676753) outFileName += ".ogg"; - //detect ogg: 5 bytes - OggS - if (buffer.Length > 8 && (buffer[5] << 24) + (buffer[6] << 16) + (buffer[7] << 8) + buffer[8] == 0x4f676753) - { - tempBuffer = new byte[fileSize - 5]; - Array.Copy(buffer, 5, tempBuffer, 0, fileSize - 5); - buffer = tempBuffer; - - outFileName += ".ogg"; - } - - //detect jag: JAGA + //detect jaga: JAGA if (buffer.Length > 3 && (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] == 0x4a414741) outFileName += ".jaga"; - //detect jag: 5 bytes - JAGA - if (buffer.Length > 8 && (buffer[5] << 24) + (buffer[6] << 16) + (buffer[7] << 8) + buffer[8] == 0x4a414741) - { - tempBuffer = new byte[fileSize - 5]; - Array.Copy(buffer, 5, tempBuffer, 0, fileSize - 5); - buffer = tempBuffer; - - outFileName += ".jaga"; - } - //detect png: .PNG if (buffer.Length > 3 && (uint)(buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] == 0x89504e47) outFileName += ".png"; - //detect png: 5 bytes - .PNG - if (buffer.Length > 8 && (uint)(buffer[5] << 24) + (buffer[6] << 16) + (buffer[7] << 8) + buffer[8] == 0x89504e47) - { - tempBuffer = new byte[fileSize - 5]; - Array.Copy(buffer, 5, tempBuffer, 0, fileSize - 5); - buffer = tempBuffer; - - outFileName += ".png"; - } - //create and write file if (!Directory.Exists(outFileDir)) Directory.CreateDirectory(outFileDir);