0

I've got an application(made by myself) and now I decided I want to try some hooking.

So the function I'm trying to hook looks like this:

void PrintMessage(const char* c_szFormat, ...)
{
    char szBuf[1024 + 2];

    strncpy_s(szBuf, "I got: ", 1024);

    int len = strlen(szBuf);

    va_list args;
    va_start(args, c_szFormat);

    len = _vsnprintf(szBuf + len, sizeof(szBuf) - (len + 1), c_szFormat, args) + len;


    va_end(args);

    szBuf[len] = '\n';
    szBuf[len + 1] = '\0';
    fprintf(stderr, "%s", szBuf);
}

I've successfully found the function at ida pro it looks like this: http://prntscr.com/s6esam

Can someone explain me why it's showing the function as integer instead of void? I understand that const char* is being showed as pointer int a1 in my case.

Also I tried to hook it by the address 0x512550

This is my code

#include <windows.h>
#include "pch.h"
#include <iostream>
#include "detours.h"

int(* originalCall)(const char*, ...); 

int hookedFunction(const char* a1, ...)
{
    MessageBoxA(NULL, "", "Function called", MB_OK);
    return originalCall("Hooked %s", "test");
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
    switch (dwReason)
    {
    case DLL_PROCESS_ATTACH:
        MessageBoxA(NULL, "", "Hook set", MB_OK);
        originalCall = (int(*)(const char*, ...))DetourFunction((PBYTE)0x512550, (PBYTE)hookedFunction);
        break;
    }
    return TRUE;
}

But I got no luck it isn't working, can someone tell me some tips or clues on how do I continue ?

Dennis
  • 19
  • 5
  • It shows as `int` because it can't be sure that the value in register `rax` at the end won't be used. You can press `Y` in IDA to change the function signature and then change it to `void` there. – CherryDT Apr 27 '20 at 00:03
  • Also, in what way is it not working? What happens instead? If you look at a call to the supposedly hooked function as well as the function implementation's first few bytes in IDA's debugger at runtime, what do you see? – CherryDT Apr 27 '20 at 00:06
  • I already know that, but my question is, why I can't set a hook? Actually I'm being able to set it but it's not working, do you have any clues on that? – Dennis Apr 27 '20 at 00:08

0 Answers0