Solved

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

Posted on 2006-06-17
4
283 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
[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
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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