搜索内存数据(二)
来源:互联网 发布:彩票缩水软件大全 编辑:程序博客网 时间:2024/04/29 08:23
- Public Function SearchMem(hProcess As Long, strSearch As String, Optional spos As Long = &H400000) As Long
- Dim i As Long, j As Long, count As Long, nLength As Long
- Dim r As Long, mbi As MEMORY_BASIC_INFORMATION
- Dim lpAddress As Long, ubs As Long, RSize As Long, lMax As Long
- Dim bSearch() As Byte
- Dim sp() As String
- Dim lpBuffer() As Byte
- Dim si As SYSTEM_INFO
-
- GetSystemInfo si
- lMax = si.lpMaximumApplicationAddres
-
-
- sp = Split(strSearch, " ")
- nLength = UBound(sp)
- ReDim bSearch(nLength)
- For i = 0 To nLength
- bSearch(i) = Val("&H" & sp(i)) And &HFF
- Next
-
- SearchMem = 0
- lpAddress = spos
- ubs = UBound(bSearch)
- bSearching = True
- r = VirtualQueryEx(hProcess, lpAddress, mbi, Len(mbi))
-
- Do While (r And (lpAddress < lMax) And bSearching)
- DoEvents
-
- If (mbi.Protect And PAGE_READWRITE) And (mbi.State = MEM_COMMIT) Then
- RSize = mbi.RegionSize
- ReDim lpBuffer(RSize - 1)
- ReadProcessMemory hProcess, mbi.BaseAddress, lpBuffer(0), RSize, 0
-
- count = RSize - 1 - ubs
- For i = 0 To count
- DoEvents
-
- For j = 0 To ubs
- DoEvents
- If bSearch(j) <> lpBuffer(i + j) Then GoTo 10
- Next
-
- bSearching = False
- SearchMem = i + lpAddress
- Exit Function
- 10:
- Next
- End If
- lpAddress = lpAddress + RSize
- r = VirtualQueryEx(hProcess, lpAddress, mbi, Len(mbi))
- Loop
- bSearching = False
- SearchMem = 0
- End Function