|
|
|
vc++中如何获取进程模块的信息 |
|
|
| http://www.iyit.net 日期:2005-11-24 17:47:49 来源:易特网络技术 点击: |
一、 实现原理:
首先通过createtoolhelp32snapshot函数创建一个进程的快照,然后通过调用process32first使用快照返回的句柄对进程进行遍历,相关的信息存放在processentry32结构类型的实例中,通过调用内部的一个函数getprocessmodule,获取对应的进程的模块名称,然后通过对进程地址空间信息的读取,从而获取相应的线程的id等的信息。
二、主要实现代码:
获取进程地址空间内的相关信息:
hprocess = openprocess (process_all_access, false, pe32.th32processid);
pfgetprocessmemoryinfo(hprocess,pmc,sizeof(pmc));
获取进程的模块信息:
bool cemutefiledlg::getprocessmodule(dword dwpid, dword dwmoduleid, lpmoduleentry32 lpme32, dword cbme32) { bool bret = false; bool bfound = false; handle hmodulesnap = null; moduleentry32 me32 = {0};
// take a snapshot of all modules in the specified process.
hmodulesnap = createtoolhelp32snapshot(th32cs_snapmodule, dwpid);
if (hmodulesnap == invalid_handle_value) return (false);
// fill the size of the structure before using it.
me32.dwsize = sizeof(moduleentry32);
// walk the module list of the process, and find the module of // interest. then copy the information to the buffer pointed // to by lpme32 so that it can be returned to the caller.
if (module32first(hmodulesnap, &me32)) { do { if (me32.th32moduleid == dwmoduleid) { copymemory (lpme32, &me32, cbme32); bfound = true; } } while (!bfound && module32next(hmodulesnap, &me32));
bret = bfound; // if this sets bret to false, dwmoduleid // no longer exists in specified process } else bret = false; // could not walk module list
// do not forget to clean up the snapshot object.
closehandle (hmodulesnap);
return (bret); }
三、提高权限:
bool enabledebugprivilege()
{ handle htoken; bool fok=false; if(openprocesstoken(getcurrentprocess(),token_adjust_privileges,&htoken)) { token_privileges tp; tp.privilegecount=1; if(!lookupprivilegevalue(null,se_debug_name,&tp.privileges[0].luid)) printf("can’t lookup privilege value.\n"); tp.privileges[0].attributes=se_privilege_enabled; if(!adjusttokenprivileges(htoken,false,&tp,sizeof(tp),null,null)) printf("can’t adjust privilege value.\n"); fok=(getlasterror()==error_success); closehandle(htoken); } return fok; }
四、后记:
我感觉信息获取的不够完整,比如说,我很想知道怎么才能获取进程的线程的模块名称,不知道那位大侠不吝赐教!
monkeycd@163.com
thanx!
|
上一篇:使用hotmetal
下一篇:数据库中图像数据的存取技术
[发送给好友] [打印本页] [关闭窗口] [返回顶部] 转载请注明来源:http://www.iyit.net |
|
| 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
| 责任编辑: |
投稿作者: 易特网络技术 |
| 信息来源: 易特网络技术 |
录入时间: 2005-11-24 17:47:49 |
| 浏览次数: |
投稿信箱: shtghy@163.com |
|
|
|
|
|