From e64a600120c965069e95281bc6832f118ba0fd87 Mon Sep 17 00:00:00 2001 From: devseed Date: Fri, 5 Apr 2024 12:05:21 +0900 Subject: [PATCH] change some macro to function, add test for ci --- .github/workflows/build_wintools.yml | 48 ++++++++++++++++++-- .github/workflows/test_wintools.yml | 36 +++++++++++++++ project/windll_winhook/test_msvc.bat | 6 +++ project/windll_winpe/test_msvc.bat | 6 +++ src/winhook.h | 65 ++++++++++++++++++---------- 5 files changed, 136 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/test_wintools.yml create mode 100644 project/windll_winhook/test_msvc.bat create mode 100644 project/windll_winpe/test_msvc.bat diff --git a/.github/workflows/build_wintools.yml b/.github/workflows/build_wintools.yml index 09e256b..db2cad5 100644 --- a/.github/workflows/build_wintools.yml +++ b/.github/workflows/build_wintools.yml @@ -1,4 +1,4 @@ -name: build_tools +name: build_wintools on: push: {tags: ['v*'] } # Push events to matching v*, i.e. v1.0, v20.15.10 pull_request: @@ -7,8 +7,8 @@ permissions: contents: write jobs: - build_winexe_libwinhook: - runs-on: windows-2019 # default batch, powershell + build_winexe_winloader: + runs-on: windows-2019 steps: - name: pull and init uses: actions/checkout@v3 @@ -26,4 +26,46 @@ jobs: with: artifacts: "./project/winexe_winloader/build/winloader32.exe,./project/winexe_winloader/build/winloader64.exe" allowUpdates: "true" + token: ${{ secrets.GITHUB_TOKEN }} + + build_windll_winhook: + runs-on: windows-2019 + steps: + - name: pull and init + uses: actions/checkout@v3 + with: {submodules: true} + + - name: add msbuild to path + uses: microsoft/setup-msbuild@v1.1 + + - name: build winloader + run: .\project\windll_winhook\release_msvc.bat + + - name: create a release + uses: ncipollo/release-action@v1 + if: github.event_name == 'push' + with: + artifacts: "./project/windll_winhook/build/libwinhook32.dll,./project/windll_winhook/build/libwinhook64.dll" + allowUpdates: "true" + token: ${{ secrets.GITHUB_TOKEN }} + + build_windll_winpe: + runs-on: windows-2019 + steps: + - name: pull and init + uses: actions/checkout@v3 + with: {submodules: true} + + - name: add msbuild to path + uses: microsoft/setup-msbuild@v1.1 + + - name: build winloader + run: .\project\windll_winpe\release_msvc.bat + + - name: create a release + uses: ncipollo/release-action@v1 + if: github.event_name == 'push' + with: + artifacts: "./project/windll_winpe/build/libwinpe32.dll,./project/windll_winpe/build/libwinpe64.dll" + allowUpdates: "true" token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test_wintools.yml b/.github/workflows/test_wintools.yml new file mode 100644 index 0000000..2edde5f --- /dev/null +++ b/.github/workflows/test_wintools.yml @@ -0,0 +1,36 @@ +name: test_wintools +on: + push: {tags: ['v*'] } # Push events to matching v*, i.e. v1.0, v20.15.10 + pull_request: + +permissions: + contents: write + +jobs: + test_windll_winhook: + runs-on: windows-2019 + steps: + - name: pull and init + uses: actions/checkout@v3 + with: {submodules: true} + + - name: add msbuild to path + uses: microsoft/setup-msbuild@v1.1 + + - name: build winloader + shell: cmd + run: .\project\windll_winhook\test_msvc.bat + + test_windll_winpe: + runs-on: windows-2019 + steps: + - name: pull and init + uses: actions/checkout@v3 + with: {submodules: true} + + - name: add msbuild to path + uses: microsoft/setup-msbuild@v1.1 + + - name: build winloader + shell: cmd + run: .\project\windll_winpe\test_msvc.bat \ No newline at end of file diff --git a/project/windll_winhook/test_msvc.bat b/project/windll_winhook/test_msvc.bat new file mode 100644 index 0000000..081ee39 --- /dev/null +++ b/project/windll_winhook/test_msvc.bat @@ -0,0 +1,6 @@ +msbuild %~dp0\libwinhook.sln -t:libwinhook_test:rebuild -p:configuration=debug -p:Platform=x86 +msbuild %~dp0\libwinhook.sln -t:libwinhook_test:rebuild -p:configuration=debug -p:Platform=x64 +pushd %~dp0\build +libwinhook_test32d +libwinhook_test64d +popd \ No newline at end of file diff --git a/project/windll_winpe/test_msvc.bat b/project/windll_winpe/test_msvc.bat new file mode 100644 index 0000000..e7766f2 --- /dev/null +++ b/project/windll_winpe/test_msvc.bat @@ -0,0 +1,6 @@ +msbuild %~dp0\libwinpe.sln -t:libwinpe_test:rebuild -p:configuration=debug -p:Platform=x86 +msbuild %~dp0\libwinpe.sln -t:libwinpe_test:rebuild -p:configuration=debug -p:Platform=x64 +pushd %~dp0\build +libwinpe_test32d +libwinpe_test64d +popd \ No newline at end of file diff --git a/src/winhook.h b/src/winhook.h index e05ca54..c1b9210 100644 --- a/src/winhook.h +++ b/src/winhook.h @@ -97,10 +97,12 @@ DWORD winhook_startexeinject(LPCSTR exepath, LPSTR cmdstr, LPCSTR dllpath); * start a exe by CreateProcess * @return pid */ -#define winhook_startexe(exepath, cmdstr)\ - winhook_startexeinject(exepath, cmdstr, NULL) - - +WINHOOK_API +DWORD winhook_startexe(LPCSTR exepath, LPSTR cmdstr) +{ + return winhook_startexeinject(exepath, cmdstr, NULL); +} + /** * get the process handle by exename */ @@ -131,9 +133,12 @@ void winhook_installconsole(); WINHOOK_API BOOL winhook_patchmemoryex(HANDLE hprocess,LPVOID addr, const void* buf, size_t bufsize); -#define winhook_patchmemory(addr, buf, bufsize)\ - winhook_patchmemoryex(GetCurrentProcess(), addr, buf, bufsize) - +WINHOOK_API +BOOL winhook_patchmemory(LPVOID addr, const void* buf, size_t bufsize) +{ + return winhook_patchmemoryex(GetCurrentProcess(), addr, buf, bufsize); +} + /** * batch patch memories */ @@ -141,8 +146,12 @@ WINHOOK_API BOOL winhook_patchmemorysex(HANDLE hprocess, LPVOID addrs[], void* bufs[], size_t bufsizes[], int n); -#define winhook_patchmemorys(addrs, bufs, bufsizes, n)\ - winhook_patchmemorysex(GetCurrentProcess(), addrs, bufs, bufsizes, n) +WINHOOK_API +BOOL winhook_patchmemorys(LPVOID addrs[], void* bufs[], size_t bufsizes[], int n) +{ + return winhook_patchmemorysex(GetCurrentProcess(), addrs, bufs, bufsizes, n); +} + /** * patch memory with pattern, @@ -164,9 +173,12 @@ WINHOOK_API int winhook_patchmemory1337ex(HANDLE hprocess, const char* pattern, size_t base, BOOL revert); -#define winhook_patchmemory1337(pattern, base, revert) \ - winhook_patchmemory1337ex(GetCurrentProcess(), pattern, base, revert) - +WINHOOK_API +int winhook_patchmemory1337(const char* pattern, size_t base, BOOL revert) +{ + return winhook_patchmemory1337ex(GetCurrentProcess(), pattern, base, revert); +} + /** * patch memory with pattern ips(International Patching System) * specifications at https://zerosoft.zophar.net/ips.php @@ -175,9 +187,12 @@ int winhook_patchmemory1337ex(HANDLE hprocess, WINHOOK_API int winhook_patchmemoryipsex(HANDLE hprocess, const char* pattern, size_t base); -#define winhook_patchmemoryips(pattern, base) \ - winhook_patchmemoryipsex(GetCurrentProcess(), pattern, base) - +WINHOOK_API +int winhook_patchmemoryips(const char* pattern, size_t base) +{ + return winhook_patchmemoryipsex(GetCurrentProcess(), pattern, base); +} + /** * search the pattern like "ab 12 ?? 34" * @return the matched address @@ -197,17 +212,23 @@ void* winhook_searchmemoryex(HANDLE hprocess, WINHOOK_API BOOL winhook_iathookpe(LPCSTR targetDllName, void* mempe, PROC pfnOrg, PROC pfnNew); -#define winhook_iathookmodule(targetDllName, moduleDllName, pfnOrg, pfnNew)\ - winhook_iathookpe(targetDllName, GetModuleHandle(moduleDllName), pfnOrg, pfnNew) - +WINHOOK_API +BOOL winhook_iathookmodule(LPCSTR targetDllName, LPCSTR moduleDllName, PROC pfnOrg, PROC pfnNew) +{ + return winhook_iathookpe(targetDllName, GetModuleHandle(moduleDllName), pfnOrg, pfnNew); +} + /** * iat dynamiclly hook, * replace the @param pfgNew with @param pfnOrg function * @param targetDllName like "user32.dll", "kernel32.dll" */ -#define winhook_iathook(targetDllName, pfnOrg, pfgNew)\ - winhook_iathookmodule(targetDllName, NULL, pfnOrg, pfgNew) - +WINHOOK_API +BOOL winhook_iathook(LPCSTR targetDllName, PROC pfnOrg, PROC pfgNew) +{ + return winhook_iathookmodule(targetDllName, NULL, pfnOrg, pfgNew); +} + /** * inline hooks wrapper, * @param pfnTargets -> @param pfnNews, save origin pointers in @param pfnOlds @@ -754,5 +775,5 @@ int winhook_inlineunhooks(PVOID pfnTargets[], PVOID pfnNews[], PVOID pfnOlds[], * v0.2.7, add win_startexeinject, fix winhook_searchmemoryex match bug * v0.3, use javadoc style, add winhook_patchmemorypattern * v0.3.1, add winhook_patchmemory1337, winhook_patchmemoryips - * v0.3.2, improve macro style + * v0.3.2, improve macro style, chaneg some of macro to function */ \ No newline at end of file