永发信息网

VB中如何用ZwQueryVirtualMemory枚举进程模块?

答案:2  悬赏:30  手机版
解决时间 2021-01-26 15:03
VB中如何用ZwQueryVirtualMemory枚举进程模块,然后将模块的基址等信息显示在List1控件上?希望能提供详细的过程,包括声明等,谢谢!

我之所以用ZwQueryVirtualMemory是因为我要枚举隐藏模块
最佳答案
声明自寻
Public Sub PrintProcessModules(ByVal dwProcessId As Long)
Dim ntStatus As Long
Dim objCid As CLIENT_ID
Dim objOa As OBJECT_ATTRIBUTES
Dim hProcess As Long
Dim dwVirtualAddr As Long
Dim pName As UNICODE_STRING1
Dim dwRet As Long
Dim intRet As Integer
Dim strModuleName As String
Dim pDosHeader As IMAGE_DOS_HEADER
Dim pNtHeaders As IMAGE_NT_HEADERS
Dim dwImageSize As Long
Dim MemoryBase As MEMORY_BASIC_INFORMATION
objOa.Length = Len(objOa)
objCid.UniqueProcess = dwProcessId
ntStatus = NtOpenProcess(hProcess, PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, objOa, objCid)
If hProcess = 0 Then
hProcess = GetHandleByProcessId(dwProcessId)
If hProcess = 0 Then
Exit Sub
End If
End If
dwVirtualAddr = &H1000
Do While dwVirtualAddr <> &H7FFF0000
ntStatus = ZwQueryVirtualMemory(hProcess, dwVirtualAddr, 0, VarPtr(MemoryBase), LenB(MemoryBase), dwRet)
If NT_SUCCESS(ntStatus) Then
If MemoryBase.AllocationBase = 0 Then
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize Mod &H1000
GoTo NextLoop
Else
ntStatus = ZwQueryVirtualMemory(hProcess, dwVirtualAddr, 2, VarPtr(pName), LenB(pName), dwRet)
If NT_SUCCESS(ntStatus) Then
ReadProcessMemory hProcess, ByVal MemoryBase.AllocationBase, pDosHeader, LenB(pDosHeader), ByVal 0&
If pDosHeader.Magic <> &H5A4D Then
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize Mod &H1000
GoTo NextLoop
End If
ReadProcessMemory hProcess, ByVal MemoryBase.AllocationBase + pDosHeader.lfanew, pNtHeaders, LenB(pNtHeaders), ByVal 0&
If pNtHeaders.Signature <> IMAGE_NT_SIGNATURE Then
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize Mod &H1000
GoTo NextLoop
End If
strModuleName = Left(pName.pBuffer, InStr(pName.pBuffer, vbNullChar) - 1)
'Debug.Print strModuleName; MemoryBase.AllocationBase; pNtHeaders.OptionalHeader.ImageSize
If MemoryBase.Type = &H1000000 Then
Form1.List1.AddItem strModuleName & ";" & Hex(MemoryBase.AllocationBase) & ";" & Hex(pNtHeaders.OptionalHeader.ImageSize) & ";State:" & Hex(MemoryBase.State) & ";Type:" & Hex(MemoryBase.Type) & ";AllocationProtect:" & Hex(MemoryBase.AllocationProtect) & ";Protect:" & Hex(MemoryBase.Protect)
End If
'dwVirtualAddr = dwVirtualAddr + pNtHeaders.OptionalHeader.ImageSize
dwVirtualAddr = MemoryBase.AllocationBase + pNtHeaders.OptionalHeader.ImageSize
dwVirtualAddr = dwVirtualAddr + pNtHeaders.OptionalHeader.ImageSize Mod &H1000
Else
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize
dwVirtualAddr = dwVirtualAddr + MemoryBase.RegionSize Mod &H1000
End If
End If
Else
dwVirtualAddr = dwVirtualAddr + &H1000
End If
NextLoop:
Loop
NtClose hProcess
End Sub
全部回答
通过进程pid枚举 相关窗口句柄 private sub command1_click() list1.clear find_window val(text1.text) end sub private sub form_load() text1.text = "" command1.caption = "枚举窗口" end sub 模块代码如下 option explicit private declare function enumwindows lib "user32" (byval lpenumfunc as long, byval lparam as long) as long private declare function getwindowthreadprocessid lib "user32" (byval hwnd as long, lpdwprocessid as long) as long private declare function getwindowtext lib "user32" alias "getwindowtexta" (byval hwnd as long, byval lpstring as string, byval cch as long) as long dim ifpid as long private function enumwindowsproc(byval hwnd as long, byval lparam as long) as long dim pid1 as long dim wtext as string * 255 getwindowthreadprocessid hwnd, pid1 if ifpid = pid1 then getwindowtext hwnd, wtext, 100 form1.list1.additem "句柄:" & hwnd & " 标题:" & wtext end if enumwindowsproc = true end function public sub find_window(byval pid as long) ifpid = pid enumwindows addressof enumwindowsproc, 0 end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
请问32寸创维液晶电视的价格
昊天工程装饰公司地址在哪,我要去那里办事
肿瘤临床分期一般是Ⅰ~Ⅳ期,除外A.神经母细
成语万里长征的意思是什么啊?有知道释义的请
定制家具有点不完美客户不允许维修和更换只要
在台湾送人鞋子是请人走路还是让人跑步?
三星C460打印机老是显示更换或安装废碳粉盒,
急急 请问从衡阳去衡东的汽车在哪个汽车站
激光打完胎记后什么时候可以晒太阳,恢复以
下列实验中,测得的实验数据合理的是DA. 用托
根据丙图所示的民居建筑外貌分析,当地的自然
委托加工物资成本的问题
成语雾鬓云鬟的意思是什么啊?有知道释义的请
炫舞中男装饼饼的猫的情侣装是哪件
摩托车没有年审可不可以年审驾驶证
推荐资讯
我们公司最近要举行一个大型的活动需要拍摄人
什么是骨瓷?什么样的骨瓷好?
高枧村怎么去啊,我要去那办事
成语膝行蒲伏的意思是什么啊?有知道释义的请
读下列图文资料回答问题。材料一 生于晚明的
罗汉鱼身上有白点,倒着游,肚子大怎么办
怎样的词语形容亲姐姐出卖妹妹的隐私
2014年两会期间,新华网开展了“您的建议,我
柞榛木多少钱/斤
成语遮掩耳目的意思是什么啊?有知道释义的请
女朋友和别的男人暧昧,我该原谅她么
微信号性别改成男的就会出现在附近的人,性别
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?