Skip to content

Commit

Permalink
remove winhook_inlinehook interface
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizuku committed Oct 16, 2024
1 parent 517fb6b commit b980d4b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 44 deletions.
1 change: 0 additions & 1 deletion project/windll_winhook/src/libwinhook.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#define WINHOOK_IMPLEMENTATION
#define WINHOOK_SHARED
#define WINHOOK_USEDYNBIND
#define WINHOOK_NO3RDLIB
#include "winhook.h"
1 change: 0 additions & 1 deletion project/windll_winhook/src/libwinhook_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define WINHOOK_IMPLEMENTATION
#define WINHOOK_USESHELLCODE
#endif
#define WINHOOK_NO3RDLIB
#include "winhook.h"

void test_patchpattern()
Expand Down
1 change: 0 additions & 1 deletion project/winexe_winloader/src/winloader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <windows.h>
#define WINHOOK_IMPLEMENTATION
#define WINHOOK_NO3RDLIB
#include "winhook.h"

#ifndef _DEBUG
Expand Down
6 changes: 6 additions & 0 deletions src/commdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#ifndef INLINE
#define INLINE __forceinline
#endif
#ifndef NOINLINE
#define NOINLINE __declspec(noinline)
#endif
#ifndef EXPORT
#define EXPORT __declspec(dllexport)
#endif
Expand All @@ -33,6 +36,9 @@
#ifndef INLINE
#define INLINE __attribute__((always_inline)) inline
#endif
#ifndef NOINLINE
#define NOINLINE __attribute__((noinline))
#endif
#ifndef EXPORT
#define EXPORT __attribute__((visibility("default")))
#endif
Expand Down
42 changes: 1 addition & 41 deletions src/winhook.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* WINHOOK_SHARED, make function export
* WINHOOK_STATIC, make function static
* WINHOOK_NOINLINE, don't use inline function
* WINHOOK_NO3RDLIB, don't use 3rd lib for inlinehook
* WINHOOK_USEDYNBIND, use dynamic binding for winapi api
*/

Expand Down Expand Up @@ -689,45 +688,6 @@ BOOL winhook_iathookpe(LPCSTR targetDllName, void* mempe, PROC pfnOrg, PROC pfnN
return FALSE;
}

#ifndef WINHOOK_NO3RDLIB
#ifndef MINHOOK_IMPLEMENTATION
#define MINHOOK_IMPLEMENTATION
#define MINHOOK_STATIC
#endif // MINHOOK_IMPLEMENTATION
#ifdef USECOMPAT
#include "stb_minhook_v1331.h"
#else
#include "stb_minhook.h"
#endif

int winhook_inlinehooks(PVOID pfnTargets[], PVOID pfnNews[], PVOID pfnOlds[], int n)
{
int i;
MH_Initialize();
for(i=0; i<n ;i++)
{
MH_STATUS status;
if(!pfnNews[i] || !pfnTargets[i]) continue;
status = MH_CreateHook(pfnTargets[i], pfnNews[i], &pfnOlds[i]);
if(status!= MH_OK) return i;
status = MH_EnableHook(pfnTargets[i]);
if(status!= MH_OK) return i;
}
return i;
}

int winhook_inlineunhooks(PVOID pfnTargets[], PVOID pfnNews[], PVOID pfnOlds[], int n)
{
int i;
for(i=0; i<n ;i++)
{
if(!pfnNews[i] || !pfnTargets[i]) continue;
MH_DisableHook(pfnTargets[i]);
}
if(MH_Uninitialize() != MH_OK) return 0;
return i;
}
#endif // WINHOOK_NO3RDLIB
#endif // MINHOOK_IMPLEMENTATION

#ifdef __cplusplus
Expand All @@ -749,5 +709,5 @@ int winhook_inlineunhooks(PVOID pfnTargets[], PVOID pfnNews[], PVOID pfnOlds[],
* v0.3, use javadoc style, add winhook_patchmemorypattern
* v0.3.1, add winhook_patchmemory1337, winhook_patchmemoryips
* v0.3.2, improve macro style, chaneg some of macro to function
* v0.3.3, seperate some macro to commdef
* v0.3.3, seperate some macro to commdef, remove winhook_inlinehook, use stb_minhook directly
*/

0 comments on commit b980d4b

Please sign in to comment.