GetWindowLong跨进程获取WndProc、DlgProc。。。
2013-01-04 00:12
281 查看
在看雪提问,没人回答,只能自己折腾。。。
标题虽然写是GetWindowLong,其实并不是GetWindowLong,只是按照GetWindowLong的内部实现改了下而已。。
下面代码Win7及以上可用。。。要想XP用,XP下必需暴力搜索user32.gSharedInfo,搜索方法:user32的入口点往下看,CsrCononToServer那个函数下面。。。或者参照网上那个枚举全局Hook的代码。
标题虽然写是GetWindowLong,其实并不是GetWindowLong,只是按照GetWindowLong的内部实现改了下而已。。
下面代码Win7及以上可用。。。要想XP用,XP下必需暴力搜索user32.gSharedInfo,搜索方法:user32的入口点往下看,CsrCononToServer那个函数下面。。。或者参照网上那个枚举全局Hook的代码。
Private Declare Function GetWindowThreadProcessId& Lib "user32" (ByVal hWnd&, ByRef lpdwProcessId&) Private Declare Function GetModuleHandleW& Lib "kernel32" (ByVal lpModuleName&) Private Declare Function GetProcAddress& Lib "kernel32" (ByVal hModule&, ByVal lpProcName$) Private Declare Function OpenProcess& Lib "kernel32" (ByVal dwDesiredAccess&, ByVal bInheritHandle As Boolean, ByVal dwProcessId&) Private Declare Function OpenThread& Lib "kernel32" (ByVal dwDesiredAccess&, ByVal bInheritHandle As Boolean, ByVal dwThreadId&) Private Declare Function ReadProcessMemory& Lib "kernel32" (ByVal hProcess&, ByVal lpBaseAddress&, ByVal lpBuffer&, ByVal nSize&, ByRef lpNumberOfBytesRead&) Private Declare Function NtQueryInformationThread& Lib "ntdll" (ByVal ThreadHandle&, ByVal ThreadInformationClass&, ByVal ThreadInformation&, ByVal ThreadInformationLength&, ByRef ReturnLength&) Private Declare Function CloseHandle& Lib "kernel32" (ByVal hObject&) Private Function GetThreadTeb&(ByVal hThread&) Dim tbi&(6) If NtQueryInformationThread(hThread, 0, VarPtr(tbi(0)), 28, 0) = 0 Then GetThreadTeb = tbi(1) End Function Private Function GetHighValueForUser32&(ByVal hProcess&, ByVal hThread&) Dim lpValue& ReadProcessMemory hProcess, GetThreadTeb(hThread) + &H6E8, VarPtr(lpValue), 4, 0 GetHighValueForUser32 = lpValue End Function Private Function GetHWNDTablePointerInUser32SharedInfoEntry&(ByVal hProcess&) Dim lpU32SharedInfo& lpU32SharedInfo = GetProcAddress(GetModuleHandleW(StrPtr("user32.dll")), "gSharedInfo") + 4 ReadProcessMemory hProcess, lpU32SharedInfo, VarPtr(lpU32SharedInfo), 4, 0 GetHWNDTablePointerInUser32SharedInfoEntry = lpU32SharedInfo End Function Private Function MakeInfoPointerByRemote2UnknownForHWND&(ByVal hProcess&, ByVal hWnd&, ByVal unkHighValue&, ByVal unkPointer&) Dim dwLowValue&, dwUnknownValue&, lpPointer& dwLowValue = hWnd And &HFFFF& dwLowValue = dwLowValue + dwLowValue * 2 lpPointer = unkPointer + dwLowValue * 4 ReadProcessMemory hProcess, lpPointer, VarPtr(dwUnknownValue), 4, 0 MakeInfoPointerByRemote2UnknownForHWND = dwUnknownValue - unkHighValue End Function Private Function GetRemoteProcessWndProc&(ByVal hProcess&, ByVal lpPointer&) Dim lpfnWndProc& ReadProcessMemory hProcess, lpPointer + &H60, VarPtr(lpfnWndProc), 4, 0 GetRemoteProcessWndProc = lpfnWndProc End Function Private Function GetRemoteProcessDlgProc&(ByVal hProcess&, ByVal lpPointer&) Dim lpfnDlgProc& ReadProcessMemory hProcess, lpPointer + &HCC, VarPtr(lpfnDlgProc), 4, 0 '//XP:+ &HA8 ReadProcessMemory hProcess, lpfnDlgProc, VarPtr(lpfnDlgProc), 4, 0 GetRemoteProcessDlgProc = lpfnDlgProc End Function Private Sub Form_Load() Dim hProcess&, hThread&, tid&, pid& tid = GetWindowThreadProcessId(197776, pid) hThread = OpenThread(2032639, False, tid) hProcess = OpenProcess(2035711, False, pid) MsgBox Hex(GetRemoteProcessWndProc(hProcess, MakeInfoPointerByRemote2UnknownForHWND(hProcess, 197776, GetHighValueForUser32(hProcess, hThread), GetHWNDTablePointerInUser32SharedInfoEntry(hProcess)))) MsgBox Hex(GetRemoteProcessDlgProc(hProcess, MakeInfoPointerByRemote2UnknownForHWND(hProcess, 197776, GetHighValueForUser32(hProcess, hThread), GetHWNDTablePointerInUser32SharedInfoEntry(hProcess)))) CloseHandle hProcess End Sub
相关文章推荐
- 内核获取进程名KeGetProcName
- readlink 获取当前进程对应proc/self/exe
- GetProcAddressEx跨进程获取导出函数地址
- GetProcAddressEx跨进程获取导出函数地址
- C#通过WndProc获取当前进程,以便重绘控件
- 简单案例教你用PROC文件系统获取进程信息 推荐
- Linux下获取当前进程的执行文件的绝对路径和所在目录(通过/proc/self/exe链接)
- 简单案例教你用PROC文件系统获取进程信息
- C#获取当前进程HASH的方法
- Linux系统 进程资源参数查询 proc/%d/stat文件
- 获取其他进程的命令行
- java获取当前tomcat进程(linux)
- 获取系统进程
- 透过文件句柄获取进程的绝对路径
- 获取进程信息和设备信息(包括设备类型,序列号,ios版本等
- Atitit,通过pid获取进程文件路径 java php c#.net版本大总结
- 根据进程名字获取id并kill
- Windows下用C语言获取进程cpu使用率,内存使用,IO情况
- shell同时启多个进程,并等待所有子进程结束,再做接下来的操作,最好能获取每个子进程的退出状态
- 获取系统中的进程列表(win 32 SDK)