| 发表于:2007-06-13 22:43:469楼 得分:0 |
我把类帖到这里(提升权限的我blog上写了,帖子上太长不让帖啊) 调用方法如下:windowtitle为窗口标题 dim m as new getprocessmemoryinfo m.showmemoryinfo(windowtitle, true) 类内容: public class getprocessmemoryinfo : inherits form private structure memory_basic_information dim baseaddress as integer dim allocationbase as integer dim allocationprotect as integer dim regionsize as integer dim state as integer dim protect as integer dim ltype as integer end structure private declare function openprocess lib "kernel32 " (byval access as int32, byval inherithandle as boolean, byval processid as int32) as int32 private declare function closehandle lib "kernel32 " (byval handle as int32) as boolean private declare function virtualqueryex lib "kernel32 " (byval hprocess as int32, byval lpaddress as intptr, byref lpbuffer as memory_basic_information, byval dwlength as int32) as int32 private declare function virtualprotectex lib "kernel32 " (byval hprocess as integer, byref lpaddress as integer, byval dwsize as integer, byval flnewprotect as integer, byval lpfloldprotect as integer) as integer private declare function getlasterror lib "kernel32 " alias "getlasterror " () as integer private m_pid as integer friend withevents listview1 as system.windows.forms.listview friend withevents columnheader1 as system.windows.forms.columnheader friend withevents columnheader2 as system.windows.forms.columnheader friend withevents columnheader3 as system.windows.forms.columnheader friend withevents button1 as system.windows.forms.button friend withevents columnheader4 as system.windows.forms.columnheader friend withevents columnheader5 as system.windows.forms.columnheader friend withevents button2 as system.windows.forms.button friend withevents columnheader6 as system.windows.forms.columnheader public sub new() mybase.new() initializecomponent() end sub public sub showmemoryinfo(byval windowtitle as string, byval frmshow as boolean) getopenprocesspid(windowtitle) getmemoryinfo() if frmshow then me.show() end sub private sub getopenprocesspid(byval windowtitle as string) dim pros() as process = process.getprocesses(), pro as process for each pro in pros if pro.mainwindowtitle = windowtitle then m_pid = pro.id end if next end sub private function getmemoryinfo() as long dim hprocess as integer, paddr as integer, dwtotalcommit as long, ret as integer, milen as integer dim mi as new memory_basic_information listview1.items.clear() milen = len(mi) dwtotalcommit = 0 '这是结果 paddr = 0 '这个时查询起始地址,设为0,即进程虚拟地址开始处。 hprocess = openprocess(&h1f0fff, 0, m_pid) '首先打开进程供查询信息 ret = virtualqueryex(hprocess, paddr, mi, milen) '从起始地址开始查询 dim mtmpstr as string '格式化为8位后输出基地址 mtmpstr = "00000000 " & hex(mi.baseaddress) mtmpstr = mtmpstr.substring(mtmpstr.length - 8, 8) listview1.items.add(mtmpstr) listview1.items(listview1.items.count - 1).subitems.add(mi.allocationprotect) listview1.items(listview1.items.count - 1).subitems.add(mi.state) listview1.items(listview1.items.count - 1).subitems.add(mi.protect) listview1.items(listview1.items.count - 1).subitems.add(mi.ltype) listview1.items(listview1.items.count - 1).subitems.add(hex(mi.regionsize)) do while (ret = milen) dwtotalcommit = dwtotalcommit + mi.regionsize paddr = mi.baseaddress + mi.regionsize '跳过已经查询过的内存块,到未被查询的内存地址起始处 ret = virtualqueryex(hprocess, paddr, mi, milen) '再次查询,直到查询失败(所有可查询地址都已经查过了) mtmpstr = "00000000 " & hex(mi.baseaddress) mtmpstr = mtmpstr.substring(mtmpstr.length - 8, 8) listview1.items.add(mtmpstr) listview1.items(listview1.items.count - 1).subitems.add(mi.allocationprotect) listview1.items(listview1.items.count - 1).subitems.add(mi.state) listview1.items(listview1.items.count - 1).subitems.add(mi.protect) listview1.items(listview1.items.count - 1).subitems.add(mi.ltype) listview1.items(listview1.items.count - 1).subitems.add(hex(mi.regionsize)) loop closehandle(hprocess) return dwtotalcommit end function | | |
|