Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-17
4
Medium Priority
?
285 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 1500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
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…
Suggested Courses

609 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