Apply clang-format code style to all source files

This commit is contained in:
icex2
2019-10-20 00:50:40 +02:00
parent c600e1a423
commit c3bc8782f4
401 changed files with 13844 additions and 11361 deletions
+48 -20
View File
@@ -1,5 +1,5 @@
#include <windows.h>
#include <unknwn.h>
#include <windows.h>
#include <stdlib.h>
@@ -10,52 +10,78 @@
#ifdef _WIN64
/***** 64-BIT TRAMPOLINE *****/
/***** 64-BIT TRAMPOLINE *****/
#define SLOT_OFFSET 0x0A
static const uint8_t com_proxy_tramp[] = {
/* mov rcx, [rcx+8] ; Replace this with this->real */
0x48, 0x8B, 0x49, 0x08,
0x48,
0x8B,
0x49,
0x08,
/* mov rax, [rcx] ; Get real->vtbl */
0x48, 0x8B, 0x01,
0x48,
0x8B,
0x01,
/* mov rax, [rax+XX] ; Get vtbl->slot_XX */
0x48, 0x8B, 0x80, -1, -1, -1, -1,
0x48,
0x8B,
0x80,
-1,
-1,
-1,
-1,
/* jmp rax ; Continue to slot_XX */
0xFF, 0xE0,
0xFF,
0xE0,
};
#else
/***** 32-BIT TRAMPOLINE *****/
/***** 32-BIT TRAMPOLINE *****/
#define SLOT_OFFSET 0x0F
static const uint8_t com_proxy_tramp[] = {
/* mov eax, [esp+4] ; Get this */
0x8B, 0x44, 0x24, 0x04,
0x8B,
0x44,
0x24,
0x04,
/* mov eax, [eax+4] ; Get this->real */
0x8B, 0x40, 0x04,
0x8B,
0x40,
0x04,
/* mov [esp+4], eax ; Replace this with this->real on stack */
0x89, 0x44, 0x24, 0x04,
0x89,
0x44,
0x24,
0x04,
/* mov ecx, [eax] ; Get real->vtbl */
0x8B, 0x08,
0x8B,
0x08,
/* mov ecx, [ecx+XX] ; Get vtbl->slot_XX */
0x8B, 0x89, -1, -1, -1, -1,
0x8B,
0x89,
-1,
-1,
-1,
-1,
/* jmp ecx ; Continue to slot_XX */
0xFF, 0xE1
};
0xFF,
0xE1};
#endif
static HRESULT STDCALL com_proxy_query_interface(IUnknown *ptr, REFIID iid,
void **iface)
static HRESULT STDCALL
com_proxy_query_interface(IUnknown *ptr, REFIID iid, void **iface)
{
struct com_proxy *self = (struct com_proxy *) ptr;
IUnknown *obj = self->real; /* Not necessarily the real IUnknown* */
@@ -117,8 +143,11 @@ struct com_proxy *com_proxy_wrap(void *iface, size_t vtbl_size)
self = xmalloc(sizeof(*self));
self->vptr = xmalloc(vtbl_size);
self->real = iface;
self->tramps = VirtualAlloc(NULL, sizeof(com_proxy_tramp) * nslots,
MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
self->tramps = VirtualAlloc(
NULL,
sizeof(com_proxy_tramp) * nslots,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
/* Set up proxied IUnknown impl */
vtbl = self->vptr;
@@ -127,7 +156,7 @@ struct com_proxy *com_proxy_wrap(void *iface, size_t vtbl_size)
vtbl[2] = com_proxy_release;
/* Populate trampoline code for remaining vtbl entries */
for (i = 3 /* Skip IUnknown */ ; i < nslots ; i++) {
for (i = 3 /* Skip IUnknown */; i < nslots; i++) {
cur_tramp = self->tramps + i * sizeof(com_proxy_tramp);
/* Copy template */
@@ -142,4 +171,3 @@ struct com_proxy *com_proxy_wrap(void *iface, size_t vtbl_size)
return self;
}
+300 -189
View File
@@ -1,158 +1,232 @@
#define LOG_MODULE "hook-d3d9"
#include "hook/com-proxy.h"
#include "hook/d3d9.h"
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "util/log.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static IDirect3D9* (STDCALL* real_Direct3DCreate9)(UINT sdk_ver);
static IDirect3D9 *(STDCALL *real_Direct3DCreate9)(UINT sdk_ver);
static BOOL (STDCALL *real_EnumDisplayDevicesA)(
const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info,
DWORD flags);
static BOOL(STDCALL *real_EnumDisplayDevicesA)(
const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags);
static HWND (STDCALL *real_CreateWindowExA)(
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam);
static HWND(STDCALL *real_CreateWindowExA)(
DWORD dwExStyle,
LPCSTR lpClassName,
LPCSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam);
static BOOL (STDCALL* real_GetClientRect)(HWND hWnd, LPRECT lpRect);
static BOOL(STDCALL *real_GetClientRect)(HWND hWnd, LPRECT lpRect);
static HRESULT (STDCALL* real_CreateDevice)(IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags,
D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev);
static HRESULT(STDCALL *real_CreateDevice)(
IDirect3D9 *self,
UINT adapter,
D3DDEVTYPE type,
HWND hwnd,
DWORD flags,
D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev);
static HRESULT (STDCALL* real_CreateTexture)(IDirect3DDevice9* self, UINT width, UINT height, UINT levels, DWORD usage,
D3DFORMAT format, D3DPOOL pool, IDirect3DTexture9** texture, HANDLE* shared_handle);
static HRESULT(STDCALL *real_CreateTexture)(
IDirect3DDevice9 *self,
UINT width,
UINT height,
UINT levels,
DWORD usage,
D3DFORMAT format,
D3DPOOL pool,
IDirect3DTexture9 **texture,
HANDLE *shared_handle);
static HRESULT (STDCALL* real_BeginScene)(IDirect3DDevice9* self);
static HRESULT(STDCALL *real_BeginScene)(IDirect3DDevice9 *self);
static HRESULT (STDCALL* real_EndScene)(IDirect3DDevice9* self);
static HRESULT(STDCALL *real_EndScene)(IDirect3DDevice9 *self);
static HRESULT (STDCALL* real_Present)(IDirect3DDevice9* self,
CONST RECT *pSourceRect, CONST RECT *pDestRect,
HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion);
static HRESULT(STDCALL *real_Present)(
IDirect3DDevice9 *self,
CONST RECT *pSourceRect,
CONST RECT *pDestRect,
HWND hDestWindowOverride,
CONST RGNDATA *pDirtyRegion);
static HRESULT (STDCALL* real_SetRenderState)(IDirect3DDevice9* self,
D3DRENDERSTATETYPE State, DWORD Value);
static HRESULT(STDCALL *real_SetRenderState)(
IDirect3DDevice9 *self, D3DRENDERSTATETYPE State, DWORD Value);
static HRESULT (STDCALL *real_DrawPrimitiveUP)(
IDirect3DDevice9* self, D3DPRIMITIVETYPE primitive_type,
UINT primitive_count, const void *data, UINT stride);
static HRESULT(STDCALL *real_DrawPrimitiveUP)(
IDirect3DDevice9 *self,
D3DPRIMITIVETYPE primitive_type,
UINT primitive_count,
const void *data,
UINT stride);
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static IDirect3D9* STDCALL my_Direct3DCreate9(UINT sdk_ver);
static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver);
static BOOL STDCALL my_EnumDisplayDevicesA(const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags);
static BOOL STDCALL my_EnumDisplayDevicesA(
const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags);
static HWND STDCALL my_CreateWindowExA(
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam);
DWORD dwExStyle,
LPCSTR lpClassName,
LPCSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam);
static BOOL STDCALL my_GetClientRect(HWND hWnd, LPRECT lpRect);
static HRESULT STDCALL my_CreateDevice(IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags,
D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev);
static HRESULT STDCALL my_CreateDevice(
IDirect3D9 *self,
UINT adapter,
D3DDEVTYPE type,
HWND hwnd,
DWORD flags,
D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev);
static HRESULT STDCALL my_CreateTexture(IDirect3DDevice9* self, UINT width, UINT height, UINT levels, DWORD usage,
D3DFORMAT format, D3DPOOL pool, IDirect3DTexture9** texture, HANDLE* shared_handle);
static HRESULT STDCALL my_CreateTexture(
IDirect3DDevice9 *self,
UINT width,
UINT height,
UINT levels,
DWORD usage,
D3DFORMAT format,
D3DPOOL pool,
IDirect3DTexture9 **texture,
HANDLE *shared_handle);
static HRESULT STDCALL my_BeginScene(IDirect3DDevice9* self);
static HRESULT STDCALL my_BeginScene(IDirect3DDevice9 *self);
static HRESULT STDCALL my_EndScene(IDirect3DDevice9* self);
static HRESULT STDCALL my_EndScene(IDirect3DDevice9 *self);
static HRESULT STDCALL my_Present(IDirect3DDevice9* self,
CONST RECT *pSourceRect, CONST RECT *pDestRect,
HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion);
static HRESULT STDCALL my_Present(
IDirect3DDevice9 *self,
CONST RECT *pSourceRect,
CONST RECT *pDestRect,
HWND hDestWindowOverride,
CONST RGNDATA *pDirtyRegion);
static HRESULT STDCALL my_SetRenderState(IDirect3DDevice9* self,
D3DRENDERSTATETYPE State, DWORD Value);
static HRESULT STDCALL my_SetRenderState(
IDirect3DDevice9 *self, D3DRENDERSTATETYPE State, DWORD Value);
static HRESULT STDCALL my_DrawPrimitiveUP(
IDirect3DDevice9* self, D3DPRIMITIVETYPE primitive_type,
UINT primitive_count, const void *data, UINT stride);
IDirect3DDevice9 *self,
D3DPRIMITIVETYPE primitive_type,
UINT primitive_count,
const void *data,
UINT stride);
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static const struct hook_symbol hook_d3d9_hook_syms[] = {
{
.name = "Direct3DCreate9",
.patch = my_Direct3DCreate9,
.link = (void **) &real_Direct3DCreate9
},
{.name = "Direct3DCreate9",
.patch = my_Direct3DCreate9,
.link = (void **) &real_Direct3DCreate9},
};
static const struct hook_symbol hook_d3d9_hook_user32_syms[] = {
{
.name = "EnumDisplayDevicesA",
.patch = my_EnumDisplayDevicesA,
.link = (void **) &real_EnumDisplayDevicesA
},
{
.name = "CreateWindowExA",
.patch = my_CreateWindowExA,
.link = (void **) &real_CreateWindowExA
},
{
.name = "GetClientRect",
.patch = my_GetClientRect,
.link = (void **) &real_GetClientRect
},
{.name = "EnumDisplayDevicesA",
.patch = my_EnumDisplayDevicesA,
.link = (void **) &real_EnumDisplayDevicesA},
{.name = "CreateWindowExA",
.patch = my_CreateWindowExA,
.link = (void **) &real_CreateWindowExA},
{.name = "GetClientRect",
.patch = my_GetClientRect,
.link = (void **) &real_GetClientRect},
};
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp* irp);
static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp* irp);
static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp *irp);
static HRESULT hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp* irp);
static HRESULT
hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp);
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static const hook_d3d9_irp_handler_t hook_d3d9_irp_real_handlers[] = {
[HOOK_D3D9_IRP_OP_INVALID] = hook_d3d9_irp_handler_real_invalid,
[HOOK_D3D9_IRP_OP_CTX_CREATE] = hook_d3d9_irp_handler_real_ctx_create,
[HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES] = hook_d3d9_irp_handler_real_enum_display_devices,
[HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX] = hook_d3d9_irp_handler_real_create_window_ex,
[HOOK_D3D9_IRP_OP_GET_CLIENT_RECT] = hook_d3d9_irp_handler_real_get_client_rect,
[HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE] = hook_d3d9_irp_handler_real_dev_create_device,
[HOOK_D3D9_IRP_OP_DEV_CREATE_TEXTURE] = hook_d3d9_irp_handler_real_dev_create_texture,
[HOOK_D3D9_IRP_OP_DEV_BEGIN_SCENE] = hook_d3d9_irp_handler_real_dev_begin_scene,
[HOOK_D3D9_IRP_OP_ENUM_DISPLAY_DEVICES] =
hook_d3d9_irp_handler_real_enum_display_devices,
[HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX] =
hook_d3d9_irp_handler_real_create_window_ex,
[HOOK_D3D9_IRP_OP_GET_CLIENT_RECT] =
hook_d3d9_irp_handler_real_get_client_rect,
[HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE] =
hook_d3d9_irp_handler_real_dev_create_device,
[HOOK_D3D9_IRP_OP_DEV_CREATE_TEXTURE] =
hook_d3d9_irp_handler_real_dev_create_texture,
[HOOK_D3D9_IRP_OP_DEV_BEGIN_SCENE] =
hook_d3d9_irp_handler_real_dev_begin_scene,
[HOOK_D3D9_IRP_OP_DEV_END_SCENE] = hook_d3d9_irp_handler_real_dev_end_scene,
[HOOK_D3D9_IRP_OP_DEV_PRESENT] = hook_d3d9_irp_handler_real_dev_present,
[HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE] = hook_d3d9_irp_handler_real_dev_set_render_state,
[HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP] = hook_d3d9_irp_handler_real_dev_draw_primitive_up,
[HOOK_D3D9_IRP_OP_DEV_SET_RENDER_STATE] =
hook_d3d9_irp_handler_real_dev_set_render_state,
[HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP] =
hook_d3d9_irp_handler_real_dev_draw_primitive_up,
};
static const hook_d3d9_irp_handler_t* hook_d3d9_handlers;
static const hook_d3d9_irp_handler_t *hook_d3d9_handlers;
static size_t hook_d3d9_nhandlers;
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static IDirect3D9* STDCALL my_Direct3DCreate9(UINT sdk_ver)
static IDirect3D9 *STDCALL my_Direct3DCreate9(UINT sdk_ver)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -172,7 +246,8 @@ static IDirect3D9* STDCALL my_Direct3DCreate9(UINT sdk_ver)
}
}
static BOOL STDCALL my_EnumDisplayDevicesA(const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags)
static BOOL STDCALL my_EnumDisplayDevicesA(
const char *dev_name, DWORD dev_num, DISPLAY_DEVICEA *info, DWORD flags)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -195,9 +270,18 @@ static BOOL STDCALL my_EnumDisplayDevicesA(const char *dev_name, DWORD dev_num,
}
static HWND STDCALL my_CreateWindowExA(
DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle,
int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam)
DWORD dwExStyle,
LPCSTR lpClassName,
LPCSTR lpWindowName,
DWORD dwStyle,
int X,
int Y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -225,7 +309,7 @@ static HWND STDCALL my_CreateWindowExA(
return irp.args.create_window_ex.result;
} else {
return NULL;
}
}
}
static BOOL STDCALL my_GetClientRect(HWND hWnd, LPRECT lpRect)
@@ -249,8 +333,13 @@ static BOOL STDCALL my_GetClientRect(HWND hWnd, LPRECT lpRect)
}
static HRESULT STDCALL my_CreateDevice(
IDirect3D9 *self, UINT adapter, D3DDEVTYPE type, HWND hwnd, DWORD flags,
D3DPRESENT_PARAMETERS *pp, IDirect3DDevice9 **pdev)
IDirect3D9 *self,
UINT adapter,
D3DDEVTYPE type,
HWND hwnd,
DWORD flags,
D3DPRESENT_PARAMETERS *pp,
IDirect3DDevice9 **pdev)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -271,8 +360,16 @@ static HRESULT STDCALL my_CreateDevice(
return hr;
}
static HRESULT STDCALL my_CreateTexture(IDirect3DDevice9* self, UINT width, UINT height, UINT levels, DWORD usage,
D3DFORMAT format, D3DPOOL pool, IDirect3DTexture9** texture, HANDLE* shared_handle)
static HRESULT STDCALL my_CreateTexture(
IDirect3DDevice9 *self,
UINT width,
UINT height,
UINT levels,
DWORD usage,
D3DFORMAT format,
D3DPOOL pool,
IDirect3DTexture9 **texture,
HANDLE *shared_handle)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -295,7 +392,7 @@ static HRESULT STDCALL my_CreateTexture(IDirect3DDevice9* self, UINT width, UINT
return hr;
}
static HRESULT STDCALL my_BeginScene(IDirect3DDevice9* self)
static HRESULT STDCALL my_BeginScene(IDirect3DDevice9 *self)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -310,7 +407,7 @@ static HRESULT STDCALL my_BeginScene(IDirect3DDevice9* self)
return hr;
}
static HRESULT STDCALL my_EndScene(IDirect3DDevice9* self)
static HRESULT STDCALL my_EndScene(IDirect3DDevice9 *self)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -325,9 +422,12 @@ static HRESULT STDCALL my_EndScene(IDirect3DDevice9* self)
return hr;
}
static HRESULT STDCALL my_Present(IDirect3DDevice9* self,
CONST RECT *pSourceRect, CONST RECT *pDestRect,
HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
static HRESULT STDCALL my_Present(
IDirect3DDevice9 *self,
CONST RECT *pSourceRect,
CONST RECT *pDestRect,
HWND hDestWindowOverride,
CONST RGNDATA *pDirtyRegion)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -346,8 +446,8 @@ static HRESULT STDCALL my_Present(IDirect3DDevice9* self,
return hr;
}
static HRESULT STDCALL my_SetRenderState(IDirect3DDevice9* self,
D3DRENDERSTATETYPE State, DWORD Value)
static HRESULT STDCALL
my_SetRenderState(IDirect3DDevice9 *self, D3DRENDERSTATETYPE State, DWORD Value)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -361,12 +461,15 @@ static HRESULT STDCALL my_SetRenderState(IDirect3DDevice9* self,
hr = hook_d3d9_irp_invoke_next(&irp);
return hr;
return hr;
}
static HRESULT STDCALL my_DrawPrimitiveUP(
IDirect3DDevice9* self, D3DPRIMITIVETYPE primitive_type,
UINT primitive_count, const void *data, UINT stride)
IDirect3DDevice9 *self,
D3DPRIMITIVETYPE primitive_type,
UINT primitive_count,
const void *data,
UINT stride)
{
struct hook_d3d9_irp irp;
HRESULT hr;
@@ -382,12 +485,13 @@ static HRESULT STDCALL my_DrawPrimitiveUP(
hr = hook_d3d9_irp_invoke_next(&irp);
return hr;
return hr;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
static HRESULT hook_d3d9_irp_handler_invoke_real(struct hook_d3d9_irp* irp)
static HRESULT hook_d3d9_irp_handler_invoke_real(struct hook_d3d9_irp *irp)
{
hook_d3d9_irp_handler_t handler;
@@ -401,18 +505,18 @@ static HRESULT hook_d3d9_irp_handler_invoke_real(struct hook_d3d9_irp* irp)
return handler(irp);
}
static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp* irp)
static HRESULT hook_d3d9_irp_handler_real_invalid(struct hook_d3d9_irp *irp)
{
log_fatal("Called invalid handler");
return E_FAIL;
}
static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp* irp)
static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp *irp)
{
IDirect3D9* api;
IDirect3D9Vtbl* api_vtbl;
struct com_proxy* api_proxy;
IDirect3D9 *api;
IDirect3D9Vtbl *api_vtbl;
struct com_proxy *api_proxy;
log_assert(irp);
@@ -428,22 +532,23 @@ static HRESULT hook_d3d9_irp_handler_real_ctx_create(struct hook_d3d9_irp* irp)
real_CreateDevice = api_vtbl->CreateDevice;
api_vtbl->CreateDevice = my_CreateDevice;
irp->args.ctx_create.ctx = (IDirect3D9*) api_proxy;
irp->args.ctx_create.ctx = (IDirect3D9 *) api_proxy;
return S_OK;
return S_OK;
}
static HRESULT hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_irp *irp)
{
BOOL res;
log_assert(irp);
res = real_EnumDisplayDevicesA(
irp->args.enum_display_devices.dev_name,
irp->args.enum_display_devices.dev_num,
irp->args.enum_display_devices.info,
irp->args.enum_display_devices.flags);
irp->args.enum_display_devices.dev_name,
irp->args.enum_display_devices.dev_num,
irp->args.enum_display_devices.info,
irp->args.enum_display_devices.flags);
if (res == TRUE) {
return S_OK;
@@ -452,23 +557,24 @@ static HRESULT hook_d3d9_irp_handler_real_enum_display_devices(struct hook_d3d9_
}
}
static HRESULT hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp *irp)
{
log_assert(irp);
irp->args.create_window_ex.result = real_CreateWindowExA(
irp->args.create_window_ex.ex_style,
irp->args.create_window_ex.class_name,
irp->args.create_window_ex.window_name,
irp->args.create_window_ex.style,
irp->args.create_window_ex.x,
irp->args.create_window_ex.y,
irp->args.create_window_ex.width,
irp->args.create_window_ex.height,
irp->args.create_window_ex.wnd_parent,
irp->args.create_window_ex.menu,
irp->args.create_window_ex.instance,
irp->args.create_window_ex.param);
irp->args.create_window_ex.ex_style,
irp->args.create_window_ex.class_name,
irp->args.create_window_ex.window_name,
irp->args.create_window_ex.style,
irp->args.create_window_ex.x,
irp->args.create_window_ex.y,
irp->args.create_window_ex.width,
irp->args.create_window_ex.height,
irp->args.create_window_ex.wnd_parent,
irp->args.create_window_ex.menu,
irp->args.create_window_ex.instance,
irp->args.create_window_ex.param);
if (irp->args.create_window_ex.result) {
return S_OK;
@@ -477,15 +583,15 @@ static HRESULT hook_d3d9_irp_handler_real_create_window_ex(struct hook_d3d9_irp*
}
}
static HRESULT hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp *irp)
{
BOOL res;
log_assert(irp);
res = real_GetClientRect(
irp->args.get_client_rect.wnd,
irp->args.get_client_rect.rect);
irp->args.get_client_rect.wnd, irp->args.get_client_rect.rect);
if (res == TRUE) {
return S_OK;
@@ -494,23 +600,24 @@ static HRESULT hook_d3d9_irp_handler_real_get_client_rect(struct hook_d3d9_irp*
}
}
static HRESULT hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp *irp)
{
HRESULT hr;
IDirect3DDevice9* api;
IDirect3DDevice9Vtbl* api_vtbl;
IDirect3DDevice9 *api;
IDirect3DDevice9Vtbl *api_vtbl;
struct com_proxy *api_proxy;
log_assert(irp);
hr = real_CreateDevice(
irp->args.ctx_create_device.self,
irp->args.ctx_create_device.adapter,
irp->args.ctx_create_device.type,
irp->args.ctx_create_device.hwnd,
irp->args.ctx_create_device.flags,
irp->args.ctx_create_device.pp,
irp->args.ctx_create_device.pdev);
irp->args.ctx_create_device.self,
irp->args.ctx_create_device.adapter,
irp->args.ctx_create_device.type,
irp->args.ctx_create_device.hwnd,
irp->args.ctx_create_device.flags,
irp->args.ctx_create_device.pp,
irp->args.ctx_create_device.pdev);
if (hr != S_OK) {
return hr;
@@ -538,76 +645,82 @@ static HRESULT hook_d3d9_irp_handler_real_dev_create_device(struct hook_d3d9_irp
real_DrawPrimitiveUP = api_vtbl->DrawPrimitiveUP;
api_vtbl->DrawPrimitiveUP = my_DrawPrimitiveUP;
*irp->args.ctx_create_device.pdev = (IDirect3DDevice9*) api_proxy;
*irp->args.ctx_create_device.pdev = (IDirect3DDevice9 *) api_proxy;
return hr;
}
static HRESULT hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_dev_create_texture(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_CreateTexture(
irp->args.dev_create_texture.self,
irp->args.dev_create_texture.width,
irp->args.dev_create_texture.height,
irp->args.dev_create_texture.levels,
irp->args.dev_create_texture.usage,
irp->args.dev_create_texture.format,
irp->args.dev_create_texture.pool,
irp->args.dev_create_texture.texture,
irp->args.dev_create_texture.shared_handle);
irp->args.dev_create_texture.self,
irp->args.dev_create_texture.width,
irp->args.dev_create_texture.height,
irp->args.dev_create_texture.levels,
irp->args.dev_create_texture.usage,
irp->args.dev_create_texture.format,
irp->args.dev_create_texture.pool,
irp->args.dev_create_texture.texture,
irp->args.dev_create_texture.shared_handle);
}
static HRESULT hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_dev_begin_scene(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_BeginScene(irp->args.dev_begin_scene.self);
}
static HRESULT hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_dev_end_scene(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_EndScene(irp->args.dev_end_scene.self);
}
static HRESULT hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp* irp)
static HRESULT hook_d3d9_irp_handler_real_dev_present(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_Present(
irp->args.dev_present.self,
irp->args.dev_present.source_rect,
irp->args.dev_present.dest_rect,
irp->args.dev_present.dest_window_override,
irp->args.dev_present.dirty_region);
irp->args.dev_present.self,
irp->args.dev_present.source_rect,
irp->args.dev_present.dest_rect,
irp->args.dev_present.dest_window_override,
irp->args.dev_present.dirty_region);
}
static HRESULT hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_SetRenderState(
irp->args.dev_set_render_state.self,
irp->args.dev_set_render_state.state,
irp->args.dev_set_render_state.value);
irp->args.dev_set_render_state.self,
irp->args.dev_set_render_state.state,
irp->args.dev_set_render_state.value);
}
static HRESULT hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp* irp)
static HRESULT
hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp)
{
log_assert(irp);
return real_DrawPrimitiveUP(
irp->args.dev_draw_primitive_up.self,
irp->args.dev_draw_primitive_up.primitive_type,
irp->args.dev_draw_primitive_up.primitive_count,
irp->args.dev_draw_primitive_up.data,
irp->args.dev_draw_primitive_up.stride);
irp->args.dev_draw_primitive_up.self,
irp->args.dev_draw_primitive_up.primitive_type,
irp->args.dev_draw_primitive_up.primitive_count,
irp->args.dev_draw_primitive_up.data,
irp->args.dev_draw_primitive_up.stride);
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------
*/
void hook_d3d9_init(const hook_d3d9_irp_handler_t *handlers, size_t nhandlers)
{
@@ -618,19 +731,17 @@ void hook_d3d9_init(const hook_d3d9_irp_handler_t *handlers, size_t nhandlers)
hook_d3d9_nhandlers = nhandlers;
hook_table_apply(
NULL,
"d3d9.dll",
hook_d3d9_hook_syms,
lengthof(hook_d3d9_hook_syms));
NULL, "d3d9.dll", hook_d3d9_hook_syms, lengthof(hook_d3d9_hook_syms));
hook_table_apply(
NULL,
"user32.dll",
hook_d3d9_hook_user32_syms,
lengthof(hook_d3d9_hook_user32_syms));
NULL,
"user32.dll",
hook_d3d9_hook_user32_syms,
lengthof(hook_d3d9_hook_user32_syms));
}
HRESULT hook_d3d9_irp_invoke_next(struct hook_d3d9_irp* irp)
HRESULT
hook_d3d9_irp_invoke_next(struct hook_d3d9_irp *irp)
{
hook_d3d9_irp_handler_t handler;
HRESULT hr;
+35 -31
View File
@@ -3,10 +3,11 @@
/**
* This module hooks the d3d9 API and abstracts it using IRPs (like iohook).
* It allows hiding the COM stuff which is required to be handled when interacting with d3d9.
* Furthermore, this module supports chaining of multiple handlers and more flexible and structured
* dispatching on the available operations (more can be added when required, obviously).
*
* It allows hiding the COM stuff which is required to be handled when
* interacting with d3d9. Furthermore, this module supports chaining of multiple
* handlers and more flexible and structured dispatching on the available
* operations (more can be added when required, obviously).
*
* @author icex2
*/
@@ -48,16 +49,16 @@ struct hook_d3d9_irp {
struct {
UINT sdk_ver;
// Return value of call
IDirect3D9* ctx;
IDirect3D9 *ctx;
} ctx_create;
/**
* Params of EnumDisplayDevicesA.
*/
struct {
const char* dev_name;
const char *dev_name;
DWORD dev_num;
DISPLAY_DEVICEA* info;
DISPLAY_DEVICEA *info;
DWORD flags;
} enum_display_devices;
@@ -92,60 +93,60 @@ struct hook_d3d9_irp {
* Params of IDirect3D9_CreateDevice.
*/
struct {
IDirect3D9* self;
IDirect3D9 *self;
UINT adapter;
D3DDEVTYPE type;
HWND hwnd;
DWORD flags;
D3DPRESENT_PARAMETERS* pp;
IDirect3DDevice9** pdev;
D3DPRESENT_PARAMETERS *pp;
IDirect3DDevice9 **pdev;
} ctx_create_device;
/**
* Params of IDirect3DDevice9_CreateTexture.
*/
struct {
IDirect3DDevice9* self;
IDirect3DDevice9 *self;
UINT width;
UINT height;
UINT levels;
DWORD usage;
D3DFORMAT format;
D3DPOOL pool;
IDirect3DTexture9** texture;
HANDLE* shared_handle;
IDirect3DTexture9 **texture;
HANDLE *shared_handle;
} dev_create_texture;
/**
* Params of IDirect3DDevice9_BeginScene.
*/
struct {
IDirect3DDevice9* self;
IDirect3DDevice9 *self;
} dev_begin_scene;
/**
* Params of IDirect3DDevice9_EndScene.
*/
struct {
IDirect3DDevice9* self;
IDirect3DDevice9 *self;
} dev_end_scene;
/**
* Params of IDirect3DDevice9_Present.
*/
struct {
IDirect3DDevice9* self;
CONST RECT* source_rect;
CONST RECT* dest_rect;
IDirect3DDevice9 *self;
CONST RECT *source_rect;
CONST RECT *dest_rect;
HWND dest_window_override;
CONST RGNDATA* dirty_region;
CONST RGNDATA *dirty_region;
} dev_present;
/**
* Params of IDirect3DDevice9_SetRenderState.
*/
struct {
IDirect3DDevice9* self;
IDirect3DDevice9 *self;
D3DRENDERSTATETYPE state;
DWORD value;
} dev_set_render_state;
@@ -154,9 +155,9 @@ struct hook_d3d9_irp {
* Params of IDirect3DDevice9_DrawPrimitiveUP.
*/
struct {
IDirect3DDevice9* self;
IDirect3DDevice9 *self;
D3DPRIMITIVETYPE primitive_type;
UINT primitive_count;
UINT primitive_count;
const void *data;
UINT stride;
} dev_draw_primitive_up;
@@ -168,25 +169,28 @@ struct hook_d3d9_irp {
/**
* D3D9 IRP handler function typedef.
*/
typedef HRESULT (*hook_d3d9_irp_handler_t)(struct hook_d3d9_irp* irp);
typedef HRESULT (*hook_d3d9_irp_handler_t)(struct hook_d3d9_irp *irp);
/**
* Initialize the d3d9 hook module.
*
* @param handlers The handlers to install which will be called once one of the hooked functions is called.
* @param nhandlers Number of handlers to install (length of provided array above).
*
* @param handlers The handlers to install which will be called once one of the
* hooked functions is called.
* @param nhandlers Number of handlers to install (length of provided array
* above).
*/
void hook_d3d9_init(const hook_d3d9_irp_handler_t *handlers, size_t nhandlers);
/**
* Main invoke next function.
*
* Call this from your handlers if you are done handling and to pass on the IRP to the further installed IRP handlers.
* At the end of the chain, calls the real function.
*
*
* Call this from your handlers if you are done handling and to pass on the IRP
* to the further installed IRP handlers. At the end of the chain, calls the
* real function.
*
* @param irp Pointer to a valid IRP.
* @return S_OK on success, error otherwise (depending on the irp op).
*/
HRESULT hook_d3d9_irp_invoke_next(struct hook_d3d9_irp* irp);
HRESULT hook_d3d9_irp_invoke_next(struct hook_d3d9_irp *irp);
#endif
+205 -216
View File
@@ -14,10 +14,8 @@
/* Helpers */
static BOOL iohook_overlapped_result(
uint32_t *syncout,
OVERLAPPED *ovl,
uint32_t value);
static BOOL
iohook_overlapped_result(uint32_t *syncout, OVERLAPPED *ovl, uint32_t value);
static HRESULT irp_invoke_real(struct irp *irp);
static HRESULT irp_invoke_real_open(struct irp *irp);
@@ -33,99 +31,95 @@ static HRESULT irp_invoke_real_ioctl(struct irp *irp);
static BOOL STDCALL my_CloseHandle(HANDLE fd);
static HANDLE STDCALL my_CreateFileW(
const wchar_t *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile);
const wchar_t *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile);
static HANDLE STDCALL my_CreateFileA(
const char *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile);
const char *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile);
static BOOL STDCALL my_ReadFile(
HANDLE hFile,
void *lpBuffer,
uint32_t nNumberOfBytesToRead,
uint32_t *lpNumberOfBytesRead,
OVERLAPPED *lpOverlapped);
HANDLE hFile,
void *lpBuffer,
uint32_t nNumberOfBytesToRead,
uint32_t *lpNumberOfBytesRead,
OVERLAPPED *lpOverlapped);
static BOOL STDCALL my_WriteFile(
HANDLE hFile,
const void *lpBuffer,
uint32_t nNumberOfBytesToWrite,
uint32_t *lpNumberOfBytesWritten,
OVERLAPPED *lpOverlapped);
HANDLE hFile,
const void *lpBuffer,
uint32_t nNumberOfBytesToWrite,
uint32_t *lpNumberOfBytesWritten,
OVERLAPPED *lpOverlapped);
static DWORD STDCALL my_SetFilePointer(
HANDLE hFile,
int32_t lDistanceToMove,
int32_t *lpDistanceToMoveHigh,
uint32_t dwMoveMethod);
HANDLE hFile,
int32_t lDistanceToMove,
int32_t *lpDistanceToMoveHigh,
uint32_t dwMoveMethod);
static BOOL STDCALL my_FlushFileBuffers(HANDLE hFile);
static BOOL STDCALL my_DeviceIoControl(
HANDLE hFile,
uint32_t dwIoControlCode,
void *lpInBuffer,
uint32_t nInBufferSize,
void *lpOutBuffer,
uint32_t nOutBufferSize,
uint32_t *lpBytesReturned,
OVERLAPPED *lpOverlapped);
HANDLE hFile,
uint32_t dwIoControlCode,
void *lpInBuffer,
uint32_t nInBufferSize,
void *lpOutBuffer,
uint32_t nOutBufferSize,
uint32_t *lpBytesReturned,
OVERLAPPED *lpOverlapped);
/* Links */
static BOOL (STDCALL *real_CloseHandle)(HANDLE fd);
static BOOL(STDCALL *real_CloseHandle)(HANDLE fd);
static HANDLE (STDCALL *real_CreateFileW)(
const wchar_t *filename,
uint32_t access,
uint32_t share,
SECURITY_ATTRIBUTES *sa,
uint32_t creation,
uint32_t flags,
HANDLE tmpl);
static HANDLE(STDCALL *real_CreateFileW)(
const wchar_t *filename,
uint32_t access,
uint32_t share,
SECURITY_ATTRIBUTES *sa,
uint32_t creation,
uint32_t flags,
HANDLE tmpl);
static BOOL (STDCALL *real_DeviceIoControl)(
HANDLE fd,
uint32_t code,
void *in_bytes,
uint32_t in_nbytes,
void *out_bytes,
uint32_t out_nbytes,
uint32_t *out_returned,
OVERLAPPED *ovl);
static BOOL(STDCALL *real_DeviceIoControl)(
HANDLE fd,
uint32_t code,
void *in_bytes,
uint32_t in_nbytes,
void *out_bytes,
uint32_t out_nbytes,
uint32_t *out_returned,
OVERLAPPED *ovl);
static BOOL (STDCALL *real_ReadFile)(
HANDLE fd,
void *buf,
uint32_t nbytes,
uint32_t *nread,
OVERLAPPED *ovl);
static BOOL(STDCALL *real_ReadFile)(
HANDLE fd, void *buf, uint32_t nbytes, uint32_t *nread, OVERLAPPED *ovl);
static BOOL (STDCALL *real_WriteFile)(
HANDLE fd,
const void *buf,
uint32_t nbytes,
uint32_t *nwrit,
OVERLAPPED *ovl);
static BOOL(STDCALL *real_WriteFile)(
HANDLE fd,
const void *buf,
uint32_t nbytes,
uint32_t *nwrit,
OVERLAPPED *ovl);
static DWORD (STDCALL *real_SetFilePointer)(
HANDLE hFile,
int32_t lDistanceToMove,
int32_t *lpDistanceToMoveHigh,
uint32_t dwMoveMethod);
static DWORD(STDCALL *real_SetFilePointer)(
HANDLE hFile,
int32_t lDistanceToMove,
int32_t *lpDistanceToMoveHigh,
uint32_t dwMoveMethod);
static BOOL (STDCALL *real_FlushFileBuffers)(HANDLE fd);
static BOOL(STDCALL *real_FlushFileBuffers)(HANDLE fd);
/* Hook table */
@@ -133,54 +127,54 @@ static struct hook_symbol iohook_kernel32_syms[] = {
/* Basic IO */
{
.name = "CloseHandle",
.patch = my_CloseHandle,
.link = (void *) &real_CloseHandle,
.name = "CloseHandle",
.patch = my_CloseHandle,
.link = (void *) &real_CloseHandle,
},
{
.name = "CreateFileA",
.patch = my_CreateFileA,
.name = "CreateFileA",
.patch = my_CreateFileA,
},
{
.name = "CreateFileW",
.patch = my_CreateFileW,
.link = (void *) &real_CreateFileW,
.name = "CreateFileW",
.patch = my_CreateFileW,
.link = (void *) &real_CreateFileW,
},
{
.name = "DeviceIoControl",
.patch = my_DeviceIoControl,
.link = (void *) &real_DeviceIoControl,
.name = "DeviceIoControl",
.patch = my_DeviceIoControl,
.link = (void *) &real_DeviceIoControl,
},
{
.name = "ReadFile",
.patch = my_ReadFile,
.link = (void *) &real_ReadFile,
.name = "ReadFile",
.patch = my_ReadFile,
.link = (void *) &real_ReadFile,
},
{
.name = "WriteFile",
.patch = my_WriteFile,
.link = (void *) &real_WriteFile,
.name = "WriteFile",
.patch = my_WriteFile,
.link = (void *) &real_WriteFile,
},
{
.name = "SetFilePointer",
.patch = my_SetFilePointer,
.link = (void *) &real_SetFilePointer,
.name = "SetFilePointer",
.patch = my_SetFilePointer,
.link = (void *) &real_SetFilePointer,
},
{
.name = "FlushFileBuffers",
.patch = my_FlushFileBuffers,
.link = (void *) &real_FlushFileBuffers,
.name = "FlushFileBuffers",
.patch = my_FlushFileBuffers,
.link = (void *) &real_FlushFileBuffers,
},
};
static const irp_handler_t irp_real_handlers[] = {
[IRP_OP_OPEN] = irp_invoke_real_open,
[IRP_OP_CLOSE] = irp_invoke_real_close,
[IRP_OP_READ] = irp_invoke_real_read,
[IRP_OP_WRITE] = irp_invoke_real_write,
[IRP_OP_SEEK] = irp_invoke_real_seek,
[IRP_OP_FSYNC] = irp_invoke_real_fsync,
[IRP_OP_IOCTL] = irp_invoke_real_ioctl,
[IRP_OP_OPEN] = irp_invoke_real_open,
[IRP_OP_CLOSE] = irp_invoke_real_close,
[IRP_OP_READ] = irp_invoke_real_read,
[IRP_OP_WRITE] = irp_invoke_real_write,
[IRP_OP_SEEK] = irp_invoke_real_seek,
[IRP_OP_FSYNC] = irp_invoke_real_fsync,
[IRP_OP_IOCTL] = irp_invoke_real_ioctl,
};
static const irp_handler_t *iohook_handlers;
@@ -195,33 +189,33 @@ void iohook_init(const irp_handler_t *handlers, size_t nhandlers)
iohook_nhandlers = nhandlers;
hook_table_apply(
NULL,
"kernel32.dll",
iohook_kernel32_syms,
lengthof(iohook_kernel32_syms));
NULL,
"kernel32.dll",
iohook_kernel32_syms,
lengthof(iohook_kernel32_syms));
if (real_CreateFileW == NULL) {
/* my_CreateFileA requires this to be present */
real_CreateFileW = (void *) GetProcAddress(
GetModuleHandleA("kernel32.dll"),
"CreateFileW");
GetModuleHandleA("kernel32.dll"), "CreateFileW");
}
log_info("IO Hook subsystem initialized");
}
HANDLE iohook_open_dummy_fd(void)
HANDLE
iohook_open_dummy_fd(void)
{
HANDLE fd;
fd = real_CreateFileW(
L"NUL",
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
L"NUL",
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (fd == INVALID_HANDLE_VALUE) {
log_fatal("Failed to open dummy fd: %08x", (uint32_t) GetLastError());
@@ -230,10 +224,8 @@ HANDLE iohook_open_dummy_fd(void)
return fd;
}
static BOOL iohook_overlapped_result(
uint32_t *syncout,
OVERLAPPED *ovl,
uint32_t value)
static BOOL
iohook_overlapped_result(uint32_t *syncout, OVERLAPPED *ovl, uint32_t value)
{
if (ovl != NULL) {
ovl->Internal = 0; // (NTSTATUS) STATUS_SUCCESS
@@ -256,7 +248,8 @@ static BOOL iohook_overlapped_result(
}
}
HRESULT irp_invoke_next(struct irp *irp)
HRESULT
irp_invoke_next(struct irp *irp)
{
irp_handler_t handler;
HRESULT hr;
@@ -300,13 +293,13 @@ static HRESULT irp_invoke_real_open(struct irp *irp)
log_assert(irp != NULL);
fd = real_CreateFileW(
irp->open_filename,
irp->open_access,
irp->open_share,
irp->open_sa,
irp->open_creation,
irp->open_flags,
irp->open_tmpl);
irp->open_filename,
irp->open_access,
irp->open_share,
irp->open_sa,
irp->open_creation,
irp->open_flags,
irp->open_tmpl);
if (fd == INVALID_HANDLE_VALUE) {
return hr_from_win32();
@@ -340,11 +333,11 @@ static HRESULT irp_invoke_real_read(struct irp *irp)
log_assert(irp != NULL);
ok = real_ReadFile(
irp->fd,
&irp->read.bytes[irp->read.pos],
irp->read.nbytes - irp->read.pos,
&nread,
irp->ovl);
irp->fd,
&irp->read.bytes[irp->read.pos],
irp->read.nbytes - irp->read.pos,
&nread,
irp->ovl);
if (!ok) {
return hr_from_win32();
@@ -363,11 +356,11 @@ static HRESULT irp_invoke_real_write(struct irp *irp)
log_assert(irp != NULL);
ok = real_WriteFile(
irp->fd,
&irp->write.bytes[irp->write.pos],
irp->write.nbytes - irp->write.pos,
&nwrit,
irp->ovl);
irp->fd,
&irp->write.bytes[irp->write.pos],
irp->write.nbytes - irp->write.pos,
&nwrit,
irp->ovl);
if (!ok) {
return hr_from_win32();
@@ -386,11 +379,11 @@ static HRESULT irp_invoke_real_seek(struct irp *irp)
log_assert(irp != NULL);
hi = (uint32_t) (irp->seek_offset >> 32);
lo = (uint32_t) (irp->seek_offset );
hi = (uint32_t)(irp->seek_offset >> 32);
lo = (uint32_t)(irp->seek_offset);
lo = real_SetFilePointer(irp->fd, (int32_t) lo, hi == 0 ? NULL : &hi,
irp->seek_origin);
lo = real_SetFilePointer(
irp->fd, (int32_t) lo, hi == 0 ? NULL : &hi, irp->seek_origin);
if (lo == INVALID_SET_FILE_POINTER) {
hr = hr_from_win32();
@@ -435,14 +428,14 @@ static HRESULT irp_invoke_real_ioctl(struct irp *irp)
log_assert(irp->read.pos == 0);
ok = real_DeviceIoControl(
irp->fd,
irp->ioctl,
(void *) irp->write.bytes, // Cast off const
irp->write.nbytes,
irp->read.bytes,
irp->read.nbytes,
&nread,
irp->ovl);
irp->fd,
irp->ioctl,
(void *) irp->write.bytes, // Cast off const
irp->write.nbytes,
irp->read.bytes,
irp->read.nbytes,
&nread,
irp->ovl);
if (!ok) {
return hr_from_win32();
@@ -454,13 +447,13 @@ static HRESULT irp_invoke_real_ioctl(struct irp *irp)
}
static HANDLE STDCALL my_CreateFileA(
const char *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile)
const char *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
wchar_t *wfilename;
HANDLE fd;
@@ -474,25 +467,26 @@ static HANDLE STDCALL my_CreateFileA(
wfilename = str_widen(lpFileName);
fd = my_CreateFileW(
wfilename,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition, dwFlagsAndAttributes,
hTemplateFile);
wfilename,
dwDesiredAccess,
dwShareMode,
lpSecurityAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
hTemplateFile);
free(wfilename);
return fd;
}
static HANDLE STDCALL my_CreateFileW(
const wchar_t *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile)
const wchar_t *lpFileName,
uint32_t dwDesiredAccess,
uint32_t dwShareMode,
SECURITY_ATTRIBUTES *lpSecurityAttributes,
uint32_t dwCreationDisposition,
uint32_t dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
struct irp irp;
HRESULT hr;
@@ -554,11 +548,11 @@ static BOOL STDCALL my_CloseHandle(HANDLE hFile)
}
static BOOL STDCALL my_ReadFile(
HANDLE hFile,
void *lpBuffer,
uint32_t nNumberOfBytesToRead,
uint32_t *lpNumberOfBytesRead,
OVERLAPPED *lpOverlapped)
HANDLE hFile,
void *lpBuffer,
uint32_t nNumberOfBytesToRead,
uint32_t *lpNumberOfBytesRead,
OVERLAPPED *lpOverlapped)
{
struct irp irp;
HRESULT hr;
@@ -579,9 +573,10 @@ static BOOL STDCALL my_ReadFile(
if (lpOverlapped == NULL) {
if (lpNumberOfBytesRead == NULL) {
log_warning( "%s: lpNumberOfBytesRead must be supplied in "
"synchronous mode",
__func__);
log_warning(
"%s: lpNumberOfBytesRead must be supplied in "
"synchronous mode",
__func__);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -607,17 +602,15 @@ static BOOL STDCALL my_ReadFile(
log_assert(irp.read.pos <= irp.read.nbytes);
return iohook_overlapped_result(
lpNumberOfBytesRead,
lpOverlapped,
irp.read.pos);
lpNumberOfBytesRead, lpOverlapped, irp.read.pos);
}
static BOOL STDCALL my_WriteFile(
HANDLE hFile,
const void *lpBuffer,
uint32_t nNumberOfBytesToWrite,
uint32_t *lpNumberOfBytesWritten,
OVERLAPPED *lpOverlapped)
HANDLE hFile,
const void *lpBuffer,
uint32_t nNumberOfBytesToWrite,
uint32_t *lpNumberOfBytesWritten,
OVERLAPPED *lpOverlapped)
{
struct irp irp;
HRESULT hr;
@@ -639,9 +632,10 @@ static BOOL STDCALL my_WriteFile(
if (lpOverlapped == NULL) {
if (lpNumberOfBytesWritten == NULL) {
log_warning( "%s: lpNumberOfBytesWritten must be supplied in "
"synchronous mode",
__func__);
log_warning(
"%s: lpNumberOfBytesWritten must be supplied in "
"synchronous mode",
__func__);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -667,16 +661,14 @@ static BOOL STDCALL my_WriteFile(
log_assert(irp.write.pos <= irp.write.nbytes);
return iohook_overlapped_result(
lpNumberOfBytesWritten,
lpOverlapped,
irp.write.pos);
lpNumberOfBytesWritten, lpOverlapped, irp.write.pos);
}
static DWORD STDCALL my_SetFilePointer(
HANDLE hFile,
int32_t lDistanceToMove,
int32_t *lpDistanceToMoveHigh,
uint32_t dwMoveMethod)
HANDLE hFile,
int32_t lDistanceToMove,
int32_t *lpDistanceToMoveHigh,
uint32_t dwMoveMethod)
{
struct irp irp;
HRESULT hr;
@@ -698,8 +690,8 @@ static DWORD STDCALL my_SetFilePointer(
with sign-extension vs zero-extension here. */
if (lpDistanceToMoveHigh != NULL) {
irp.seek_offset = ((( int64_t) *lpDistanceToMoveHigh) << 32)
| ((uint64_t) lDistanceToMove);
irp.seek_offset = (((int64_t) *lpDistanceToMoveHigh) << 32) |
((uint64_t) lDistanceToMove);
} else {
irp.seek_offset = (int64_t) lDistanceToMove;
}
@@ -751,14 +743,14 @@ static BOOL STDCALL my_FlushFileBuffers(HANDLE hFile)
}
static BOOL STDCALL my_DeviceIoControl(
HANDLE hFile,
uint32_t dwIoControlCode,
void *lpInBuffer,
uint32_t nInBufferSize,
void *lpOutBuffer,
uint32_t nOutBufferSize,
uint32_t *lpBytesReturned,
OVERLAPPED *lpOverlapped)
HANDLE hFile,
uint32_t dwIoControlCode,
void *lpInBuffer,
uint32_t nInBufferSize,
void *lpOutBuffer,
uint32_t nOutBufferSize,
uint32_t *lpBytesReturned,
OVERLAPPED *lpOverlapped)
{
struct irp irp;
HRESULT hr;
@@ -773,8 +765,8 @@ static BOOL STDCALL my_DeviceIoControl(
if (lpOverlapped == NULL) {
if (lpBytesReturned == NULL) {
log_warning(
"%s: lpBytesReturned must be supplied in synchronous mode",
__func__);
"%s: lpBytesReturned must be supplied in synchronous mode",
__func__);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
@@ -809,8 +801,5 @@ static BOOL STDCALL my_DeviceIoControl(
log_assert(irp.read.pos <= irp.read.nbytes);
return iohook_overlapped_result(
lpBytesReturned,
lpOverlapped,
irp.read.pos);
lpBytesReturned, lpOverlapped, irp.read.pos);
}
+66 -50
View File
@@ -8,11 +8,11 @@
#include "util/log.h"
typedef BOOL (WINAPI *dll_main_t)(HMODULE, uint32_t, void *);
typedef BOOL(WINAPI *dll_main_t)(HMODULE, uint32_t, void *);
static const IMAGE_NT_HEADERS *pe_get_nt_header(HMODULE pe);
static uint32_t pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh,
int nsections);
static uint32_t
pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, int nsections);
static void *pe_offset(void *ptr, size_t off);
static const void *pe_offsetc(const void *ptr, size_t off);
@@ -42,8 +42,8 @@ static const void *pe_offsetc(const void *ptr, size_t off)
return base + off;
}
static uint32_t pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh,
int nsections)
static uint32_t
pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh, int nsections)
{
uint32_t sec_end;
uint32_t size;
@@ -51,7 +51,7 @@ static uint32_t pe_get_virtual_size(const IMAGE_SECTION_HEADER *sh,
size = 0;
for (i = 0 ; i < nsections ; i++) {
for (i = 0; i < nsections; i++) {
sec_end = sh[i].VirtualAddress + sh[i].Misc.VirtualSize;
if (size < sec_end) {
@@ -79,8 +79,10 @@ const pe_iid_t *pe_iid_get_first(HMODULE pe)
const IMAGE_IMPORT_DESCRIPTOR *iid;
nth = pe_get_nt_header(pe);
iid = pe_offsetc(pe, nth->OptionalHeader
.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
iid = pe_offsetc(
pe,
nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
.VirtualAddress);
if (iid == NULL || iid->Name == 0) {
return NULL;
@@ -107,8 +109,8 @@ const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid)
}
}
bool pe_iid_get_iat_entry(HMODULE pe, const pe_iid_t *iid, size_t n,
struct pe_iat_entry *entry)
bool pe_iid_get_iat_entry(
HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry)
{
const IMAGE_IMPORT_BY_NAME *import;
uintptr_t *import_rvas;
@@ -148,12 +150,14 @@ void pe_patch_pointer(void **ppointer, void *new_value)
{
DWORD old_protect;
VirtualProtect(ppointer, sizeof(void*), PAGE_EXECUTE_READWRITE, &old_protect);
VirtualProtect(
ppointer, sizeof(void *), PAGE_EXECUTE_READWRITE, &old_protect);
*ppointer = new_value;
VirtualProtect(ppointer, sizeof(void*), old_protect, &old_protect);
VirtualProtect(ppointer, sizeof(void *), old_protect, &old_protect);
}
HMODULE pe_explode(const uint8_t *bytes, uint32_t nbytes)
HMODULE
pe_explode(const uint8_t *bytes, uint32_t nbytes)
{
HMODULE base;
const IMAGE_DOS_HEADER *dh;
@@ -168,47 +172,58 @@ HMODULE pe_explode(const uint8_t *bytes, uint32_t nbytes)
sh = pe_offsetc(bytes, dh->e_lfanew + sizeof(*nth));
virtual_size = pe_get_virtual_size(sh, nth->FileHeader.NumberOfSections);
base = (HMODULE) VirtualAlloc((void *) nth->OptionalHeader.ImageBase,
virtual_size, MEM_RESERVE, PAGE_NOACCESS);
base = (HMODULE) VirtualAlloc(
(void *) nth->OptionalHeader.ImageBase,
virtual_size,
MEM_RESERVE,
PAGE_NOACCESS);
if (base == NULL) {
/* Try again, allowing any base address */
base = (HMODULE) VirtualAlloc(NULL, virtual_size, MEM_RESERVE,
PAGE_NOACCESS);
base = (HMODULE) VirtualAlloc(
NULL, virtual_size, MEM_RESERVE, PAGE_NOACCESS);
if (base == NULL) {
/* Aargh */
log_fatal("Failed to VirtualAlloc %#x bytes of address space",
virtual_size);
log_fatal(
"Failed to VirtualAlloc %#x bytes of address space",
virtual_size);
}
}
log_misc("Exploding PE, base %p actual %p",
(void *) nth->OptionalHeader.ImageBase,
base);
log_misc(
"Exploding PE, base %p actual %p",
(void *) nth->OptionalHeader.ImageBase,
base);
/* Commit header region */
VirtualAlloc((void *) base, nth->OptionalHeader.SizeOfHeaders, MEM_COMMIT,
PAGE_READWRITE);
VirtualAlloc(
(void *) base,
nth->OptionalHeader.SizeOfHeaders,
MEM_COMMIT,
PAGE_READWRITE);
memcpy(base, dh, sizeof(*dh));
memcpy(pe_offset(base, dh->e_lfanew), nth, sizeof(*nth));
memcpy(pe_offset(base, dh->e_lfanew + sizeof(*nth)), sh,
sizeof(*sh) * nth->FileHeader.NumberOfSections);
memcpy(
pe_offset(base, dh->e_lfanew + sizeof(*nth)),
sh,
sizeof(*sh) * nth->FileHeader.NumberOfSections);
for (i = 0 ; i < nth->FileHeader.NumberOfSections ; i++) {
vflags = sh[i].Characteristics & 0x20000000
? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
for (i = 0; i < nth->FileHeader.NumberOfSections; i++) {
vflags = sh[i].Characteristics & 0x20000000 ? PAGE_EXECUTE_READWRITE :
PAGE_READWRITE;
VirtualAlloc(
pe_offset(base, sh[i].VirtualAddress),
sh[i].Misc.VirtualSize,
MEM_COMMIT,
vflags);
pe_offset(base, sh[i].VirtualAddress),
sh[i].Misc.VirtualSize,
MEM_COMMIT,
vflags);
memcpy( pe_offset(base, sh[i].VirtualAddress),
pe_offsetc(bytes, sh[i].PointerToRawData),
sh[i].SizeOfRawData);
memcpy(
pe_offset(base, sh[i].VirtualAddress),
pe_offsetc(bytes, sh[i].PointerToRawData),
sh[i].SizeOfRawData);
}
return base;
@@ -227,16 +242,15 @@ void pe_relocate(HMODULE pe)
delta_va = (intptr_t) pe - nth->OptionalHeader.ImageBase;
dde = nth->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_BASERELOC;
for (chunk = pe_offsetc(pe, dde->VirtualAddress)
; (void *) chunk < pe_offsetc(pe, dde->VirtualAddress + dde->Size)
; chunk = pe_offsetc(chunk, chunk->SizeOfBlock)) {
for (reloc = (uint16_t *) (chunk + 1)
; (void *) reloc < pe_offsetc(chunk, chunk->SizeOfBlock)
; reloc++) {
for (chunk = pe_offsetc(pe, dde->VirtualAddress);
(void *) chunk < pe_offsetc(pe, dde->VirtualAddress + dde->Size);
chunk = pe_offsetc(chunk, chunk->SizeOfBlock)) {
for (reloc = (uint16_t *) (chunk + 1);
(void *) reloc < pe_offsetc(chunk, chunk->SizeOfBlock);
reloc++) {
if (*reloc >> 12 == IMAGE_REL_BASED_HIGHLOW) {
addr_ptr = pe_offset(
pe,
chunk->VirtualAddress + (*reloc & 0x0FFF));
addr_ptr =
pe_offset(pe, chunk->VirtualAddress + (*reloc & 0x0FFF));
*addr_ptr += delta_va;
}
}
@@ -252,16 +266,18 @@ void *pe_get_export(HMODULE pe, const char *name, uint16_t ord)
DWORD i;
nth = pe_get_nt_header(pe);
ied = pe_offsetc(pe, nth->OptionalHeader
.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
ied = pe_offsetc(
pe,
nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]
.VirtualAddress);
name_rvas = pe_offsetc(pe, ied->AddressOfNames);
target_rvas = pe_offsetc(pe, ied->AddressOfFunctions);
if (name != NULL) {
for (i = 0 ; i < ied->NumberOfNames ; i++) {
if (name_rvas[i] != 0
&& strcmp(pe_offsetc(pe, name_rvas[i]), name) == 0) {
for (i = 0; i < ied->NumberOfNames; i++) {
if (name_rvas[i] != 0 &&
strcmp(pe_offsetc(pe, name_rvas[i]), name) == 0) {
return pe_offset(pe, target_rvas[i]);
}
}
+2 -2
View File
@@ -17,8 +17,8 @@ struct pe_iat_entry {
const pe_iid_t *pe_iid_get_first(HMODULE pe);
const char *pe_iid_get_name(HMODULE pe, const pe_iid_t *iid);
const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid);
bool pe_iid_get_iat_entry(HMODULE pe, const pe_iid_t *iid, size_t n,
struct pe_iat_entry *entry);
bool pe_iid_get_iat_entry(
HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry);
void *pe_get_export(HMODULE pe, const char *name, uint16_t ord);
BOOL pe_call_dll_main(HMODULE pe, uint32_t reason, void *ctx);
+3 -4
View File
@@ -13,7 +13,6 @@ static const PEB *peb_get(void)
#else
return (const PEB *) __readfsdword(0x30);
#endif
}
const peb_dll_t *peb_dll_get_first(void)
@@ -42,7 +41,8 @@ const peb_dll_t *peb_dll_get_next(const peb_dll_t *dll)
return containerof(node, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
}
HMODULE peb_dll_get_base(const peb_dll_t *dll)
HMODULE
peb_dll_get_base(const peb_dll_t *dll)
{
return dll->DllBase;
}
@@ -55,7 +55,7 @@ char *peb_dll_dup_name(const peb_dll_t *dll)
wstr = &dll->FullDllName;
for (i = wstr->Length / 2 - 1 ; i > 0 ; i--) {
for (i = wstr->Length / 2 - 1; i > 0; i--) {
if (wstr->Buffer[i] == L'\\') {
wstr_narrow(&wstr->Buffer[i + 1], &name);
@@ -65,4 +65,3 @@ char *peb_dll_dup_name(const peb_dll_t *dll)
return NULL;
}
+22 -33
View File
@@ -11,31 +11,24 @@
#include "util/mem.h"
static void hook_table_apply_to_all(
const char *depname,
const struct hook_symbol *syms,
size_t nsyms);
const char *depname, const struct hook_symbol *syms, size_t nsyms);
static void hook_table_apply_to_iid(
HMODULE target,
const pe_iid_t *iid,
const struct hook_symbol *syms,
size_t nsyms);
HMODULE target,
const pe_iid_t *iid,
const struct hook_symbol *syms,
size_t nsyms);
static bool hook_table_match_proc(
const struct pe_iat_entry *iate,
const struct hook_symbol *sym);
const struct pe_iat_entry *iate, const struct hook_symbol *sym);
static void hook_table_apply_to_all(
const char *depname,
const struct hook_symbol *syms,
size_t nsyms)
const char *depname, const struct hook_symbol *syms, size_t nsyms)
{
const peb_dll_t *dll;
HMODULE pe;
for (dll = peb_dll_get_first()
; dll != NULL
; dll = peb_dll_get_next(dll)) {
for (dll = peb_dll_get_first(); dll != NULL; dll = peb_dll_get_next(dll)) {
pe = peb_dll_get_base(dll);
if (pe == NULL) {
@@ -48,10 +41,10 @@ static void hook_table_apply_to_all(
}
void hook_table_apply(
HMODULE target,
const char *depname,
const struct hook_symbol *syms,
size_t nsyms)
HMODULE target,
const char *depname,
const struct hook_symbol *syms,
size_t nsyms)
{
const pe_iid_t *iid;
const char *iid_name;
@@ -62,9 +55,8 @@ void hook_table_apply(
hook_table_apply_to_all(depname, syms, nsyms);
} else {
for ( iid = pe_iid_get_first(target) ;
iid != NULL ;
iid = pe_iid_get_next(target, iid)) {
for (iid = pe_iid_get_first(target); iid != NULL;
iid = pe_iid_get_next(target, iid)) {
iid_name = pe_iid_get_name(target, iid);
if (_stricmp(iid_name, depname) == 0) {
@@ -75,10 +67,10 @@ void hook_table_apply(
}
static void hook_table_apply_to_iid(
HMODULE target,
const pe_iid_t *iid,
const struct hook_symbol *syms,
size_t nsyms)
HMODULE target,
const pe_iid_t *iid,
const struct hook_symbol *syms,
size_t nsyms)
{
struct pe_iat_entry iate;
size_t i;
@@ -88,7 +80,7 @@ static void hook_table_apply_to_iid(
i = 0;
while (pe_iid_get_iat_entry(target, iid, i++, &iate)) {
for (j = 0 ; j < nsyms ; j++) {
for (j = 0; j < nsyms; j++) {
sym = &syms[j];
if (hook_table_match_proc(&iate, sym)) {
@@ -103,12 +95,10 @@ static void hook_table_apply_to_iid(
}
static bool hook_table_match_proc(
const struct pe_iat_entry *iate,
const struct hook_symbol *sym)
const struct pe_iat_entry *iate, const struct hook_symbol *sym)
{
if ( sym->name != NULL &&
iate->name != NULL &&
strcmp(sym->name, iate->name) == 0) {
if (sym->name != NULL && iate->name != NULL &&
strcmp(sym->name, iate->name) == 0) {
return true;
}
@@ -118,4 +108,3 @@ static bool hook_table_match_proc(
return false;
}
+4 -4
View File
@@ -14,9 +14,9 @@ struct hook_symbol {
};
void hook_table_apply(
HMODULE target,
const char *depname,
const struct hook_symbol *syms,
size_t nsyms);
HMODULE target,
const char *depname,
const struct hook_symbol *syms,
size_t nsyms);
#endif