Global Hook
-
Meinst du sowas: ClickMe
Ja, das ist genau das was ich gesucht habe :p
Nur leider scheint der Code nicht so zu funktionieren wie ich will,
mein Compiler gefällt der Typ "Export" vor den beiden Funktionen nicht,
wenn ich es weglasse, klagt er darüber, dass kein Identifier vorhanden sei,
gibt es iergendwo in der Form ein Demo-Projekt?Vielen Dank schonmal für deine Hilfe
@ CodeFinder
-
Jens.S schrieb:
[...]
Nur leider scheint der Code nicht so zu funktionieren wie ich will,
mein Compiler gefällt der Typ "Export" vor den beiden Funktionen nicht,
wenn ich es weglasse, klagt er darüber, dass kein Identifier vorhanden sei
[...]Was hast du denn für 'n Compiler ?
-
CodeFinder schrieb:
Jens.S schrieb:
[...]
Nur leider scheint der Code nicht so zu funktionieren wie ich will,
mein Compiler gefällt der Typ "Export" vor den beiden Funktionen nicht,
wenn ich es weglasse, klagt er darüber, dass kein Identifier vorhanden sei
[...]Was hast du denn für 'n Compiler ?
Mircrosoft Windows Visual Studio C++ 2005
-
Werd ich nachher mal asuprobieren, hab atm keine Zeit...hassu den alles richtig eingebunden und
auch ein Win32-DLL-Projekt erstellt ?Siehe
http://www.c-plusplus.net/forum/viewtopic-var-t-is-143003.html
-
Habe jetzt alles nochmal neu gemacht und er compiliert es jetzt

Es funktioniert leider immernoch nicht alles:#include "stdafx.h" #include "hook.h" #include <iostream> #include <windows.h> #ifdef _MANAGED #pragma managed(push, off) #endif HWND hWindow = 0 ; LRESULT CALLBACK KeyboardHookProc (int, WPARAM, LPARAM) ; // Der Prototyp der Funktion KeyboardHookProc HHOOK hhkHook ; HINSTANCE hDllInstance ; int APIENTRY DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved){ switch (fdwReason){ case DLL_PROCESS_ATTACH : hDllInstance = hInstance ; // Wenn ich hier nen Exit(0); setze, schließt sich Notepad automatisch (ich injiziere in Notepad) break ; } return TRUE ; } EXPORT BOOL CALLBACK SetupHook (HWND hParent){ hWindow = hParent ; // Initialisierung der globalen Variable mit dem Eingabe Parameter hhkHook = SetWindowsHookEx (WH_KEYBOARD, KeyboardHookProc, hDllInstance, NULL) ; // Keyboardhook setzen und das Ergebnis in der globalen Variable // hhkHook speichern. return TRUE ; } LRESULT CALLBACK KeyboardHookProc (int nCode, WPARAM wParam, LPARAM lParam){ Beep(1000, 1000); // Aha, die Funktion wurde aufgerufen ( es piept ) if (nCode == HC_ACTION){ if ((lParam & 1073741824) != 1073741824){ SendMessage ((HWND) hWindow, (WM_USER + 2), (WPARAM) wParam, (LPARAM) lParam) ; } } return CallNextHookEx (hhkHook, nCode, wParam, lParam) ; } EXPORT BOOL CALLBACK UninstallHook (void){ UnhookWindowsHookEx (hhkHook) ; return TRUE ; }Da ich mit Exit(0); überprüft habe ob die DLL Befehle ausführt (siehe Kommentare im Code) habe ich sichergestellt, das ich auch Tatsächlich in Notepad Commands ausführen kann,
Leider Piept mein Pc nicht bei jeder Tasteneingabe, dies sollte aber der Fall sein da bei jeder Tasteneingabe meine Hookfunktion aufgerufen werden sollte, dieBeep(1000, 1000); // Aha, die Funktion wurde aufgerufen ( es piept )beinhaltet.

-
Niemand will helfen?

-
Version 2:
#include "stdafx.h" #include "hook.h" #include <iostream> #include <windows.h> #ifdef _MANAGED #pragma managed(push, off) #endif #pragma data_seg ("Shared") HWND hWindow = 0 ; #pragma data_seg () #pragma comment (linker, "/section:Shared,RWS") LRESULT CALLBACK KeyboardHookProc (int, WPARAM, LPARAM) ; // Der Prototyp der Funktion KeyboardHookProc HHOOK hhkHook ; HINSTANCE hDllInstance ; int APIENTRY DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved){ hDllInstance = hInstance ; MessageBox(NULL,"DllMain was called!","DllMain",MB_OK); return TRUE ; } EXPORT BOOL CALLBACK SetupHook (HWND hParent){ Beep(100, 100); hWindow = hParent ; // Initialisierung der globalen Variable mit dem Eingabe Parameter hhkHook = SetWindowsHookEx (WH_KEYBOARD, KeyboardHookProc, hDllInstance, NULL) ; if(hhkHook == NULL){ Beep(100, 1000000); Sleep(2000); exit(0); } if(hhkHook != NULL) MessageBox(NULL,"Hook installed!","Hook",MB_OK); // Keyboardhook setzen und das Ergebnis in der globalen Variable // hhkHook speichern. return TRUE ; } LRESULT CALLBACK KeyboardHookProc (int nCode, WPARAM wParam, LPARAM lParam){ if (nCode < 0) return CallNextHookEx (hhkHook, nCode, wParam, lParam) ; if(nCode == VK_HOME) // wenn tab gedrückt { MessageBox(NULL,"Home key recieved!","Hook",MB_OK); } return CallNextHookEx (hhkHook, nCode, wParam, lParam) ; } EXPORT BOOL CALLBACK UninstallHook (void){ UnhookWindowsHookEx (hhkHook) ; return TRUE ; } #ifdef _MANAGED #pragma managed(pop) #endifHook.h:
#ifdef __cplusplus #define EXPORT extern "C" __declspec (dllexport) #else #define EXPORT __declspec (dllexport) #endif // Funktonalität sowohl unter C als auch unter C++ gegeben EXPORT BOOL CALLBACK SetupHook (HWND) ; EXPORT BOOL CALLBACK UninstallHook (void) ;Output: "DllMain was called." "DllMain was called." "DllMain was called." //nix passiert... ich beende das Programm "DllMain was called." //Programm ausDer Hook wird nichtmal aufgerufen...
-
Zeig mal den Code der die DLL lädt bzw. den Hook startet.
-
tja da willste ja gleich mein bestes Stück sehen

#include <windows.h> #include <iostream> #include <winuser.h> using namespace std; HINSTANCE hInst; void EnableDebugPriv(); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { hInst = hInstance; HWND hwar3=FindWindow(NULL,"Unbenannt - Editor"); if(!hwar3) { if(MessageBox(0,"Bitte Notepad starten, bevor die DLL geladen wird!","DLL Loader",MB_OK)==IDOK) return 0; } EnableDebugPriv(); DWORD PID,TID; TID = GetWindowThreadProcessId (hwar3, &PID); //Open wc3 process HANDLE hProcess=OpenProcess( PROCESS_ALL_ACCESS,FALSE,PID); HANDLE hThread; //Inject DLL full path char szLibPath [_MAX_PATH]; if( !GetCurrentDirectory(_MAX_PATH,szLibPath)) return 0; //DLL name strcat(szLibPath, "\\hook.dll"); void* pLibRemote; DWORD hLibModule = 0; HMODULE hKernel32 = GetModuleHandle("Kernel32"); pLibRemote = VirtualAllocEx( hProcess, NULL, sizeof(szLibPath), MEM_COMMIT, PAGE_READWRITE ); WriteProcessMemory( hProcess, pLibRemote, (void*)szLibPath, sizeof(szLibPath), NULL ); hThread = CreateRemoteThread( hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) GetProcAddress( hKernel32,"LoadLibraryA" ), pLibRemote, 0, NULL ); if( hThread ) { MessageBox(0,"DLL wurde erfolgreich in Notepad injiziert.","",MB_OK); WaitForSingleObject( hThread, INFINITE ); GetExitCodeThread( hThread, &hLibModule ); CloseHandle( hThread ); VirtualFreeEx( hProcess, pLibRemote, sizeof(szLibPath), MEM_RELEASE ); if( hLibModule != NULL ) { hThread = CreateRemoteThread( hProcess,NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32,"FreeLibrary"), pLibRemote,0, NULL ); if( hThread != NULL ) { WaitForSingleObject( hThread, INFINITE ); GetExitCodeThread( hThread, &hLibModule ); CloseHandle( hThread ); } } } else { if(MessageBox(0,"Fehler beim Injizieren, bitte erneut probieren! (Kein Windows XP!?)","",MB_OK)==IDOK) return 0; } CloseHandle(hProcess); return 0; } void EnableDebugPriv() { HANDLE hToken; LUID sedebugnameValue; TOKEN_PRIVILEGES tkp; if ( ! OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) ) return; if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){ CloseHandle( hToken ); return; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Luid = sedebugnameValue; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) ) CloseHandle( hToken ); }
-
Hmmm suche jetzt seit 4 Tagen eine Lösung auf dieses Problem,
dabei ist ein Hook doch eine Grundlage von c++
Ihr habt ja auch alle code-resourcen von mir.
Könntet ihr es nich einmal bei euch compilieren
und gucken woran es liegt?Vielen Dank schonmal!
-
ein letztes mal hole ich es noch nach oben,
sonst werd ich das Projekt aufgeben