Solved

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

Posted on 2006-06-17
4
279 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
ADO Memory leak with DELPHI 2007 37 170
not able to insert into temp table 68 157
fizzArray  challenge 1 63
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

920 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

15 Experts available now in Live!

Get 1:1 Help Now