From 143f0823f9dc303ff583779dbff35714fbbf8ea0 Mon Sep 17 00:00:00 2001 From: hfiref0x Date: Sun, 15 May 2022 13:13:59 +0700 Subject: [PATCH] 1.9.3 GenAsIo2Unlock util --- .../Utils/GenAsIo2Unlock/GenAsIo2Unlock.sln | 25 ++ .../GenAsIo2Unlock/GenAsIo2Unlock.vcxproj | 102 ++++++ .../GenAsIo2Unlock.vcxproj.filters | 36 ++ .../GenAsIo2Unlock.vcxproj.user | 7 + Source/Utils/GenAsIo2Unlock/main.cpp | 326 ++++++++++++++++++ WinObjEx64.sha256 | 5 + 6 files changed, 501 insertions(+) create mode 100644 Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.sln create mode 100644 Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj create mode 100644 Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.filters create mode 100644 Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.user create mode 100644 Source/Utils/GenAsIo2Unlock/main.cpp diff --git a/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.sln b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.sln new file mode 100644 index 0000000..35660a8 --- /dev/null +++ b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31025.218 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GenAsIo2Unlock", "GenAsIo2Unlock.vcxproj", "{19A7EF82-4431-4167-AAC9-57FA29B1AE21}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {19A7EF82-4431-4167-AAC9-57FA29B1AE21}.Debug|x64.ActiveCfg = Debug|x64 + {19A7EF82-4431-4167-AAC9-57FA29B1AE21}.Debug|x64.Build.0 = Debug|x64 + {19A7EF82-4431-4167-AAC9-57FA29B1AE21}.Release|x64.ActiveCfg = Release|x64 + {19A7EF82-4431-4167-AAC9-57FA29B1AE21}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {61964766-0C22-42CC-8170-469C28F6C2D8} + EndGlobalSection +EndGlobal diff --git a/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj new file mode 100644 index 0000000..3d34a26 --- /dev/null +++ b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj @@ -0,0 +1,102 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {19a7ef82-4431-4167-aac9-57fa29b1ae21} + GenAsusUnlock + 10.0 + GenAsIo2Unlock + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + true + .\output\$(Platform)\$(Configuration)\ + .\output\$(Platform)\$(Configuration)\ + + + false + .\output\$(Platform)\$(Configuration)\ + .\output\$(Platform)\$(Configuration)\ + true + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level4 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + Guard + + + Console + true + true + false + /NOCOFFGRPINFO %(AdditionalOptions) + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.filters b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.filters new file mode 100644 index 0000000..04a1ac7 --- /dev/null +++ b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {df6b50ba-6a92-4149-873b-67cf23736ddf} + + + + + Source Files + + + minirtl + + + + + Header Files + + + minirtl + + + \ No newline at end of file diff --git a/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.user b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.user new file mode 100644 index 0000000..6e0df35 --- /dev/null +++ b/Source/Utils/GenAsIo2Unlock/GenAsIo2Unlock.vcxproj.user @@ -0,0 +1,7 @@ + + + + c:\makeexe\kdu\kdu.exe + WindowsLocalDebugger + + \ No newline at end of file diff --git a/Source/Utils/GenAsIo2Unlock/main.cpp b/Source/Utils/GenAsIo2Unlock/main.cpp new file mode 100644 index 0000000..39f2d13 --- /dev/null +++ b/Source/Utils/GenAsIo2Unlock/main.cpp @@ -0,0 +1,326 @@ +/******************************************************************************* +* +* (C) COPYRIGHT AUTHORS, 2020 - 2021 +* +* TITLE: MAIN.CPP +* +* VERSION: 1.00 +* +* DATE: 18 Apr 2021 +* +* AsIo2 "unlock" resource generator and binder. +* +* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED +* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +* PARTICULAR PURPOSE. +* +*******************************************************************************/ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#include "../../Shared/ntos/ntos.h" +#include "../../Shared/minirtl/cmdline.h" +} +#endif + +/* +* supChkSum +* +* Purpose: +* +* Calculate partial checksum for given buffer. +* +*/ +USHORT supChkSum( + ULONG PartialSum, + PUSHORT Source, + ULONG Length +) +{ + while (Length--) { + PartialSum += *Source++; + PartialSum = (PartialSum >> 16) + (PartialSum & 0xffff); + } + return (USHORT)(((PartialSum >> 16) + PartialSum) & 0xffff); +} + +/* +* supCalculateCheckSumForMappedFile +* +* Purpose: +* +* Calculate PE file checksum. +* +*/ +DWORD supCalculateCheckSumForMappedFile( + _In_ PVOID BaseAddress, + _In_ ULONG FileLength +) +{ + PUSHORT AdjustSum; + PIMAGE_NT_HEADERS NtHeaders; + USHORT PartialSum; + ULONG CheckSum; + + PartialSum = supChkSum(0, (PUSHORT)BaseAddress, (FileLength + 1) >> 1); + + NtHeaders = RtlImageNtHeader(BaseAddress); + if (NtHeaders != NULL) { + AdjustSum = (PUSHORT)(&NtHeaders->OptionalHeader.CheckSum); + PartialSum -= (PartialSum < AdjustSum[0]); + PartialSum -= AdjustSum[0]; + PartialSum -= (PartialSum < AdjustSum[1]); + PartialSum -= AdjustSum[1]; + } + else + { + PartialSum = 0; + } + CheckSum = (ULONG)PartialSum + FileLength; + return CheckSum; +} + +BOOL UpdateChecksum( + _In_ LPCSTR lpFileName +) +{ + BOOL bResult = FALSE; + HANDLE hFile = INVALID_HANDLE_VALUE; + HANDLE hFileMap = NULL; + DWORD FileSize; + LPVOID ImageBase = NULL; + + PIMAGE_OPTIONAL_HEADER32 oh32 = NULL; + PIMAGE_OPTIONAL_HEADER64 oh64 = NULL; + + ULONG NewCheckSum; + + IMAGE_NT_HEADERS* NtHeaders = NULL; + + __try { + + hFile = CreateFileA(lpFileName, GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hFile == INVALID_HANDLE_VALUE) { + printf_s("[G] Cannot open input file\n"); + __leave; + } + + FileSize = GetFileSize(hFile, NULL); + if (FileSize == 0) { + printf_s("[G] Input file is empty\n"); + __leave; + } + + hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); + if (hFileMap == NULL) { + printf_s("[G] CreateFileMapping failed for input file\n"); + __leave; + } + + ImageBase = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0); + if (ImageBase == NULL) { + printf_s("[G] MapViewOfFile failed for input file\n"); + __leave; + } + + NtHeaders = RtlImageNtHeader(ImageBase); + if (NtHeaders == NULL) { + printf_s("[G] RtlImageNtHeader failed for input file\n"); + __leave; + } + + oh32 = (PIMAGE_OPTIONAL_HEADER32)&NtHeaders->OptionalHeader; + oh64 = (PIMAGE_OPTIONAL_HEADER64)oh32; + + if ((NtHeaders->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64) && (NtHeaders->FileHeader.Machine != IMAGE_FILE_MACHINE_I386)) { + printf_s("[G] Unsuported FileHeader.Machine value\n"); + __leave; + } + + NewCheckSum = supCalculateCheckSumForMappedFile(ImageBase, FileSize); + if (NtHeaders->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64) { + oh64->CheckSum = NewCheckSum; + } + else { + oh32->CheckSum = NewCheckSum; + } + + bResult = TRUE; + + } + __finally { + if (ImageBase) { + FlushViewOfFile(ImageBase, 0); + UnmapViewOfFile(ImageBase); + } + + if (hFileMap) + CloseHandle(hFileMap); + + if (hFile != INVALID_HANDLE_VALUE) + CloseHandle(hFile); + } + + return bResult; +} + + +VOID ProcessFile( + _In_ LPCSTR lpFileName) +{ + BOOL bUpdated = FALSE, bInit; + ULONG seconds = 0, dwError; + LARGE_INTEGER fileTime; + + BYTE Buffer[16]; + DWORD aKey[4] = { 0x16157EAA, 0xA6D2AE28, 0x8815F7AB, 0x3C4FCF09 }; + + HCRYPTPROV hProv; + HCRYPTKEY hKey = NULL; + DWORD bytesIO = 0; + DWORD dwMode; + + struct { + BLOBHEADER hdr; + DWORD len; + BYTE key[16]; + } KeyBlob; + + GetSystemTimeAsFileTime((PFILETIME)&fileTime); + RtlTimeToSecondsSince1970(&fileTime, &seconds); + + RtlSecureZeroMemory(Buffer, sizeof(Buffer)); + + RtlCopyMemory(Buffer, &seconds, sizeof(DWORD)); + + do { + + bInit = CryptAcquireContext(&hProv, + NULL, + MS_ENH_RSA_AES_PROV, + PROV_RSA_AES, + CRYPT_SILENT); + + if (!bInit) + { + if (GetLastError() == NTE_BAD_KEYSET) { + + bInit = CryptAcquireContext(&hProv, + NULL, + MS_ENH_RSA_AES_PROV, + PROV_RSA_AES, + CRYPT_NEWKEYSET); + } + + } + + if (bInit == FALSE) { + printf_s("[G] Failed to acquire context for Crypto API, error %lX\n", GetLastError()); + break; + } + + printf_s("[G] CryptoAPI context acquired\n"); + + KeyBlob.hdr.bType = PLAINTEXTKEYBLOB; + KeyBlob.hdr.bVersion = CUR_BLOB_VERSION; + KeyBlob.hdr.reserved = 0; + KeyBlob.hdr.aiKeyAlg = CALG_AES_128; + KeyBlob.len = sizeof(aKey); + RtlCopyMemory(KeyBlob.key, aKey, sizeof(aKey)); + + if (!CryptImportKey(hProv, (BYTE*)&KeyBlob, sizeof(KeyBlob), NULL, 0, &hKey)) { + printf_s("[G] Failed to import key, error %lX\n", GetLastError()); + break; + } + else { + printf_s("[G] AES key imported successfully\n"); + } + + dwMode = CRYPT_MODE_ECB; + + if (!CryptSetKeyParam(hKey, KP_MODE, (BYTE*)&dwMode, 0)) { + printf_s("[G] Failed to set key param, error %lX\n", GetLastError()); + break; + } + else { + printf_s("[G] AES ECB mode set\n"); + } + + bytesIO = sizeof(Buffer); + + if (!CryptEncrypt(hKey, NULL, FALSE, 0, (BYTE*)Buffer, &bytesIO, bytesIO)) { + printf_s("[G] Failed to encrypt data, error %lX\n", GetLastError()); + break; + } + else { + printf_s("[G] Data for driver unlocking encrypted successfully\n"); + } + + } while (FALSE); + + if (hKey) CryptDestroyKey(hKey); + CryptReleaseContext(hProv, 0); + + printf_s("[G] Generating AsIo2 unlock resource\n"); + + HANDLE hRes = BeginUpdateResourceA(lpFileName, FALSE); + if (hRes) { + + if (!UpdateResourceA(hRes, + (LPCSTR)RT_RCDATA, + "ASUSCERT", + MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), + Buffer, + sizeof(Buffer))) + { + dwError = GetLastError(); + printf_s("[G] Could not update resources, GetLastError %lu\n", dwError); + } + else { + printf_s("[G] File resources updated\n"); + } + + bUpdated = EndUpdateResource(hRes, FALSE); + + } + else { + dwError = GetLastError(); + printf_s("[G] Could not open %s, GetLastError %lu\n", lpFileName, dwError); + } + + if (bUpdated) { + + printf_s("[G] Updating file checksum\n"); + + if (UpdateChecksum(lpFileName)) { + printf_s("[G] Checksum updated\n"); + } + else { + printf_s("[G] Could not update checksum!\n"); + } + } +} + +int main() +{ + ULONG l; + CHAR szFileName[MAX_PATH + 1]; + + l = 0; + RtlSecureZeroMemory(szFileName, sizeof(szFileName)); + GetCommandLineParamA(GetCommandLineA(), 1, szFileName, MAX_PATH, &l); + if (l > 0) { + printf_s("GenAsIo2Unlock v1.0 built at %s\n[G] Processing input file %s\n", __TIMESTAMP__, szFileName); + ProcessFile(szFileName); + } + else { + printf_s("[G] Input file not specified\n"); + } + return 0; +} diff --git a/WinObjEx64.sha256 b/WinObjEx64.sha256 index 56cf8bd..13096a2 100644 --- a/WinObjEx64.sha256 +++ b/WinObjEx64.sha256 @@ -134,6 +134,11 @@ b46c40109223624940a76c65db6ec26cf21f6d4886e81dedc09c1a48f223822e *Source\Shared\ fe9f3b5ce134b8d292a6a82df44ce0a201cfb2c029ac131f54564e3ac80b7172 *Source\Shared\tabs\tabsctrl.h ce2ec00fd84aa5db7c67e1c95f503657804ffa6b3fb6a8fffe95de99476c6a18 *Source\Shared\treelist\treelist.c 33aac331f85b82bb59f46a81c085eabc26cbb62997a331b65cbb944f02dd96fa *Source\Shared\treelist\treelist.h +c776bc97ee2fbe48d3e148bb37c887862e6de212d4391d6df9b5f149e40ed223 *Source\Utils\GenAsIo2Unlock\GenAsIo2Unlock.sln +c4a28bc43a63a40ff2d8699fa261ee1ced6783d199043484ea7921e8d078ea08 *Source\Utils\GenAsIo2Unlock\GenAsIo2Unlock.vcxproj +0f66125c8a4beed047c8bfb2eb57f8aa8ce3acc390b9303b4b2d10815e8d4b9c *Source\Utils\GenAsIo2Unlock\GenAsIo2Unlock.vcxproj.filters +97ce741fbe96ea77dbb626f6021405ec9b204ad8591db4b69f8fde8aae628a1a *Source\Utils\GenAsIo2Unlock\GenAsIo2Unlock.vcxproj.user +351d5566119c9d193cff59c4ae70124b68b23c0602f7eba3e73772f42009844e *Source\Utils\GenAsIo2Unlock\main.cpp 70a3b8284ab598ffcabd5c4d794be7445847f1711db63503c64d1cbdde4791e7 *Source\WinObjEx64\aboutDlg.c e2877173023bae50e74772f142fec35cb72e30ea963dd90b39f382339a8a5b24 *Source\WinObjEx64\aboutDlg.h 9e54675313dfcf120d83549865688882d6a6fd85f029c797d4be4eed9e3a58b7 *Source\WinObjEx64\driver.rc