Solved

C++ ReadProcessMemory() won't print out

Posted on 2006-06-20
7
549 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 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