自写Api过r3的Api函数hook
API 函数 hook R3
2023-09-11 14:13:58 时间
这里验证的环境是win7 64位和win10 64位
首先是64位程序,这里由于win7和win10的调用号不同,需要根据所使用的系统修改相应的调用号,顺带说明一下win64的vs程序是不支持内联汇编,这里是我自己下载的intel的parallel studio使得vs支持了内联汇编。
#include<windows.h>
/*---------------------------------------------------------findwindows--------------------------------------*/
#pragma pack(1)
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
#pragma pack()
typedef VOID(__stdcall *PRtlInitUnicodeString)(IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString);
PRtlInitUnicodeString RtlInitUnicodeString = (PRtlInitUnicodeString)GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlInitUnicodeString");
__declspec(naked) HWND __stdcall PNtUserFindWindowEx(ULONG hwndParent, ULONG hwndChild, PUNICODE_STRING pstrClassName, PUNICODE_STRING pstrWindowName, ULONG dwType) {
__asm {
mov r10, rcx
mov eax, 0x106f//win7 0x106e
_EMIT 0x0F
_EMIT 0x05
ret
}
}
int __stdcall main() {
UNICODE_STRING pu_className, pu_Caption;
memset(&pu_className, 0, sizeof(UNICODE_STRING));
RtlInitUnicodeString(&pu_Caption, L"计算器");
HWND fw = PNtUserFindWindowEx(0, 0, &pu_className, &pu_Caption, 0);
SetWindowPos(fw, NULL, 100, 100, 300, 400, 1);
system("pause");
return 0;
}
接着是32位程序,这里的32位程序调用的是sysWow64,sysWow64做了相应的转化,使得32位程序能够调用到正确的Api函数。
#include<windows.h>
#pragma pack(1)
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
#pragma pack()
typedef VOID(__stdcall *PRtlInitUnicodeString)(IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString);
PRtlInitUnicodeString RtlInitUnicodeString = (PRtlInitUnicodeString)GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlInitUnicodeString");
__declspec(naked) HWND __stdcall PNtUserFindWindowEx(ULONG hwndParent, ULONG hwndChild, PUNICODE_STRING pstrClassName, PUNICODE_STRING pstrWindowName, ULONG dwType) {
__asm {
//win 10 0x106f
mov eax,0x106e
mov ecx,0x0
lea edx,dword ptr ss:[esp+0x4]
call fs:[0xc0]
add esp,0x4 //win10需要干掉它
retn 0x14
}
}
int main(){
UNICODE_STRING pu_className, pu_Caption;
memset(&pu_className, 0, sizeof(UNICODE_STRING));
RtlInitUnicodeString(&pu_Caption, L"计算器");
HWND fw= PNtUserFindWindowEx(0, 0,&pu_className,&pu_Caption,0);
SetWindowPos(fw, NULL, 100, 100,300, 400, 1);
return 0;
}
相关文章
- 国际化相对时间格式化API:Intl.RelativeTimeFormat
- aaronyang的百度地图API之LBS云与.NET开发 Javascript API 2.0【把数据存到LBS云2/2】
- Android中文API(99)—— RelativeLayout
- 【GO】K8s 管理系统项目7[API部分--Pv]
- 缺少 Google API 秘钥,因此 Chromium 的部分功能将无法使用
- 122. 在 SAP UI5 应用中使用浏览器原生的 Fetch API 发起网络请求
- Atitit.常用语言的常用内部api 以及API兼容性对源码级别可移植的重要性 总结
- Atitit. 衡量项目规模 ----包含的类的数量 .net java类库包含多少类 多少个api方法??
- Android SDK | Android中文API
- API生态的发展与机遇:从5000组数据看中国API生态与开发者现状
- Opencl API解释(二)
- 汇编 -- Hook API (MessageBoxW)
- Windows API一日一练(27)SetBkMode函数
- Windows API一日一练(42)CreateThread函数
- Windows API一日一练(46)EnterCriticalSection和LeaveCriticalSection函数
- Windows API一日一练(58)FindFirstFile和FindNextFile函数
- Windows API一日一练(50)SuspendThread和ResumeThread函数
- Windows API一日一练(64) RegSetValueEx和RegDeleteValue函数
- Windows API一日一练(66)CreateWaitableTimer和SetWaitableTimer函数
- Windows API一日一练(71)GetComputerName函数
- Windows API一日一练(82)LoadLibrary函数
- Windows API一日一练(91)GetProcessMemoryInfo函数
- Windows API一日一练(59)CreateFileMapping和MapViewOfFile函数
- 使用 Postman 做 API 自动化测试
- 【Qbot】6.讯飞文字转语音Api使用/VITS派蒙复读机实现