Использование easyhook для подключения списка функций Windows API в Stack Overflow

Я работаю над проектом, который включает в себя подключение нескольких функций Windows API с помощью easyhook с C ++.

Когда дело доходит до перехвата нескольких функций, я считаю, что мой код неверен.

Результаты моего кода правильные, но я уверен, что я не реализовал его должным образом, поскольку получаю сообщение «Хук успешно установлен» 121 (11 * 11) раз вместо 11.

Причина, по которой это происходит, заключается в том, что я вызываю функцию RhInjectLibrary () 11 раз, когда каждый вызов заставляет мой dll-код устанавливать 11 перехватчиков.

Так что я предполагаю, что либо мне нужно изменить код инжектора, чтобы он вызывал RhInjectLibrary () только один раз, либо мне нужно изменить мой dll на несколько, чтобы узнать, какой хук он должен установить в текущем вызове.

Вот мой соответствующий код инжектора:

int _tmain(int argc, _TCHAR* argv[])
{

DWORD processId;
std::wcout << "Enter the target process Id: ";
std::cin >> processId;
WCHAR* dllToInject = L"..\\..\\dllToInject\\Debug\\dllToInject.dll";
wprintf(L"Attempting to inject dll in path: %s\n\n", dllToInject);
injectAllDifferentParameters(processId, dllToInject);

take50ScreenShotsEvery5Seconds();
system("PAUSE");
return 0;
}
void chechIfDllWasInjectedSuccessfully(NTSTATUS nt)//print if an error accourd loading our dll
{
if (nt != 0)
{
printf("RhInjectLibrary failed with error code = %d\n", nt);
PWCHAR err = RtlGetLastErrorString();
std::wcout << err << "\n";
}
else    std::wcout << L"Library injected successfully.\n";
}
void injectDll(DWORD pid, WCHAR* DllToInject32, PVOID* parametrs)//this function is injecting a 32 bit DLL!
{
//creating struct that can "carry" all parameters:
NTSTATUS nt = RhInjectLibrary(
pid,   // The process to inject into
0,           // ThreadId to wake up upon injection
EASYHOOK_INJECT_DEFAULT,
DllToInject32, // 32-bit
NULL,        // 64-bit not provided
parametrs, // data to send to injected DLL entry point
sizeof(parametrs) + 1// size of data to send
);
chechIfDllWasInjectedSuccessfully(nt);
}
void injectAllDifferentParameters(DWORD pid, WCHAR* dllToInject)
{
//create PVOID pointers to struct of parameters:
std::vector<PVOID*> functionsParameters;
functionsParameters.push_back((PVOID*)((new CreateFileParameters())));
functionsParameters.push_back((PVOID*)((new setRegistreyFunctionPatameters())));
functionsParameters.push_back((PVOID*)((new CreateToolhelp32SnapshotParameters())));
functionsParameters.push_back((PVOID*)((new Process32FirstParameters())));
functionsParameters.push_back((PVOID*)((new Process32NextParameters())));
functionsParameters.push_back((PVOID*)((new VirtualAllocExParameters())));
functionsParameters.push_back((PVOID*)((new VirtualAllocParameters())));
functionsParameters.push_back((PVOID*)((new OpenProcessParameters())));
functionsParameters.push_back((PVOID*)((new WriteProcessMemoryParameters())));
functionsParameters.push_back((PVOID*)((new CreateRemoteThreadParameters())));
functionsParameters.push_back((PVOID*)((new CreateRemoteThreadExParameters())));

const int SIZE = functionsParameters.size();
//injectOurDll to the process:
for (unsigned int i = 0; i < SIZE; i++) injectDll(pid, dllToInject, functionsParameters[i]);

//free memory:
for (unsigned int i = 0; i < SIZE; i++) delete functionsParameters[i];
}

и вот мой DLL соответствующий код:

void __stdcall NativeInjectionEntryPoint(REMOTE_ENTRY_INFO* inRemoteInfo)//this code excecutes when we call injectDll() in the injector process.
{
std::cout << "\n\nNativeInjectionEntryPointt(REMOTE_ENTRY_INFO* inRemoteInfo)\n\n" <<
"IIIII           jjj               tt                dd !!! \n"" III  nn nnn        eeee   ccccc tt      eee       dd !!! \n"" III  nnn  nn   jjj ee   e cc     tttt  ee   e  dddddd !!! \n"" III  nn   nn   jjj eeeee  cc     tt    eeeee  dd   dd     \n""IIIII nn   nn   jjj  eeeee  ccccc  tttt  eeeee  dddddd !!! \n""              jjjj                                         \n\n";

std::cout << "Injected by process Id: " << inRemoteInfo->HostPID << "\n";
std::cout << "Passed in data size: " << inRemoteInfo->UserDataSize << "\n";
std::cout << "userData: " << inRemoteInfo->UserData << "\n";
installHook(TEXT("Advapi32"), LPCSTR("RegSetValueExA"), mySetReg);
installHook(TEXT("Kernel32"), LPCSTR("CreateFileA"), MyCreateFile);
installHook(TEXT("Kernel32"), LPCSTR("CreateToolhelp32Snapshot"), myCreateToolhelp32Snapshot);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("Process32First"), myProcess32First);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("Process32Next"), myProcess32Next);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("VirtualAllocEx"), myVirtualAllocEx);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("VirtualAlloc"), myVirtualAlloc);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("OpenProcess"), myOpenProcess);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("WriteProcessMemory"), myWriteProcessMemory);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("CreateRemoteThread"), myCreateRemoteThread);//add A/W ?
installHook(TEXT("Kernel32"), LPCSTR("CreateRemoteThreadEx"), myCreateRemoteThreadEx);//add A/W ?
return;
}
void checkForValidInstallOfHook(NTSTATUS nt)
{
if (FAILED(nt))
{
std::wstring s(RtlGetLastErrorString());
std::wcout << "Failed to install hook: \n";
std::wcout << s;
}
else
{
std::cout << "Hook installed successfully!\n";
}

}
void installHook(LPTSTR dll, LPCSTR funcToHook, void* func)
{
// Perform hooking
HOOK_TRACE_INFO hHook = { NULL }; // keep track of our hook
// Install the hook
NTSTATUS result = LhInstallHook(
GetProcAddress(GetModuleHandle(dll), funcToHook),
func,
NULL,
&hHook);
checkForValidInstallOfHook(result);
// If the threadId in the ACL is set to 0,
// then internally EasyHook uses GetCurrentThreadId()
ULONG ACLEntries[1] = { 0 };

// Disable the hook for the provided threadIds, enable for all others
LhSetExclusiveACL(ACLEntries, 1, &hHook);
}

Вся тема подключения является новой для меня .. Спасибо!

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector