|
请问下老师:
我用IDA查看Kernel32.dll中WriteProcessMemory函数的实现流程,发现他是先调用NtProtectVirtualMemory将目标进程内存的访问权限改为可写,后调用NtWriteVirtualMemory执行写入。
在给NtWriteVirtualMemory传参时,代码如下:
.text:7C802265 8D 45 08 lea eax, [ebp+hProcess]
.text:7C802268 50 push eax ; NumberOfBytesWritten
即上述两行代码,应该是将EBP+8处的地址入栈吧?也就是将传入的hProcess的地址入栈?为什么IDA会将其解释为将NumberOfBytesWritten入栈?
函数BOOL __stdcall WriteProcessMemory(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesWritten)中也只传入了NumberOfBytesWritten的地址,用于将结果存入改地址啊?
我不看参考他的注释,仅看堆栈偏移对应的参数来重写,也能成功写入数据。请问这是为什么呢?
BOOL WINAPI MyWriteProcessMemory(
HANDLE hProcess, // handle to process
LPVOID lpBaseAddress, // base of memory area
LPVOID lpBuffer, // data buffer
DWORD nSize, // number of bytes to write
LPDWORD lpNumberOfBytesWritten // number of bytes written
)
{
DWORD dwRet = FALSE;
__asm
{
lea eax,dword ptr [ebp + 0x08] //&hProcess
push eax
push dword ptr [ebp + 0x14] //nSize
push dword ptr [ebp + 0x10] //lpBuffer
push dword ptr [ebp + 0x0c] //lpBaseAddress
push dword ptr [ebp + 0x08] //hProcess
//push dword ptr [ebp + 0x18] //lpNumberOfBytesWritten
call MyNtWriteVirtualMemory
mov dword ptr [dwRet],eax
}
if (dwRet == 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
肯定老师指点一二,谢谢谢谢!!!
|
|