Skip to content

Commit

Permalink
change some macro to function, add test for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizuku committed Apr 5, 2024
1 parent 96850de commit 15347ca
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 31 deletions.
52 changes: 47 additions & 5 deletions .github/workflows/build_wintools.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -17,13 +17,55 @@ jobs:
- name: add msbuild to path
uses: microsoft/[email protected]

- name: build winloader
- name: build target
run: .\project\winexe_winloader\release_msvc.bat

- name: create a release
- name: upload release
uses: ncipollo/release-action@v1
if: github.event_name == 'push'
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/[email protected]

- name: build target
run: .\project\windll_winhook\release_msvc.bat

- name: upload 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/[email protected]

- name: build target
run: .\project\windll_winpe\release_msvc.bat

- name: upload 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 }}
36 changes: 36 additions & 0 deletions .github/workflows/test_wintools.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- name: test target
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/[email protected]

- name: test target
shell: cmd
run: .\project\windll_winpe\test_msvc.bat
6 changes: 6 additions & 0 deletions project/windll_winhook/test_msvc.bat
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions project/windll_winpe/libwinpe_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
</ClCompile>
Expand All @@ -112,7 +112,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
</ClCompile>
Expand All @@ -127,7 +127,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
</ClCompile>
Expand All @@ -142,7 +142,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../src</AdditionalIncludeDirectories>
</ClCompile>
Expand Down
6 changes: 6 additions & 0 deletions project/windll_winpe/test_msvc.bat
Original file line number Diff line number Diff line change
@@ -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
65 changes: 43 additions & 22 deletions src/winhook.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -131,18 +133,25 @@ 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
*/
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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
*/

0 comments on commit 15347ca

Please sign in to comment.