From 4799b4bf250ea143c47908078194d72d975165b0 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Sat, 13 Jul 2024 22:05:00 +0700 Subject: [PATCH] Build: Updated build scripts and tools to build the ARM64 setup --- .github/workflows/build.yml | 62 +++++++++++------ ExplorerPatcher/def.h | 4 ++ .../ep_generate_release_description.c | 10 ++- ep_setup_patch/ep_setup_patch.c | 68 ++++++------------- 4 files changed, 76 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 79548a8b8..0a34cbbeb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -123,15 +123,15 @@ jobs: (gc .\funchook-static.vcxproj) -replace 'MultiThreadedDLL', 'MultiThreaded' | Out-File .\funchook-static.vcxproj cmake --build . --config Release - # - name: Build funchook arm64 - # shell: powershell - # run: | - # cd libs/funchook - # md build-arm64 - # cd build-arm64 - # cmake -G "Visual Studio 17 2022" -A ARM64 -DFUNCHOOK_CPU=arm64 -DFUNCHOOK_DISASM=capstone -DFUNCHOOK_BUILD_TESTS=OFF .. - # (gc .\funchook-static.vcxproj) -replace 'MultiThreadedDLL', 'MultiThreaded' | Out-File .\funchook-static.vcxproj - # cmake --build . --config Release + - name: Build funchook arm64 + shell: powershell + run: | + cd libs/funchook + md build-arm64 + cd build-arm64 + cmake -G "Visual Studio 17 2022" -A ARM64 -DFUNCHOOK_CPU=arm64 -DFUNCHOOK_DISASM=capstone -DFUNCHOOK_BUILD_TESTS=OFF .. + (gc .\funchook-static.vcxproj) -replace 'MultiThreadedDLL', 'MultiThreaded' | Out-File .\funchook-static.vcxproj + cmake --build . --config Release - name: Build EP IA-32 if: github.event.inputs.config == '' @@ -145,11 +145,11 @@ jobs: run: | msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=amd64 ${{env.SOLUTION_FILE_PATH}} - # - name: Build EP arm64 - # if: github.event.inputs.config == '' - # working-directory: ${{env.GITHUB_WORKSPACE}} - # run: | - # msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=arm64 ${{env.SOLUTION_FILE_PATH}} + - name: Build EP arm64 + if: github.event.inputs.config == '' + working-directory: ${{env.GITHUB_WORKSPACE}} + run: | + msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=arm64 /p:WithArm64XBinaries=true ${{env.SOLUTION_FILE_PATH}} - name: Build EP custom if: github.event.inputs.config != '' @@ -170,11 +170,20 @@ jobs: if [[ -f "build/Release/x64/ExplorerPatcher.amd64.dll" ]]; then cp build/Release/x64/ExplorerPatcher.amd64.dll build/Release/x64/dxgi.dll; fi if [[ -f "build/Release/ARM64/ExplorerPatcher.arm64.dll" ]]; then cp build/Release/ARM64/ExplorerPatcher.arm64.dll build/Release/ARM64/dxgi.dll; fi - - name: Patch setup + - name: Patch amd64 setup shell: cmd - working-directory: build/Release/x64 run: | - ep_setup_patch.exe + if exist "build\Release\x64\ExplorerPatcher.amd64.dll" ( + "build\Release\x64\ep_setup_patch.exe" "build\Release\x64\ExplorerPatcher.amd64.dll" "build\Release\x64\ep_setup.exe" + ) + exit /b 0 + + - name: Patch arm64 setup + shell: cmd + run: | + if exist "build\Release\ARM64\ExplorerPatcher.arm64.dll" ( + "build\Release\x64\ep_setup_patch.exe" "build\Release\ARM64\ExplorerPatcher.arm64.dll" "build\Release\ARM64\ep_setup.exe" + ) exit /b 0 - name: Upload artifacts @@ -184,6 +193,19 @@ jobs: path: | build/Release/ + # build/Release/x64/ep_setup.exe -> build/Release/ep_setup.exe + # build/Release/ARM64/ep_setup.exe -> build/Release/ep_setup.arm64.exe + - name: Stage files for release + if: github.ref == 'refs/heads/master' && github.event.inputs.ref == '' + shell: bash + run: | + if [ -d "build/Release/x64" ] && ls build/Release/x64/ep_setup.exe 1> /dev/null 2>&1; then + cp build/Release/x64/ep_setup.exe build/Release/ep_setup.exe + fi + if [ -d "build/Release/ARM64" ] && ls build/Release/ARM64/ep_setup.exe 1> /dev/null 2>&1; then + cp build/Release/ARM64/ep_setup.exe build/Release/ep_setup.arm64.exe + fi + - name: Generate release name shell: bash working-directory: build/Release/x64 @@ -213,7 +235,8 @@ jobs: tag_name: ${{ steps.release_name.outputs.data }}_${{ steps.vars.outputs.sha_short }} body: ${{ steps.release_description.outputs.data }} files: | - build/Release/x64/ep_setup.exe + build/Release/ep_setup.exe + build/Release/ep_setup.arm64.exe env: GITHUB_TOKEN: ${{ secrets.PAT }} @@ -228,6 +251,7 @@ jobs: tag_name: ${{ steps.release_name.outputs.data }}_${{ steps.vars.outputs.sha_short }} body: ${{ steps.release_description.outputs.data }} files: | - build/Release/x64/ep_setup.exe + build/Release/ep_setup.exe + build/Release/ep_setup.arm64.exe env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/ExplorerPatcher/def.h b/ExplorerPatcher/def.h index ba61dc290..ea2761897 100644 --- a/ExplorerPatcher/def.h +++ b/ExplorerPatcher/def.h @@ -12,7 +12,11 @@ #define EP_CLSID_LITE "D17F1E1A-5919-4427-8F89-A1A8503CA3EB" #define EP_CLSID "{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}" #define DOSMODE_OFFSET 78 +#ifndef _M_ARM64 #define SETUP_UTILITY_NAME "ep_setup.exe" +#else +#define SETUP_UTILITY_NAME "ep_setup.arm64.exe" +#endif #define TOAST_BUFSIZ 1024 #define SEH_REGPATH "Control Panel\\Quick Actions\\Control Center\\QuickActionsStateCapture\\ExplorerPatcher" #define EP_SETUP_HELPER_SWITCH "/CreateExplorerShellUnelevatedAfterServicing" diff --git a/ep_generate_release_description/ep_generate_release_description.c b/ep_generate_release_description/ep_generate_release_description.c index 2a6f9c67a..d8d637c1f 100644 --- a/ep_generate_release_description/ep_generate_release_description.c +++ b/ep_generate_release_description/ep_generate_release_description.c @@ -22,13 +22,17 @@ int main(int argc, char** argv) sprintf_s(szEndPattern, MAX_PATH, "## "); FILE* f = NULL; - fopen_s(&f, "..\\..\\" FILE_NAME, "r"); + fopen_s(&f, "..\\..\\..\\" FILE_NAME, "r"); if (!f) { - fopen_s(&f, "..\\" FILE_NAME, "r"); + fopen_s(&f, "..\\..\\" FILE_NAME, "r"); if (!f) { - fopen_s(&f, "" FILE_NAME, "r"); + fopen_s(&f, "..\\" FILE_NAME, "r"); + if (!f) + { + fopen_s(&f, "" FILE_NAME, "r"); + } } } if (f) diff --git a/ep_setup_patch/ep_setup_patch.c b/ep_setup_patch/ep_setup_patch.c index dbe2ba49a..afbbc70d8 100644 --- a/ep_setup_patch/ep_setup_patch.c +++ b/ep_setup_patch/ep_setup_patch.c @@ -10,49 +10,47 @@ int WINAPI wWinMain( _In_ int nShowCmd ) { - WCHAR wszPath[MAX_PATH]; - GetModuleFileNameW(GetModuleHandle(NULL), wszPath, MAX_PATH); - PathRemoveFileSpecW(wszPath); - wcscat_s(wszPath, MAX_PATH, L"\\" _T(PRODUCT_NAME) L".amd64.dll"); - HMODULE hModule = LoadLibraryExW(wszPath, NULL, LOAD_LIBRARY_AS_DATAFILE); - - CHAR hash[100]; - ZeroMemory(hash, 100); - if (__argc > 1) + if (__argc < 3) { - for (size_t i = 0; i < MIN(wcslen(__wargv[1]), 32); ++i) - { - hash[i] = __wargv[1][i]; - } + return __LINE__; } - else + + WCHAR wszMainModulePath[MAX_PATH]; + WCHAR wszSetupPath[MAX_PATH]; + wcscpy_s(wszMainModulePath, MAX_PATH, __wargv[1]); + wcscpy_s(wszSetupPath, MAX_PATH, __wargv[2]); + + HMODULE hModule = LoadLibraryExW(wszMainModulePath, NULL, LOAD_LIBRARY_AS_DATAFILE); + if (hModule == NULL) { - ComputeFileHash2(hModule, wszPath, hash, 100); - FreeLibrary(hModule); + return __LINE__; } - PathRemoveFileSpecW(wszPath); - wcscat_s(wszPath, MAX_PATH, L"\\" _T(SETUP_UTILITY_NAME)); + CHAR hash[100]; + ZeroMemory(hash, 100); + ComputeFileHash2(hModule, wszMainModulePath, hash, 100); + + FreeLibrary(hModule); - HANDLE hFile = CreateFileW(wszPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE hFile = CreateFileW(wszSetupPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { - return 1; + return __LINE__; } HANDLE hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); - if (hFileMapping == 0) + if (!hFileMapping) { CloseHandle(hFile); - return 2; + return __LINE__; } char* lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0); - if (lpFileBase == 0) + if (!lpFileBase) { CloseHandle(hFileMapping); CloseHandle(hFile); - return 3; + return __LINE__; } memcpy(lpFileBase + DOSMODE_OFFSET, hash, strlen(hash)); @@ -61,27 +59,5 @@ int WINAPI wWinMain( CloseHandle(hFileMapping); CloseHandle(hFile); - if (__argc > 1) - { - SHELLEXECUTEINFO ShExecInfo = { 0 }; - ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); - ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; - ShExecInfo.hwnd = NULL; - ShExecInfo.lpVerb = L"runas"; - ShExecInfo.lpFile = wszPath; - ShExecInfo.lpParameters = NULL; - ShExecInfo.lpDirectory = NULL; - ShExecInfo.nShow = SW_SHOW; - ShExecInfo.hInstApp = NULL; - if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) - { - WaitForSingleObject(ShExecInfo.hProcess, INFINITE); - DWORD dwExitCode = 0; - GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); - CloseHandle(ShExecInfo.hProcess); - return dwExitCode; - } - } - return 0; } \ No newline at end of file