I'm doing an example with api hooking since I'm writing an article about it input I find the following errors:
Dynamic.cpp:8:30: error: 'typedef void (* SendMessageW)()' redeclared as differe nt kind of symbol
typedef void (*SendMessageW)();//Typedef for the hooked function
^
In file included from C:/msys32/mingw32/i686-w64-mingw32/include/windows.h:72:0,
from C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\ include\MinHook.h:35,
from Dynamic.cpp:1:
C:/msys32/mingw32/i686-w64-mingw32/include/winuser.h:1981:29: note: previous dec laration 'LRESULT SendMessageW(HWND, UINT, WPARAM, LPARAM)'
WINUSERAPI LRESULT WINAPI SendMessageW(HWND hWnd,UINT Msg,WPARAM wParam,LPARA M lParam);
^~~~~~~~~~~~
Dynamic.cpp:9:8: error: 'SendMessageW' does not name a type
static SendMessageW Basewritefoobar;//Backup of the originak fonction
^~~~~~~~~~~~
Dynamic.cpp:13:16: warning: 'LRESULT SendMessageW(HWND, UINT, WPARAM, LPARAM)' r edeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
LRESULT WINAPI SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
^~~~~~~~~~~~
Dynamic.cpp: In function 'bool Hook()':
Dynamic.cpp:64:73: error: 'Basewritefoobar' was not declared in this scope
if (MH_CreateHookEx((void*)&SendMessageW, (void*)&BSSSendMessageW, &Basewri tefoobar) != MH_OK)
^~~~~~~ ~~~~~~~~
The code of my program:
#include "C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h"//MHook header
#include <iostream>
#include <windows.h>
#include <Commctrl.h>
#include <conio.h>//For getch
using namespace std;
typedef void (*SendMessageW)();//Typedef for the hooked function
static SendMessageW Basewritefoobar;//Backup of the originak fonction
LRESULT WINAPI SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
static const wchar_t *hiddenprocess=L"tusitio";
LRESULT WINAPI BSSSendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if ( msg == LVM_INSERTITEMW || msg == LVM_SETITEMW)//Intercepts LVM_INSERTITEM and LVM_SETITEM messages
{
if (!lstrcmpW(((LVITEMW*)lparam)->pszText, hiddenprocess))//The lparam is a LVITEM* struct.
{
return 0;//If the item name is the same as process we want to hide, we simply return 0 (and we do not call the real SendMessage function.
}
return 0;
}
return SendMessage(hwnd, msg, wparam, lparam);//Calls the real SendMessage function.
}
//void Writefoobar();//Original function
//void Hookedwritefoobar();//Original function's redirection
static bool Hook();
template <typename T>
inline MH_STATUS MH_CreateHookEx(void* target, void* const base, T** original)
{
return MH_CreateHook(target, base, reinterpret_cast<void**>(original));
}
int main()
{
if (!Hook())//Hook "Writefoobar"
{
cout << "Hook failed" << endl;
return 1;
}
//Writefoobar();//Standard call to Writefoobar, but instead, Hookedwritefoobar will be executed
cout << "Press a key to exit" << endl;
_getch();
return 0;
}
bool Hook()
{
if (MH_Initialize() != MH_OK)
{
return false;
}
if (MH_CreateHookEx((void*)&SendMessageW, (void*)&BSSSendMessageW, &Basewritefoobar) != MH_OK)
{
return FALSE;
}
return MH_EnableHook((void*)&SendMessageW) == MH_OK;
}
I am using api hooking and the minhook library. Reference: Minhook Library
And if the purposes are purely ethical, write an article about it related to security.
You can't declare a function pointer alias that has the same name as a function...(and having the same declaration).
You can choose to wrap the alias in a
namespace
or rename it so it doesn't match the function you import from WinAPI.I can't tell you anything about the last error because you haven't included the corresponding code.