Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 Search for string in process memory

Posted on 2010-08-18
7
Medium Priority
?
1,551 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:Meir Rivkin
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 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