|

- 帖子
- 524
- 精华
- 2
- 威望
- 224
- 擂点
- 0
- 人气
- 68
- 注册时间
- 2007-3-25
|
1楼
发表于 2008-7-27 14:14
| 只看该作者
[原创] 带头开源 - CsrWalker_VB(源码)
'版权声明: suanzi , iceboy(因为是ICY同学教我做的,也写上他名字)
'直接把ProcessView里的一个枚举进程模块copy出来 随便写的代码 很乱 不过我加了比较详细的注释了
'代码中我加了一处手脚 原因.. 有垃圾.. 垃圾在哪?
'提示一下 某行代码的传址传值我修改了 会的人一调试就知
'带上广告,附上我的ProcessView- Option Explicit
- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
- Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
- Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
- Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hprocess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
- Private Declare Function CsrGetProcessId Lib "ntdll" () As Long '这是csrss的Pid
- Private Type CSR_PROCESS_PARTIAL
- UniqueProcess As Long
- UniqueThread As Long
- Flink As Long
- Blink As Long
- End Type
- Public Function EnumByCsrWalk() As Long()
- Dim hprocess As Long, hModule As Long, addr As Long
- Dim buff(0 To &H2F) As Byte, AddrCRP As Long, addr2 As Long
- Dim cpp As CSR_PROCESS_PARTIAL, FirstFlink As Long
- Dim Pids() As Long, I As Long
- hprocess = IszOpenProcess(&H400 Or &H10, CsrGetProcessId()) '打开csrss需要SE_DEBUG
- hModule = LoadLibrary("csrsrv.dll")
- addr = GetProcAddress(hModule, "CsrLockProcessByClientId") 'CsrLockProcessByClientId的地址
- CopyMemory buff(0), ByVal CLng(addr + &H8), &H30
-
- For I = 0 To UBound(buff) - 1 '搜索并定位CsrRootProcess
- If buff(I) = &H8B And buff(I + 1) = &H35 Then 'CsrRootProcess在XP反汇编得的特征码是8B 35
- CopyMemory AddrCRP, ByVal buff(I + 2), 4
- End If
- Next
- ReadProcessMemory hprocess, ByVal AddrCRP, addr2, 4, ByVal 0& '读取AddrCRP指向的地址,这个地址指向一个结构
- ReadProcessMemory hprocess, ByVal addr2, cpp, 16, ByVal 0& '这里已经读取第1个了
- FirstFlink = cpp.Flink '记录一下第1个 因为这是一个双向链表
- ReDim Pids(0)
- Do
- ReadProcessMemory hprocess, ByVal cpp.Flink - 8, cpp, 16, ByVal 0& '下一个是Flink - 8
- AddItemToArray cpp.UniqueProcess, Pids
- Loop While cpp.Flink <> FirstFlink
-
- If (UBound(Pids) = 0) Then MsgBox "错误发生在_EnumByCsrWalk"
- IcyClose hprocess
- FreeLibrary hModule
- EnumByCsrWalk = Pids
- End Function
复制代码 [ 本帖最后由 suanzi 于 2008-7-27 14:16 编辑 ] |
附件: 您所在的用户组无法下载或查看附件
-
2
评分次数
-
|