Solved

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

Posted on 2006-06-17
4
280 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
ID: 16927480
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
ID: 16928644
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
ID: 16931509

    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
ID: 16931520
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

813 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

19 Experts available now in Live!

Get 1:1 Help Now