Solved

VB6 Search for string in process memory

Posted on 2010-08-18
7
1,436 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
  • 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 27

Expert Comment

by:Ark
ID: 33508253
Check out my sample
Read-Write.zip
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 27

Accepted Solution

by:
Ark earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now