ReactOS 0.4.15-dev-8428-g6910fa6
apitest_iathook.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static PIMAGE_IMPORT_DESCRIPTOR FindImportDescriptor (PBYTE DllBase, PCSTR DllName)
 
static BOOL RedirectIat (HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR NewFunction, ULONG_PTR *OriginalFunction)
 
static BOOL RestoreIat (HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR OriginalFunction)
 

Function Documentation

◆ FindImportDescriptor()

static PIMAGE_IMPORT_DESCRIPTOR FindImportDescriptor ( PBYTE  DllBase,
PCSTR  DllName 
)
static

Definition at line 4 of file apitest_iathook.h.

5{
8 while (ImportDescriptor->Name && ImportDescriptor->OriginalFirstThunk)
9 {
10 PCHAR Name = (PCHAR)(DllBase + ImportDescriptor->Name);
11 if (!lstrcmpiA(Name, DllName))
12 {
13 return ImportDescriptor;
14 }
15 ImportDescriptor++;
16 }
17 return NULL;
18}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4223
#define PCHAR
Definition: match.c:90
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by RedirectIat().

◆ RedirectIat()

static BOOL RedirectIat ( HMODULE  TargetDll,
PCSTR  DllName,
PCSTR  FunctionName,
ULONG_PTR  NewFunction,
ULONG_PTR OriginalFunction 
)
static

Definition at line 20 of file apitest_iathook.h.

21{
22 PBYTE DllBase = (PBYTE)TargetDll;
23 PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor = FindImportDescriptor(DllBase, DllName);
24 if (ImportDescriptor)
25 {
26 // On loaded images, OriginalFirstThunk points to the name / ordinal of the function
27 PIMAGE_THUNK_DATA OriginalThunk = (PIMAGE_THUNK_DATA)(DllBase + ImportDescriptor->OriginalFirstThunk);
28 // FirstThunk points to the resolved address.
29 PIMAGE_THUNK_DATA FirstThunk = (PIMAGE_THUNK_DATA)(DllBase + ImportDescriptor->FirstThunk);
30 while (OriginalThunk->u1.AddressOfData && FirstThunk->u1.Function)
31 {
32 if (!IMAGE_SNAP_BY_ORDINAL32(OriginalThunk->u1.AddressOfData))
33 {
34 PIMAGE_IMPORT_BY_NAME ImportName = (PIMAGE_IMPORT_BY_NAME)(DllBase + OriginalThunk->u1.AddressOfData);
35 if (!lstrcmpiA((PCSTR)ImportName->Name, FunctionName))
36 {
37 DWORD dwOld;
38 VirtualProtect(&FirstThunk->u1.Function, sizeof(ULONG_PTR), PAGE_EXECUTE_READWRITE, &dwOld);
39 *OriginalFunction = FirstThunk->u1.Function;
40 FirstThunk->u1.Function = NewFunction;
41 VirtualProtect(&FirstThunk->u1.Function, sizeof(ULONG_PTR), dwOld, &dwOld);
42 return TRUE;
43 }
44 }
45 OriginalThunk++;
46 FirstThunk++;
47 }
48 skip("Unable to find the Import %s!%s\n", DllName, FunctionName);
49 }
50 else
51 {
52 skip("Unable to find the ImportDescriptor for %s\n", DllName);
53 }
54 return FALSE;
55}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1279
static PIMAGE_IMPORT_DESCRIPTOR FindImportDescriptor(PBYTE DllBase, PCSTR DllName)
#define skip(...)
Definition: atltest.h:64
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define IMAGE_SNAP_BY_ORDINAL32(Ordinal)
Definition: ntimage.h:524
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566
BYTE * PBYTE
Definition: pedump.c:66
struct _IMAGE_IMPORT_BY_NAME * PIMAGE_IMPORT_BY_NAME
union _IMAGE_THUNK_DATA32::@2130 u1
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:135

Referenced by hook_disp(), hook_theme(), RestoreIat(), and test_Sign_Media().

◆ RestoreIat()

static BOOL RestoreIat ( HMODULE  TargetDll,
PCSTR  DllName,
PCSTR  FunctionName,
ULONG_PTR  OriginalFunction 
)
static

Definition at line 57 of file apitest_iathook.h.

58{
59 ULONG_PTR old = 0;
60 return RedirectIat(TargetDll, DllName, FunctionName, OriginalFunction, &old);
61}
static BOOL RedirectIat(HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR NewFunction, ULONG_PTR *OriginalFunction)

Referenced by test_Sign_Media(), unhook_disp(), and unhook_theme().