Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static int getPackageCountFromRawBinary(byte[] internalData)
- {
- byte[] numArray = new byte[2];
- Array.Copy((Array)internalData, 20, (Array)numArray, 0, 2);
- return (int)BitConverter.ToUInt16(numArray, 0);
- }
- static string calculateMD5ofByteArray(byte[] byte_0)
- {
- return BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(byte_0)).Replace("-", "");
- }
- static bool tcopp_sanity_check(byte[] tcopp)
- {
- string[] md5hashes = new string[16]
- {
- "13F817878913B3A22452D6274BC24D99",
- "1AD1DBA1544F722D74729862BECE1726",
- "940F2CC79DF835D5C9C18F860A297128",
- "667D549AAF7112ED6BA41C278D587D02",
- "09168B35EB7AD2D80EEAB9669608338A",
- "3CE89D4D2CCA98645C573CDD5983AB6D",
- "D82C24AF79C34439551E20C4FAB7B79E",
- "D0EBAAF957F88A4BBD6314A7AF080759",
- "0AE2781B988852DA5566E169F8DDBA30",
- "FEEBC8437D791C98C413E02118AC33A0",
- "26FE20E48A6E3D7E50F1882AB2727CEB",
- "E2EA82BAC16FC70ADA2AF3283CA67F59",
- "E5B7934744C928BC119B891CB9F8BC0A",
- "0271C2AA4224CB140B8730FDD1DCDBAB",
- "B4D8D2BFBE7A766B214D7B8857741A29",
- "997F8E5876C4DBB5B6FD787C2B131E09"
- };
- Console.WriteLine($" => Length = {tcopp.Length}");
- Console.WriteLine($" => Type = {tcopp[0].ToString()}");
- if ((tcopp.Length != 266) &&
- (tcopp.Length != 541))
- {
- Console.WriteLine($" => tcopp size not valid (size = {tcopp.Length})");
- return false;
- }
- if ((tcopp[0] != 4) &&
- (tcopp[0] != 2))
- {
- Console.WriteLine($" => header type not valid (type = {tcopp[0].ToString()})");
- return false;
- }
- if (((tcopp.Length == 266) && (tcopp[0] != (byte)2)) ||
- ((tcopp.Length == 541) && (tcopp[0] != (byte)4)))
- {
- Console.WriteLine($" => header doesn't match tcopp size (size = {tcopp.Length}, header = {tcopp[0].ToString()})");
- return false;
- }
- byte[] magicConstantData = new byte[284];
- Array.Copy(tcopp, /* Copy from this array */
- 1, /* Copy from this offset */
- magicConstantData, /* Copy to this array */
- 0, /* Copy to this offset */
- magicConstantData.Length /* Max size of the target array */
- );
- string magicConstantDataMD5 = calculateMD5ofByteArray(magicConstantData);
- Console.WriteLine($" => MagicConstantDataMD5 = {magicConstantDataMD5}");
- if (Array.IndexOf(md5hashes, magicConstantDataMD5) < 0)
- {
- Console.WriteLine($" => MD5 not in hardcoded md5 list (MD5 = {magicConstantDataMD5})");
- return false;
- }
- return true;
- }
- static void Main(string[] args)
- {
- if (args.Length == 0)
- {
- Console.WriteLine("Invoke this app with a .min file!");
- return;
- }
- string file = args[0];
- try
- {
- byte[] rawMinData = File.ReadAllBytes(file);
- byte[] rawDataWithoutHeader = new byte[rawMinData.Length - 22];
- Array.Copy((Array)rawMinData, 22, (Array)rawDataWithoutHeader, 0, rawMinData.Length - 22);
- byte[] internalData;
- Dictionary<string, byte[]> dictionary_0;
- RijndaelManaged rijndaelManaged = new RijndaelManaged();
- rijndaelManaged.Key = Encoding.UTF8.GetBytes("0619431931167B5466CA4256A2124504");
- rijndaelManaged.IV = Encoding.UTF8.GetBytes("3EEACFF1842BEB65");
- rijndaelManaged.Mode = CipherMode.CBC;
- ICryptoTransform decryptor = rijndaelManaged.CreateDecryptor(rijndaelManaged.Key, rijndaelManaged.IV);
- MemoryStream memoryStream = new MemoryStream();
- CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Write);
- cryptoStream.Write(rawDataWithoutHeader, 0, rawDataWithoutHeader.Length);
- cryptoStream.FlushFinalBlock();
- File.WriteAllBytes($"{file}_decrypted_raw.bin", memoryStream.ToArray());
- internalData = memoryStream.ToArray();
- dictionary_0 = new Dictionary<string, byte[]>();
- Console.WriteLine($"Package Count = {getPackageCountFromRawBinary(internalData)}");
- if (getPackageCountFromRawBinary(internalData) == 0)
- {
- return;
- }
- for (int index = 0; index < getPackageCountFromRawBinary(internalData); ++index)
- {
- /* Header of package */
- int sourceIndex1 = 22 + 20 * index + 541 * index;
- byte[] bytes = new byte[20];
- Array.Copy((Array)internalData, sourceIndex1, (Array)bytes, 0, 20);
- string pkgID = Encoding.ASCII.GetString(bytes).ToUpper();
- /* Data of package */
- int sourceIndex2 = 22 + 20 * index + 541 * index + 20;
- byte[] pkgData = new byte[541];
- Array.Copy((Array)internalData, sourceIndex2, (Array)pkgData, 0, 541);
- dictionary_0.Add(pkgID, pkgData);
- Console.WriteLine($" #{index}, hashed_pkey_target = {pkgID}");
- File.WriteAllBytes($"{file}_decrypted_id_{index}_pkg_{pkgID}.bin", pkgData);
- //tcopp_sanity_check(numArray);
- }
- if (getPackageCountFromRawBinary(internalData) == dictionary_0.Count)
- {
- Console.WriteLine("Count = PackageCount => Tudo bom, tudo legal");
- return;
- }
- Console.WriteLine("Count != PackageCount => invalid decrypted packages count!");
- return;
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Exception!\nInfo: {ex.ToString()}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment