[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C++ ReadProcessMemory() won't print out

Posted on 2006-06-20
7
Medium Priority
?
557 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
[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
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 1000 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 1000 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

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.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

650 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