mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 20:05:41 +00:00
Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers into modules, and delete rossubsys.
This commit is contained in:
parent
b94e2d8ca0
commit
c2c66aff7d
24198 changed files with 0 additions and 37285 deletions
64
modules/rostests/apitests/include/apitest_iathook.h
Normal file
64
modules/rostests/apitests/include/apitest_iathook.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef _APITEST_IATHOOK_H
|
||||
#define _APITEST_IATHOOK_H
|
||||
|
||||
static PIMAGE_IMPORT_DESCRIPTOR FindImportDescriptor(PBYTE DllBase, PCSTR DllName)
|
||||
{
|
||||
ULONG Size;
|
||||
PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor = RtlImageDirectoryEntryToData((HMODULE)DllBase, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &Size);
|
||||
while (ImportDescriptor->Name && ImportDescriptor->OriginalFirstThunk)
|
||||
{
|
||||
PCHAR Name = (PCHAR)(DllBase + ImportDescriptor->Name);
|
||||
if (!lstrcmpiA(Name, DllName))
|
||||
{
|
||||
return ImportDescriptor;
|
||||
}
|
||||
ImportDescriptor++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL RedirectIat(HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR NewFunction, ULONG_PTR* OriginalFunction)
|
||||
{
|
||||
PBYTE DllBase = (PBYTE)TargetDll;
|
||||
PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor = FindImportDescriptor(DllBase, DllName);
|
||||
if (ImportDescriptor)
|
||||
{
|
||||
// On loaded images, OriginalFirstThunk points to the name / ordinal of the function
|
||||
PIMAGE_THUNK_DATA OriginalThunk = (PIMAGE_THUNK_DATA)(DllBase + ImportDescriptor->OriginalFirstThunk);
|
||||
// FirstThunk points to the resolved address.
|
||||
PIMAGE_THUNK_DATA FirstThunk = (PIMAGE_THUNK_DATA)(DllBase + ImportDescriptor->FirstThunk);
|
||||
while (OriginalThunk->u1.AddressOfData && FirstThunk->u1.Function)
|
||||
{
|
||||
if (!IMAGE_SNAP_BY_ORDINAL32(OriginalThunk->u1.AddressOfData))
|
||||
{
|
||||
PIMAGE_IMPORT_BY_NAME ImportName = (PIMAGE_IMPORT_BY_NAME)(DllBase + OriginalThunk->u1.AddressOfData);
|
||||
if (!lstrcmpiA((PCSTR)ImportName->Name, FunctionName))
|
||||
{
|
||||
DWORD dwOld;
|
||||
VirtualProtect(&FirstThunk->u1.Function, sizeof(ULONG_PTR), PAGE_EXECUTE_READWRITE, &dwOld);
|
||||
*OriginalFunction = FirstThunk->u1.Function;
|
||||
FirstThunk->u1.Function = NewFunction;
|
||||
VirtualProtect(&FirstThunk->u1.Function, sizeof(ULONG_PTR), dwOld, &dwOld);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
OriginalThunk++;
|
||||
FirstThunk++;
|
||||
}
|
||||
skip("Unable to find the Import %s!%s\n", DllName, FunctionName);
|
||||
}
|
||||
else
|
||||
{
|
||||
skip("Unable to find the ImportDescriptor for %s\n", DllName);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL RestoreIat(HMODULE TargetDll, PCSTR DllName, PCSTR FunctionName, ULONG_PTR OriginalFunction)
|
||||
{
|
||||
ULONG_PTR old = 0;
|
||||
return RedirectIat(TargetDll, DllName, FunctionName, OriginalFunction, &old);
|
||||
}
|
||||
|
||||
#endif // _APITEST_IATHOOK_H
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue