Solved

C++ ReadProcessMemory() won't print out

Posted on 2006-06-20
7
550 Views
Last Modified: 2013-11-20
   OpenProc = OpenProcess(PROCESS_VM_READ,FALSE,ProcessID);
   
    if(OpenProc)
    {
        NumberOfPeopleInRoom = SendMessage(ListBox(), LB_GETCOUNT, 0, 0) - 1;
        cout << NumberOfPeopleInRoom << endl;
     
        WORD length;
        char pszCmdLine[16];
        DWORD itemData;
        DWORD Baddress;
        char MemCopiedTo[16];

       /* okay, this is the code i have so far now, still prints a blank line
        * Am I supposed to close the Process before i print it out or what??
        * I just want it to print the item i selected in this case it would be item 10
        * just trying to print the string which is contained on/in the 10th item
        * i posted previously but beyond this point i got no more help
        */

         itemData = SendMessage(ListBox(), LB_GETITEMDATA,(WPARAM) 10,0);
        Baddress = (DWORD)itemData;
        ReadProcessMemory(OpenProc,(LPCVOID)Baddress,pszCmdLine,16,&bytes);
        CopyMemory(MemCopiedTo,pszCmdLine,20);
        cout << MemCopiedTo << endl;
        }
0
Comment
Question by:crims
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16948703
Try to replace LB_GETITEMDATA with LB_GETTEXT. In one of your previous questions I have already asked you "Why do you think that LB_GETITEMDATA result points to listbox string?"
It this will not work, return to my previous answer which was ignored.
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 250 total points
ID: 16957880
You may refer this for further help :
Stealing Program's Memory : http://www.codeproject.com/threads/int64_memsteal.asp <=== Grabs items of ListView from another Processes.

Along with following thread :
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21839361.html

-MAHESH

0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 250 total points
ID: 16973359
AlexFM,
>> "Why do you think that LB_GETITEMDATA result points to listbox string?"

We don't know this to be the case here, but if that is an Owner-draw listbox without LBS_HASSTRINGS, then the itemdata *is* a pointer to the text (as i was reminded when reading the link posted by mahesh1402.

    http://www.experts-exchange.com/Programming/MFC/Q_21839361.html#16622847

crims,
Check out the short sequence of code in my comment in the above link.    It might do the trick for you.

-- Dan
0
 

Author Comment

by:crims
ID: 16974207
Alex,

I didn't ignore you, i replied I am new to this expert-exchange, i think i closed it out the topic or something, gave some guy 500 points for just telling me to change a variable.
 i asked are you saying i need to allocate virtual memory?
and btw the LB_GETTEXT didn't work.

MAHESH,

The link on exper-exchange you posted, has
CListBox* pLB = (CListBox*) Get_Control(lb_id);  // gets the listbox from the control id- this works fine
     int i, count = pLB->GetCount();  // this works too- the correct numberof items shows up

I don't know what CListBox* pLB is... obviously some type of variable. didn't know how to use it or what.
and the pLB->GetCount(); I tried a few of the functions in that code... are they in the standard C++ libraries, or did the guy code them himself?


I guess the best way to say it is... below is the code in vb trying to convert it to C++

uzgy: Public Sub NewAddRoomToList(TheList As ListBox, AddUser As Boolean)
' You can use this sub with any AOL
    On Error Resume Next
    Dim cprocess As Long, itmhold As Long, ScreenName As String
    Dim psnhold As Long, rbytes As Long, Index As Long, room As Long
    Dim rlist As Long, sthread As Long, mthread As Long, itmNum As Long
    room& = FindRoom&
    If room& = 0& Then Exit Sub
    itmNum& = 24
Top:
    rlist& = FindWindowEx(room&, 0&, "_AOL_Listbox", vbNullString)
    sthread& = GetWindowThreadProcessId(rlist, cprocess&)
    mthread& = OpenProcess(PROCESS_READ Or RIGHTS_REQUIRED, False, cprocess&)
    If mthread& Then
        For Index& = 0 To SendMessage(rlist, LB_GETCOUNT, 0, 0) - 1
            ScreenName$ = String$(4, vbNullChar)
            itmhold& = SendMessage(rlist, LB_GETITEMDATA, ByVal CLng(Index&), ByVal 0&)
            itmhold& = itmhold& + itmNum&
            Call ReadProcessMemory(mthread&, itmhold&, ScreenName$, 4, rbytes)
            Call CopyMemory(psnhold&, ByVal ScreenName$, 4)
            psnhold& = psnhold& + 6
            ScreenName$ = String$(16, vbNullChar)
            Call ReadProcessMemory(mthread&, psnhold&, ScreenName$, Len(ScreenName$), rbytes&)
            ScreenName$ = Left$(ScreenName$, InStr(ScreenName$, vbNullChar) - 1)
            'This is used because if you use the old way it returns either
            'a blank or just a 'p'
            If Trim(ScreenName$) = "" Or Trim(ScreenName$) = "p" Then
                itmNum& = 28
                Call CloseHandle(mthread)
                GoTo Top
            End If
            If ScreenName$ &lt;&gt; GetUser Or AddUser = True Then
                TheList.AddItem ScreenName$
            End If
        Next Index&
        Call CloseHandle(mthread)
    End If
End Sub


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 104
Detect file exist or not 3 177
unix example issues 18 98
Way to decrease size of apk file 9 86
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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