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 ?