warning C4273,Inkonsistente DLL-Bindung



  • hey Leute,
    mein der zeitiges Project bezieht sich auf dll injection,
    allerdings bekomme ich immer folgende Warnung beim compilieren:

    dllmain.cpp(13): warning C4273: 'GetUserNameA': Inkonsistente DLL-Bindung.
              C:\Programme\Microsoft SDKs\Windows\v7.0A\include\winbase.h(12659): Siehe vorherige Definition von 'GetUserNameA'
    

    es sieht so aus als wenn vs die "Exports.def" nicht findet....ich weiß nicht warum das so ist deswegen hoffe ich das mir hier jemand einen kleinen tip geben kann 🙂

    hier mal der rest meines src

    DllMain.cpp

    #include "stdafx.h"
    #include "LunaCore.h"
    
    HMODULE libraryHandle;
    
    _declspec(dllexport) BOOL WINAPI GetUserNameA(LPSTR input, LPDWORD buffer)
    {
        typedef BOOL (WINAPI* CFunction)(LPSTR input,LPDWORD buffer);
        CFunction getUserName = (CFunction)GetProcAddress(libraryHandle, "GetUserNameA");
        return getUserName(input, buffer);
    }
    
    BOOL WINAPI DllMain(HMODULE module,DWORD action,LPVOID reserved)
    {
        libraryHandle = LoadLibraryA("ADVAPI32.dll");
    
        Darn::LunaCore *hook = new Darn::LunaCore();
        switch(action)
        {
            case DLL_PROCESS_ATTACH:
                hook->Attach();
            break;
            case DLL_THREAD_ATTACH:
                hook->Detach();
            break;
        }
        return true;
    }
    

    LunaCore.cpp

    #include "stdafx.h"
    #include "LunaCore.h"
    
    namespace Darn
    
    {
        void LunaCore::Attach()
        {
           this->DisableExperienceLoss();
        }
    
        void LunaCore::Detach()
        {
        }
    
        ///
        ///    Disable experience loss when dying. 
        ///
        void LunaCore::DisableExperienceLoss()      
        {
            unsigned char myCode[4] = {0xC2, 0x04, 0x00, 0x90};
            this->MemoryCopy((DWORD)0x004643A0,(DWORD)&myCode,4);
        }
    
        LPVOID LunaCore::MemoryCopy(DWORD destination, DWORD source, int length)
        {
            DWORD oldSource      = 0;
            DWORD oldDestination = 0;
    
            VirtualProtect((LPVOID)source,length,PAGE_EXECUTE_READWRITE,&oldSource);
             VirtualProtect((LPVOID)destination,length,PAGE_EXECUTE_READWRITE,&oldDestination);
    
            memcpy((void*)destination,(void*)source,length);
    
            VirtualProtect((LPVOID)destination,length,oldDestination,&oldDestination);
            VirtualProtect((LPVOID)source,length,oldSource,&oldSource);
    
            return (LPVOID)destination;
        };
    
        DWORD LunaCore::Intercept(int instruction, DWORD source, DWORD destination, int length)
        {
            DWORD realTarget;
            LPBYTE buffer = new BYTE[length];
    
            memset(buffer,0x90,length); 
    
            if(instruction != INST_NOP && length >= 5)
            {
                buffer[(length-5)] = instruction;
                DWORD dwJMP = (DWORD)destination - (source + 5 + (length-5));
                memcpy(&realTarget,(void*)(source+1),4);
                realTarget = realTarget + source + 5;
                memcpy(buffer + 1 + (length - 5),&dwJMP,4);
            }
    
            if(instruction == SHORT_JZ)
            {
                buffer[0] = instruction;
                buffer[1] = (BYTE)destination;
            }
    
            if(instruction == INST_BYTE)
            {
                buffer[0] = (BYTE)destination;
            }
    
            this->MemoryCopy(source,(DWORD)buffer,length);
            delete[] buffer;
    
            return realTarget;
        }
    }
    

    LunaCore.h

    #define INST_NOP  0x90
    #define INST_CALL 0xE8
    #define INST_JMP  0xE9
    #define INST_BYTE 0x00
    #define SHORT_JZ  0x74
    
    namespace Darn
    {    
        class LunaCore
        {
            public:
                void Attach();
                void Detach();
                void DisableExperienceLoss();
    
            private:
                LPVOID MemoryCopy(DWORD destination, DWORD source, int length);
                DWORD Intercept(int instruction, DWORD source, DWORD destination, int length);
        };
    };
    

    Exports.def

    LIBRARY    "LunaCore"
    EXPORTS
        GetUserNameA
        DllMain
    

    Bild von Linker Einstellungen
    http://666kb.com/i/cauzr7odlo1ryzh9m.png



  • GetUserNameA ist eine Funktion der WinAPI die in der advapi32.dll implementiert ist.
    In irgend einem Windows Header-File steht daher auch ein Prototyp für GetUserNameA der mit __declspec(dllimport) versehen ist.

    Dort steht also "importiere das bitte" und du definierst die Funktion dann nochmal mit dllexport , also "exportiere das bitte". Und das ist widersprüchlich. Und daher schreibt dir der Compiler ne Warnung raus.

    Davon abgesehen darfst du in der DllMain soweit ich weiss LoadLibrary nicht aufrufen.



  • [quote="hustbaerDavon abgesehen darfst du in der DllMain soweit ich weiss LoadLibrary nicht aufrufen.[/quote]

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx



  • Ahja, danke.
    Nochmal für Lesefaule

    MSDN schrieb:

    The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order.



  • void LunaCore::DisableExperienceLoss()      
        {
            unsigned char myCode[4] = {0xC2, 0x04, 0x00, 0x90};
            this->MemoryCopy((DWORD)0x004643A0,(DWORD)&myCode,4);
        }
    

    Dieser part solltest Du auch nochmal überdenken (hardcoded address).


Anmelden zum Antworten