Re: Добраться до данных другого процесса. Это реально?
От: Lokki Зимбабве  
Дата: 23.11.01 13:19
Оценка:
Здравствуйте scopr21, Вы писали:

S>Например, есть у нас программа с картой месности, а в статус баре кажутся координаты географические того места, где курсор.

S>Моя идея — навести мышь на место, а в другой программе эти координаты подсматривать.

S>Как это вообще реализовать можно.

S>Пытался через handle окна добраться — ничего не получилось.
S>Думал, может какие сообщения WM_SETTEXT, или что-то подобное шлет — нифига не шлет :))
S>Пробовал, как дочерний процесс запустить — тоже ничего не вышло (в смысле до данных добраться).

S>Народ, тема думаю многим интересна будет — дайте плиз наметки — куда пробовать.


S>Заранее спасибо.


вот кусок кода, который тупым образом подбирает пароли к sub7 server editor
на примере этого можно ипхать куда угодно.
кроме того — до некоторых данных ты можешь добраться весьма тривиальным образом :
получить handle этого child-window (для начала можно тем же самым SPYXX)
потом
CWnd * pWnd;
pWnd::FromHandle (hHwnd);
pWnd->GetWindowText(...);
pWnd->SetWindowText(...);
pWnd->GetDlgItemText(...);
pWnd->SetDlgItemText(...);
но у меня не получалось так добираться до некоторых окон которые сделаны в Delphi

#include "stdafx.h"
#include "sub7.h"
#include "sub7Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "windows.h"
#include "winuser.h"
#include "process.h"

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSub7Dlg dialog

CSub7Dlg::CSub7Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CSub7Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSub7Dlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
thr_status=TRUE;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSub7Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSub7Dlg)
DDX_Control(pDX, IDC_BUTTON4, m_pause);
DDX_Control(pDX, IDC_EDIT3, m_filename);
DDX_Control(pDX, IDC_BUTTON3, m_stopbtn);
DDX_Control(pDX, IDC_BUTTON2, m_openbtn);
DDX_Control(pDX, IDC_BUTTON1, m_startbtn);
DDX_Control(pDX, IDC_EDIT2, m_interval);
DDX_Control(pDX, IDC_EDIT1, m_log);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSub7Dlg, CDialog)
//{{AFX_MSG_MAP(CSub7Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSub7Dlg message handlers

BOOL CSub7Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
/* LVCOLUMN m_col1;
m_col1.mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH;
m_col1.fmt=LVCFMT_LEFT;
m_col1.cx=50;
m_col1.pszText=_T("PID");
m_col1.iSubItem=0;
m_tlist.InsertColumn(0,&m_col1);
m_col1.iSubItem=1;
m_col1.pszText=_T("Name");
m_col1.cx=100;
m_tlist.InsertColumn(1,&m_col1);
*/
HINSTANCE huserlib = LoadLibrary("user32.dll");
if (!huserlib) {MessageBox("Error","Error loading library",MB_OK);}
myinf = (pGetWindowInfo) GetProcAddress (huserlib,_T("GetWindowInfo"));
WINDOWINFO tinf;
if (!myinf) {MessageBox("Error","Error Get Proc",MB_OK);}
myinf(this->GetSafeHwnd(),&tinf);
m_interval.SetWindowText(_T("10"));
// m_startbtn.ModifyStyle(0,WS_DISABLED,0);
// m_startbtn.RedrawWindow();
m_stopbtn.ModifyStyle(0,WS_DISABLED,0);
m_pause.EnableWindow(FALSE);
m_stopbtn.RedrawWindow();
m_filename.SetWindowText(_T("Pass File : "));

return TRUE; // return TRUE unless you set the focus to a control
}

void CSub7Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CSub7Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() — cxIcon + 1) / 2;
int y = (rect.Height() — cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSub7Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CSub7Dlg::OnButton1()
{ __try {
if (!(ftell (passwdfile) ^ 0xffffffff)){this->OnButton2();};
}
__except (this->OnButton2(),1) {}
if (NULL == (htermevent = CreateEvent(NULL,TRUE,FALSE,_T("breakevent")))){
MessageBox(_T("Can't create event"));
};
if (!ResetEvent(htermevent)){MessageBox (_T("Can't Reset Event"));} ;
thr_id = _beginthread(this->processpasswdz,0,this);
m_startbtn.ModifyStyle(0,WS_DISABLED,0);
m_startbtn.RedrawWindow();
m_stopbtn.ModifyStyle(WS_DISABLED,0,0);
m_stopbtn.RedrawWindow();
m_openbtn.ModifyStyle(0,WS_DISABLED,0);
m_openbtn.RedrawWindow();
m_pause.EnableWindow(TRUE);
m_pause.RedrawWindow();
m_filename.SetWindowText((LPCTSTR)passfilename);
}

void CSub7Dlg::SendPasswd(CHAR* passwd)
{
HWND hmainwnd = ::FindWindow (_T("TEditForm"),NULL);
HANDLE hlocalevent = OpenEvent (EVENT_ALL_ACCESS,FALSE,_T("breakevent"));
POINTS apoint;
DWORD* wparm;
apoint.x=374;
apoint.y=39;
wparm = (LPDWORD) &apoint;
// ::SetForegroundWindow(hmainwnd);
// ::SetActiveWindow(hmainwnd);
::PostMessage(hmainwnd,WM_LBUTTONDOWN,MK_LBUTTON,*wparm);
::PostMessage(hmainwnd,WM_LBUTTONUP,MK_LBUTTON,*wparm);

HWND thewnd = ::FindWindow(_T("TGetTextForm"),"");
HWND hpasswdwnd = ::FindWindowEx(thewnd,NULL,_T("TFlatEdit"),NULL);
while (!IsVisible(thewnd)&& (WaitForSingleObject(hlocalevent,0) != WAIT_OBJECT_0)){}

// ::SetActiveWindow(hpasswdwnd);
apoint.x=93;
apoint.y=95;
// ::SetForegroundWindow(hpasswdwnd);
SendString(hpasswdwnd,passwd);
// ::SendMessage(thewnd,WM_CHAR,VK_RETURN,1);
wparm = (LPDWORD) &apoint;
//Simulation of Mouseclick on the OK button
::SendMessage(thewnd,WM_LBUTTONDOWN,MK_LBUTTON,*wparm);
::SendMessage(thewnd,WM_LBUTTONUP,MK_LBUTTON,*wparm);
while (IsVisible(thewnd)&& (WaitForSingleObject(hlocalevent,0) != WAIT_OBJECT_0)){};
HWND herrorwnd = ::FindWindow(_T("TMsgForm"),_T("message"));
POINTS thepoint;
thepoint.x=66;
thepoint.y=60;
DWORD* theparm;
theparm=(LPDWORD) &thepoint;

while (!IsVisible(herrorwnd)&& (WaitForSingleObject(hlocalevent,0) != WAIT_OBJECT_0)){};

// ::SetActiveWindow(herrorwnd);
// ::SetForegroundWindow(herrorwnd);
::SendMessage(herrorwnd,WM_LBUTTONDOWN,MK_LBUTTON,*theparm);
::SendMessage(herrorwnd,WM_LBUTTONUP,MK_LBUTTON,*theparm);
while (IsVisible(herrorwnd)&& (WaitForSingleObject(hlocalevent,0) != WAIT_OBJECT_0)){};
}

BOOL CSub7Dlg::IsVisible(HWND hwnd)
{
WINDOWINFO theinfo;
myinf(hwnd,&theinfo);
return (theinfo.dwStyle & WS_VISIBLE);
}

void CSub7Dlg::SendString(HWND hwnd, CHAR *m_str)
{
int f;
for (f=0;(f<=(strlen(m_str)-1));f++)
{
if (m_str[f]!=0x0A){
::SendMessage(hwnd,WM_CHAR,m_str[f],1);}
}
}

void CSub7Dlg::OnButton2()
{
// TODO: Add your control notification handler code here
CFileDialog pfiledlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,NULL,NULL);
if ( pfiledlg.DoModal() != IDCANCEL ) {
CString aa = pfiledlg.GetPathName ();
passfilename = _T("Pass File : ");
passfilename += pfiledlg.GetFileName();
passwdfile = fopen (aa,"r");
if (!passwdfile){MessageBox(_T("Error opening passwdfile"),_T("Error opening log"),MB_OK);}
logfile = fopen (_T("log.txt"),"a");
if (!logfile){MessageBox(_T("Error opening logfile"),_T("Error opening log"),MB_OK);}
m_startbtn.ModifyStyle(WS_DISABLED,0,0);
m_openbtn.ModifyStyle(0,WS_DISABLED,0);
this->RedrawWindow();
}
}
void __cdecl CSub7Dlg::processpasswdz (void *dummy)
{
// TODO: Add your control notification handler code here
HANDLE hlocalevent = OpenEvent (EVENT_ALL_ACCESS,FALSE,_T("breakevent"));
CSub7Dlg *likethis;
likethis = (CSub7Dlg*) dummy;
int f = 0;
CHAR *stopstring, *strint = new CHAR[5];
likethis->m_interval.GetWindowText(strint,5);
// memset (strint,0,5);
int loginterval =0;
int curlog = 0;
loginterval=strtol(strint,&stopstring,10);
CString aaa;
curlog=loginterval;
CHAR* pass = new CHAR[1024];
while (fgets(pass ,1024,likethis->passwdfile) && (WaitForSingleObject(hlocalevent,0) != WAIT_OBJECT_0)){

likethis->SendPasswd(pass);
// SendString ((HWND)0x00660546,pass);
CString count;
count.Format("%d",f);
likethis->m_log.SetWindowText((LPCTSTR) count );
f++;
curlog--;
if (curlog==0) {
fputs(pass,likethis->logfile);
likethis->UpdateWindow();
likethis->RedrawWindow();

curlog=loginterval;
fflush (likethis->logfile);
};
}
long a = ftell (likethis->logfile);
fclose (likethis->logfile);
fclose (likethis->passwdfile);
long b = (ftell (likethis->logfile) ^ 0xffffffff);
// if (b ^ 0xffffffff)
delete pass;
// delete stopstring;
delete strint;
likethis->m_openbtn.ModifyStyle (WS_DISABLED,0,0);
likethis->m_startbtn.ModifyStyle(WS_DISABLED,0,0);
likethis->m_stopbtn.ModifyStyle(0,WS_DISABLED,0);
likethis->RedrawWindow();

}

void CSub7Dlg::OnButton3()
{
// TODO: Add your control notification handler code here

// bool a = TerminateThread (thr_id,1);
if (!SetEvent(htermevent)){MessageBox (_T("Can't send stop signal"));}
if (!thr_status) {
::ResumeThread ((void*)thr_id);
m_pause.SetWindowText(_T("Pause"));
thr_status=TRUE;
}
m_openbtn.ModifyStyle (WS_DISABLED,0,0);
m_startbtn.ModifyStyle(WS_DISABLED,0,0);
m_stopbtn.ModifyStyle(0,WS_DISABLED,0);
m_pause.EnableWindow(FALSE);
this->RedrawWindow();
}


void CSub7Dlg::OnButton4()
{
// TODO: Add your control notification handler code here
if (thr_status){
::SuspendThread ((void*)thr_id);
m_pause.SetWindowText(_T("Continue"));
thr_status=FALSE;
} else
{
::ResumeThread ((void*)thr_id);
m_pause.SetWindowText(_T("Pause"));
thr_status=TRUE;
}

}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.