From 53c9a03e36c6bff28c7de403b5436689c08822d2 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Wed, 1 Jan 2025 17:35:02 +0800 Subject: [PATCH] update minitool3 --- minitool1.sln | 6 ++ minitool3/Program.cs | 103 +++++++++++++++++++++++ minitool3/Properties/launchSettings.json | 8 ++ minitool3/encrypted文件结构.txt | 13 +++ minitool3/minitool3.csproj | 10 +++ 5 files changed, 140 insertions(+) create mode 100644 minitool3/Program.cs create mode 100644 minitool3/Properties/launchSettings.json create mode 100644 minitool3/encrypted文件结构.txt create mode 100644 minitool3/minitool3.csproj diff --git a/minitool1.sln b/minitool1.sln index 86570c4..d4c67dd 100644 --- a/minitool1.sln +++ b/minitool1.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "minitool1", "minitool1\mini EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "minitool2", "minitool2\minitool2.csproj", "{0FE5458A-A3A9-4D0B-A540-BF4A7CD3F7EA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "minitool3", "minitool3\minitool3.csproj", "{F6B38C11-304C-4FF8-BB74-D4CA0E515189}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {0FE5458A-A3A9-4D0B-A540-BF4A7CD3F7EA}.Debug|Any CPU.Build.0 = Debug|Any CPU {0FE5458A-A3A9-4D0B-A540-BF4A7CD3F7EA}.Release|Any CPU.ActiveCfg = Release|Any CPU {0FE5458A-A3A9-4D0B-A540-BF4A7CD3F7EA}.Release|Any CPU.Build.0 = Release|Any CPU + {F6B38C11-304C-4FF8-BB74-D4CA0E515189}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6B38C11-304C-4FF8-BB74-D4CA0E515189}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6B38C11-304C-4FF8-BB74-D4CA0E515189}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6B38C11-304C-4FF8-BB74-D4CA0E515189}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/minitool3/Program.cs b/minitool3/Program.cs new file mode 100644 index 0000000..d3bb367 --- /dev/null +++ b/minitool3/Program.cs @@ -0,0 +1,103 @@ +using System.Security.Cryptography; +using System.Text; + +namespace minitool3 +{ + internal class Program + { + private const string DefaultSecretKey = "dB3aqcLtAmBd"; + private const string DefaultKeyBase = "RWd3NusabzRc"; + + static void Main(string[] args) + { + if (args.Length == 0) + { + Console.WriteLine("Please drag and drop one or more files onto this program."); + Console.ReadKey(); + return; + } + + Byte[] SHA256Byte = GenerateSHA256Byte(DefaultKeyBase, Encoding.UTF8.GetBytes(DefaultSecretKey)); + + foreach (var filePath in args) + { + if (File.Exists(filePath)) + { + Console.WriteLine($"Processing file: {filePath}"); + try + { + byte[] fileData = File.ReadAllBytes(filePath); + + if (fileData.Length < 20) // 4 bytes (size) + 16 bytes (IV) + { + Console.WriteLine("The file does not contain enough data for size and IV."); + continue; + } + + // Read the encrypted data & iv size (4 bytes) + int encryptedSize = BitConverter.ToInt32(fileData, 0); + + if (encryptedSize <= 0 || encryptedSize > fileData.Length - 4) + { + Console.WriteLine("Invalid encrypted data size."); + continue; + } + + encryptedSize -= 16; + + // Read the IV (16 bytes) + byte[] iv = new byte[16]; + Array.Copy(fileData, 4, iv, 0, 16); + + // Read the ciphertext based on the size + byte[] cipherText = new byte[encryptedSize]; + Array.Copy(fileData, 20, cipherText, 0, encryptedSize); + + byte[] decryptedData = Decrypt(cipherText, SHA256Byte, iv); + + string outputDir = Path.Combine(Path.GetDirectoryName(filePath)!, "dec"); + Directory.CreateDirectory(outputDir); // Ensure the directory exists + string outputFilePath = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(filePath) + ".assets"); + File.WriteAllBytes(outputFilePath, decryptedData); + + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } + else + { + Console.WriteLine($"File not found: {filePath}"); + } + } + + Console.WriteLine("Processing complete. Press any key to exit."); + Console.ReadKey(); + } + + public static byte[] GenerateSHA256Byte(string data, byte[] key) + { + using var hmac = new HMACSHA256(key); + return hmac.ComputeHash(Encoding.UTF8.GetBytes(data)); + } + + public static byte[] Decrypt(byte[] cipherText, byte[] sha256Key, byte[] iv) + { + using var aes = Aes.Create(); + aes.Key = sha256Key; + aes.IV = iv; + aes.Mode = CipherMode.CBC; + aes.Padding = PaddingMode.PKCS7; + + using var decryptor = aes.CreateDecryptor(); + using var memoryStream = new MemoryStream(cipherText); + using var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read); + + byte[] decryptedData = new byte[cipherText.Length]; + int bytesRead = cryptoStream.Read(decryptedData, 0, decryptedData.Length); + + return [.. decryptedData]; + } + } +} diff --git a/minitool3/Properties/launchSettings.json b/minitool3/Properties/launchSettings.json new file mode 100644 index 0000000..f5f5461 --- /dev/null +++ b/minitool3/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "minitool3": { + "commandName": "Project", + "commandLineArgs": "\"G:\\source\\minitool1\\minitool3\\bin\\Debug\\net8.0\\bg_avg_003.jp.encrypted\"" + } + } +} \ No newline at end of file diff --git a/minitool3/encrypted文件结构.txt b/minitool3/encrypted文件结构.txt new file mode 100644 index 0000000..97d8006 --- /dev/null +++ b/minitool3/encrypted文件结构.txt @@ -0,0 +1,13 @@ +*.encrypted文件结构 +(D) +4B: enc data + iv size +16B: iv +{data size}B: enc data(AES256 encryption) + + +SecretKey = "dB3aqcLtAmBd" +KeyBase = "RWd3NusabzRc" + +hmac = new HMACSHA256(Encoding.UTF8.GetBytes(SecretKey)) +AESKey = hmac.ComputeHash(Encoding.UTF8.GetBytes(KeyBase)) +iv = 看顶上 diff --git a/minitool3/minitool3.csproj b/minitool3/minitool3.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/minitool3/minitool3.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + +