?
Solved

VB6 Search for string in process memory

Posted on 2010-08-18
7
Medium Priority
?
1,525 Views
Last Modified: 2012-06-21
I have a routine in VB6 that will allow me to find the PID of a running application. What I need to do is search for a text string within the memory being used by that application.

How do I best go about this? It should be as a normal text string - not Unicode.

Thanks
0
Comment
Question by:Chris Millard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33462443
>>What I need to do is search for a text string within the memory being used by that application.what do u mean the memory being used by the app?can u give an example?
0
 
LVL 17

Author Comment

by:Chris Millard
ID: 33462530
Well, take a look at Process Memory Dumper from https://www.evilfingers.com/tools/ProcessMemoryDumper.php

It will dump the memory from a running process to a file on disk. I need to search the process memory rather than dump it.
0
 
LVL 28

Expert Comment

by:Ark
ID: 33508253
Check out my sample
Read-Write.zip
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Author Comment

by:Chris Millard
ID: 33514856
Hi Ark,

I've seen this sample before, and unfortunately I can't get it to work. Instead of launching calc.exe what I am trying to do is scan the memory of an already running application (I know the PID) for a particular text string (not in unicode). I know that the string exists within the memory being used by the application, but your sample does not find the string.
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 33517299
Using:
Dim ret As Long
ret=ScanProcessMemory(pid,"Hello")
If ret Then
   MsgBox "Found [Hello] at position " & ret
Else
   MsgBox "Search string not found"
End If

Public Function ScanProcessMemory(ByVal pid As Long, ByVal strSearch As String) As Long
    Dim hProcess As Long, lpMem As Long, lLenMBI As Long
    Dim ret As Long, lWritten As Long, lPos As Long
    Dim sBuffer As String
    Dim si As SYSTEM_INFO
    Dim mbi As MEMORY_BASIC_INFORMATION
    
    hProcess = OpenProcess(PROCESS_READ_WRITE_QUERY, False, pid)
    lLenMBI = Len(mbi)
    Call GetSystemInfo(si)
    lpMem = si.lpMinimumApplicationAddress
    Do While lpMem < si.lpMaximumApplicationAddress
        mbi.RegionSize = 0
        ret = VirtualQueryEx(hProcess, ByVal lpMem, mbi, lLenMBI)
        If ret = lLenMBI Then
            If ((mbi.lType = MEM_PRIVATE) And (mbi.State = MEM_COMMIT)) Then ' this block is In use by this process
                If mbi.RegionSize > 0 Then
                   sBuffer = String(mbi.RegionSize, 0)
                   ReadProcessMemory hProcess, ByVal mbi.BaseAddress, ByVal sBuffer, mbi.RegionSize, lWritten
                   lPos = InStr(1, sBuffer, strSearch, vbTextCompare)
                   If lPos > 0 Then Exit Do
                End If
            End If
            On Error GoTo Finished
            lpMem = mbi.BaseAddress + mbi.RegionSize
            On Error GoTo 0
        Else
            Exit Do
        End If
    Loop
Finished:
   CloseHandle hProcess
   ScanProcessMemory = lPos
End Function

Open in new window

0
 
LVL 17

Author Comment

by:Chris Millard
ID: 33602420
Hi again Ark,

Try as I might, I still cannot get this to work - your example above does not find the string that I am searching for - yet I know it's there, because the ProcessMemoryDumper application I mentioned above, does dump the process memory to a file which I can then open and search using a hex editor...

Thanks

Chris
0
 
LVL 17

Author Closing Comment

by:Chris Millard
ID: 34358319
Thanks Ark, with a bit of tweaking, I got this to work.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question