The startInjection function calls the MapModuleToProcess function to implement the injection of HookLibrary.dll,But the MapModuleToProcess function first maps the HookLibrary.dll into its own memory and resolves the import table,and then uses WriteProcessMemory to write the resolved image to the target process.At this time, shouldn't the function address pointed to by FirstThunk belong to the InjectorCLI process? Why can HookLibrary.dll be executed normally in the target process?The function address of the dll used by the HookLibrary.dll may be different in the two processes.
HookLibrary only imports NTDLL functions. NTDLL is always mapped at the same location in every running process. This is also the case for Kernel32.dll.
The
startInjection
function calls theMapModuleToProcess
function to implement the injection ofHookLibrary.dll
,But theMapModuleToProcess
function first maps theHookLibrary.dll
into its own memory and resolves the import table,and then usesWriteProcessMemory
to write the resolved image to the target process.At this time, shouldn't the function address pointed to byFirstThunk
belong to theInjectorCLI
process? Why canHookLibrary.dll
be executed normally in the target process?The function address of the dll used by theHookLibrary.dll
may be different in the two processes.ResolveImports((PIMAGE_IMPORT_DESCRIPTOR)((DWORD_PTR)imageLocal + pNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress), (DWORD_PTR)imageLocal);
SIZE_T skipBytes = wipeHeaders ? pNtHeader->OptionalHeader.SizeOfHeaders : 0;
(WriteProcessMemory(hProcess, (PVOID)((ULONG_PTR)imageRemote + skipBytes), (PVOID)((ULONG_PTR)imageLocal + skipBytes)