|
-
January 16th, 2009, 10:22 PM
#1
sample source MessageBox API Hook
i am trying Hook API,are you help me???,source or code
-
January 17th, 2009, 11:06 AM
#2
Re: sample source MessageBox API Hook
Click on "Search" on Google or Google Groups.
Hundreds of complete samples... (C, C++, asm Win32, etc)
-
January 18th, 2009, 05:04 AM
#3
Re: sample source MessageBox API Hook
It's not very clear what exactly you want to accomplish.
However, I hope this article from Codeguru can be a good starting point: Fancy Custom MessageBox.
-
January 28th, 2009, 11:01 PM
#4
Re: sample source MessageBox API Hook
Here is a sample of hooking MessageBox using Microsoft's Microsoft Detours
Code:
#pragma comment(lib, "detours.lib")
#pragma comment(lib, "detoured.lib")
#pragma comment(lib, "user32.lib")
#include <windows.h>
#include <stdio.h>
#include "detours.h"
#define ID_BUTTONMESSAGE 200
INT (WINAPI * trueMessageBox)(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) = MessageBox;
INT WINAPI hookedMessageBox(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
LPCSTR lpNewCaption = "You've been hijacked";
int iReturn = trueMessageBox(hWnd, lpText, lpNewCaption, uType);
return iReturn;
}
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
VOID SetupDetour(void)
{
DWORD dwError;
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)trueMessageBox, hookedMessageBox);
dwError = DetourTransactionCommit();
if (dwError == NO_ERROR)
MessageBox(NULL, "MessageBox hook installed successfully", "HOOK", MB_OK);
else
MessageBox(NULL, "MessageBox hook installation failed", "Error", MB_OK);
}
INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("MessageBox Hook") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetSysColorBrush(COLOR_3DFACE) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName,
TEXT ("MessageBox Hook"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
700,
300,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
CreateWindow( "button", "Display MessageBox",
WS_VISIBLE | WS_CHILD ,
200, 50, 180, 25,
hwnd, (HMENU) ID_BUTTONMESSAGE, NULL, NULL);
SetupDetour();
return 0 ;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_BUTTONMESSAGE:
MessageBox(hwnd, "This is a test of the hook, note caption", "Test", MB_OK);
break;
}
break;;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
-
January 29th, 2009, 03:36 AM
#5
Re: sample source MessageBox API Hook
-
January 23rd, 2012, 06:21 PM
#6
Re: sample source MessageBox API Hook
@BobS0327 Hi I managed to get the above code working, though I would like to know if there is a way to make this work across different processes e.g. notepad.exe?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|