Start to implement BlakHole encryption (what method does it use?)
This commit is contained in:
parent
2454e2a1e8
commit
bc3f121ece
@ -39,7 +39,7 @@ namespace UniversalEditor.DataFormats.FileSystem.ZipTV.BlakHole
|
||||
// uncompressed deflate fuse bzip2-ultra bzip2-normal
|
||||
byte unknown1 = reader.ReadByte(); // 5
|
||||
byte unknown2 = reader.ReadByte(); // 7
|
||||
ushort unknown3 = reader.ReadUInt16(); // 49
|
||||
BHEncryptionMethod encryptionMethod = (BHEncryptionMethod)reader.ReadUInt16(); // 49
|
||||
ushort unknown4 = reader.ReadUInt16(); // 55845
|
||||
ushort windowSize = reader.ReadUInt16(); // 4 516 4 516 4
|
||||
BHCompressionMethod compressionMethod = (BHCompressionMethod)reader.ReadByte(); // 0 8 3 12 12
|
||||
@ -65,6 +65,7 @@ namespace UniversalEditor.DataFormats.FileSystem.ZipTV.BlakHole
|
||||
file.Size = decompressedSize;
|
||||
file.Properties.Add("reader", reader);
|
||||
file.Properties.Add("offset", offset);
|
||||
file.Properties.Add("EncryptionMethod", encryptionMethod);
|
||||
file.Properties.Add("CompressionMethod", compressionMethod);
|
||||
file.Properties.Add("CompressedSize", compressedSize);
|
||||
file.Properties.Add("DecompressedSize", decompressedSize);
|
||||
@ -154,9 +155,21 @@ namespace UniversalEditor.DataFormats.FileSystem.ZipTV.BlakHole
|
||||
BHCompressionMethod compressionMethod = (BHCompressionMethod)file.Properties["CompressionMethod"];
|
||||
uint compressedSize = (uint)file.Properties["CompressedSize"];
|
||||
uint decompressedSize = (uint)file.Properties["DecompressedSize"];
|
||||
BHEncryptionMethod encryptionMethod = (BHEncryptionMethod)file.Properties["EncryptionMethod"];
|
||||
|
||||
reader.Seek(offset, SeekOrigin.Begin);
|
||||
byte[] compressedData = reader.ReadBytes(compressedSize);
|
||||
|
||||
switch (encryptionMethod)
|
||||
{
|
||||
case BHEncryptionMethod.Encrypted:
|
||||
{
|
||||
byte[] decryptedData = BHEncryptDecrypt.Decrypt(compressedData, "mike-marco");
|
||||
compressedData = decryptedData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] decompressedData = null;
|
||||
switch (compressionMethod)
|
||||
{
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.DataFormats.FileSystem.ZipTV.BlakHole
|
||||
{
|
||||
internal class BHEncryptDecrypt
|
||||
{
|
||||
// This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
|
||||
// This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
|
||||
// 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
|
||||
private static readonly byte[] initVectorBytes = Encoding.ASCII.GetBytes("tu89geji340t89u2");
|
||||
|
||||
// This constant is used to determine the keysize of the encryption algorithm.
|
||||
private const int keysize = 256;
|
||||
|
||||
public static byte[] Decrypt(byte[] input, string password)
|
||||
{
|
||||
PasswordDeriveBytes passwd = new PasswordDeriveBytes(password, null);
|
||||
|
||||
byte[] keyBytes = passwd.GetBytes(keysize / 8);
|
||||
using (AesManaged symmetricKey = new AesManaged())
|
||||
{
|
||||
symmetricKey.Mode = CipherMode.CBC;
|
||||
using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(input))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
byte[] output = new byte[input.Length];
|
||||
int decryptedByteCount = cryptoStream.Read(output, 0, output.Length);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.DataFormats.FileSystem.ZipTV.BlakHole
|
||||
{
|
||||
public enum BHEncryptionMethod
|
||||
{
|
||||
None = 49,
|
||||
Encrypted = 44
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user