Last active
September 23, 2015 21:46
-
-
Save kumatti1/3dd953e6272f176469bb to your computer and use it in GitHub Desktop.
APIフック
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define UNICODE | |
| #include <windows.h> | |
| #include <stdio.h> | |
| DWORD OldProtect; | |
| BYTE tmp[6]; | |
| BYTE ByteAsm[6]; | |
| DWORD * pFunc; | |
| int WINAPI Hook_MessageBoxA( | |
| _In_opt_ HWND hWnd, | |
| _In_opt_ LPCTSTR lpText, | |
| _In_opt_ LPCTSTR lpCaption, | |
| _In_ UINT uType | |
| ) | |
| { | |
| MessageBoxW(0, L"", L"foo", MB_OK); | |
| return 0; | |
| } | |
| void StarteHook() | |
| { | |
| HMODULE hDll = GetModuleHandleW(L"user32.dll"); | |
| pFunc = (DWORD*)GetProcAddress(hDll, "MessageBoxA"); | |
| if (VirtualProtect(pFunc, 6, PAGE_EXECUTE_READWRITE, &OldProtect)) | |
| { | |
| memcpy(tmp, pFunc, 6); | |
| ByteAsm[0] = 0x68; //push dword ptr | |
| DWORD* dwProc = (DWORD*)Hook_MessageBoxA; | |
| memcpy(&ByteAsm[1], &dwProc, 4); | |
| ByteAsm[5] = 0xC3; //ret | |
| memcpy(pFunc, ByteAsm, 6); | |
| } | |
| } | |
| int CALLBACK WinMain( | |
| _In_ HINSTANCE hInstance, | |
| _In_ HINSTANCE hPrevInstance, | |
| _In_ LPSTR lpCmdLine, | |
| _In_ int nCmdShow | |
| ) | |
| { | |
| StarteHook(); | |
| MessageBoxA(0, "", "hoge", MB_OK); | |
| memcpy(pFunc, tmp, 6); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment