Memory reading not working when hooking WIN32 API functions

171 views Asked by At

I'm trying to inject the DLL into my other program and hook the win32 API function SetConsoleTitle so I can read what parameters are being passed. Everything seems to work except that the strings appear to be unreadable.

When I was hooking my function (non winapi) everything worked just fine.

SetConsoleTitle export and hooked functions:

typedef BOOL(WINAPI* SetConsole)(LPCTSTR str);

BOOL SetConsoleHooked(LPCTSTR str)
{
    //im checking the string here in the vs debugger

    SetConsole s = (SetConsole)ConsoleAddress;
    return s(str);
}

"Error reading characters of string"

The string is showing as nonreadable and I don't know how to access it.

And here is my DLLMain function:

BOOL WINAPI DllMain(
    HINSTANCE hinstDLL,  // handle to DLL module
    DWORD fdwReason,     // reason for calling function
    LPVOID lpvReserved)  // reserved
{
    if (fdwReason == DLL_PROCESS_ATTACH)
    {
        HMODULE hModule = GetModuleHandle(L"SomeFile.exe");

        HandleAddress = (DWORD)hModule + (DWORD)0x51D05;
        ConsoleAddress = (DWORD)hModule + (DWORD)0x55ACA;

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());

        DetourAttach(&(LPVOID&)ConsoleAddress, &SetConsoleHooked);

        DetourTransactionCommit();
        while (true) {}

        return true;
    }
}

And lastly function from IDA that I've been trying to hook

0

There are 0 answers