首页
社区
课程
招聘
[旧帖] 完整本地Hook API ,有句看不懂,求高手指点 0.00雪花
发表于: 2012-10-25 21:23 1663

[旧帖] 完整本地Hook API ,有句看不懂,求高手指点 0.00雪花

2012-10-25 21:23
1663
.
.
源码如下:

#include "stdafx.h"
#include <windows.h> 
#include <iostream> 
#pragma comment(lib,"bufferoverflowU.lib")

using namespace std; 

typedef int (WINAPI *pMessageBoxDef)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType); 

char szOldMessageBox[5] = {0}; 
char szJmpMyMessageBox[5] = {(char)0xe9}; 
pMessageBoxDef pMessageBox = NULL; 
  
int WINAPI MyMessageBox(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)  

  wcout<<L"hWnd:"<<(int)hWnd<<endl; 
  wcout<<L"lpText:"<<lpText<<endl; 
  wcout<<L"lpCaption:"<<lpCaption<<endl; 
  wcout<<L"uType:"<<uType<<endl<<endl; 

WriteProcessMemory((void*)-1, pMessageBox, szOldMessageBox, 5, NULL); 

MessageBoxW(hWnd, lpText, lpCaption, uType); 

WriteProcessMemory((void*)-1, pMessageBox, szJmpMyMessageBox, 5, NULL); 
return 0; 


int main() 

  
DWORD dwJmpAddr = 0; 
HMODULE hModule = LoadLibrary("User32.Dll"); 
pMessageBox = (pMessageBoxDef)GetProcAddress(hModule, "MessageBoxW"); 
dwJmpAddr = (DWORD)MyMessageBox - (DWORD)pMessageBox - 5; 

memcpy(szJmpMyMessageBox + 1, &dwJmpAddr, 4); 
FreeLibrary(hModule); 
ReadProcessMemory((void*)-1, pMessageBox, szOldMessageBox, 5, NULL);//读出原来的前5个字节 
WriteProcessMemory((void*)-1, pMessageBox, szJmpMyMessageBox, 5, NULL);//写入我们处理后的5个字节 

pMessageBox(GetForegroundWindow(), L"Inline Hook:MessageBox", L"HOOK API", MB_OK); 

pMessageBox(GetForegroundWindow(), L"Hello World", L"Win32", MB_OK); 
return 0; 
}

看不懂的代码:

dwJmpAddr = (DWORD)MyMessageBox - (DWORD)pMessageBox - 5; //只有这句不明白

memcpy(szJmpMyMessageBox + 1, &dwJmpAddr, 4); 

以下是我的理解,不知道对不对:

szJmpMyMessageBox 我理解是shellCode 作用就是跳转到我们的函数(MyMessageBox )

但是它跳转的地址为什么不是我们的函数(MyMessageBox)地址,而是 dwJmpAddr 呢?

MyMessageBox函数地址不是 &MyMessageBox 么,为什么是dwJmpAddr

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 622
活跃值: (294)
能力值: ( LV13,RANK:410 )
在线值:
发帖
回帖
粉丝
2
请参考Jmp 指令的跳转地址计算方法。

例子:
OFFSET          DATA            Disasm
0x00000000      E9 00000000     JMP 0x00000005
0x00000005      90              NOP
2012-10-25 22:35
0
雪    币: 7246
活跃值: (5073)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
感谢感谢。用OD看了下,弄懂了。
2012-10-25 22:49
0
雪    币: 22
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
jmp 指令不是绝对地址,“szJmpMyMessageBox 我理解是shellCode”这么说不妥当
2012-10-25 23:53
0
雪    币: 17
活跃值: (40)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
E9 00000000     JMP 0x00000005
E9 的反汇编为什么 是JMP 0x05
2012-10-26 08:45
0
游客
登录 | 注册 方可回帖
返回
//