Solved

ReadProcessMemory() I need help this is urgent (thanks to anyone who can help)

Posted on 2006-06-17
4
278 Views
Last Modified: 2013-11-20
I am trying to copy a string from... a listbox of another program (in this case AOL) ... I am having difficulty with the... ReadProcessMemory(). I have been to msdn, wasn't much help, i have been stuck for almost 2 weeks on this one line.
 
I learn best by examples, so the best question i can ask is "how would you do it? (with the code below)"

p.s. Problem is in the main()

#include<iostream>
#include<windows.h>
 
using std::cin;
using std::cout;
using std::endl;
 
HWND AOL();
HWND MDI();
HWND ListBox();
HWND FindChat();
 
int main()
{
   
    DWORD LBthread;
    DWORD ProcessID;
    char ScreenNames[17];
   
    DWORD NumberOfPeopleInRoom;
    unsigned long bytes;
   
    LBthread = GetWindowThreadProcessId(ListBox(),&ProcessID);
   
    HANDLE OpenProc;
    OpenProc = OpenProcess(PROCESS_VM_READ,FALSE,ProcessID);
   
    if(OpenProc)
    {
        NumberOfPeopleInRoom = SendMessage(ListBox(), LB_GETCOUNT, 0, 0) - 1;
        cout << NumberOfPeopleInRoom << endl;
       
        WORD length;
        char pszCmdLine[20];
        DWORD itemData;
        DWORD *Baddress;
   
   
        itemData = SendMessage(ListBox(), LB_GETITEMDATA,(WPARAM) 10,0);
        Baddress = &itemData;
       
        ReadProcessMemory(OpenProc,(LPCVOID)*Baddress,pszCmdLine,20,&bytes);
       
        cout << *pszCmdLine << endl;
    }
 
   
    system("PAUSE");
    return 0;
}
 
HWND AOL()
{
    HWND AOLwindow;
    AOLwindow = FindWindowEx(0,0,"AOL Frame25",0);
    return AOLwindow;  
}
 
HWND MDI()
{
    HWND MDIwindow;
    MDIwindow = FindWindowEx(AOL(),0,"MDIClient",0);
    return MDIwindow;    
}
 
HWND FindChat()
{
     HWND hwndChild = 0, hwndAOLChatForm = 0;
     
     do
     {
          hwndAOLChatForm = FindWindowEx(hwndChild, 0, "_AOL_Static", "AOL_CHAT_FORM");
          if (hwndAOLChatForm) break;
          hwndChild = FindWindowEx(MDI(), hwndChild, "AOL Child", 0);
     }
     while (hwndChild);
     return hwndChild;
}
 
HWND ListBox()
{
    HWND listbox;
    listbox = FindWindowEx(FindChat(),0,"_AOL_Listbox",0);
    return listbox;
}
 
 
0
Comment
Question by:crims
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
The error is how you are addressing the pointers:

        itemData = SendMessage(ListBox(), LB_GETITEMDATA,(WPARAM) 10,0);
        Baddress = &itemData; // incorrect, no '&' needed, that is only valid in *your* process
       
        ReadProcessMemory(OpenProc,(LPCVOID)*Baddress,pszCmdLine,20,&bytes); // incorrect, no '*' needed, that is only valid in *your* process

Just make that read

        itemData = SendMessage(ListBox(), LB_GETITEMDATA,(WPARAM) 10,0);
        Baddress = (DWORD) itemData;
       
        ReadProcessMemory(OpenProc,(LPCVOID)Baddress,pszCmdLine,20,&bytes);

and you should be there.
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
After applying jkr's correction you can get correct item data, but why do you think that it points to the item string? To read listbox string from another process you need some additional code.
You can learn how to do this in the following article:
http://www.codeguru.com/cpp/misc/misc/article.php/c3807/
0
 

Author Comment

by:crims
Comment Utility

    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
        */

         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
 

Author Comment

by:crims
Comment Utility
Alex thanks for the url. But are you saying i need to use the VirtualAllocEx() ??
Alex, or jkr, how would you print out a string from the listbox with the code above? using the "cout << "
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

7 Experts available now in Live!

Get 1:1 Help Now