Solved

C++ ReadProcessMemory() won't print out

Posted on 2006-06-20
7
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 21
deburging in oracle form 12 76
scoreUp challenge 14 48
How to convert MFC::CString to UTF8 wchar_t* 10 92
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

744 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

15 Experts available now in Live!

Get 1:1 Help Now