Advertisemen
First I was wondering how to create a brute forcing application for i.e. passwords, I then realised to do that you would have to access the elements in another application. I had to no clue how to do this, it involved delving into the Windows API... So I did!
I then made a small program which can play and pause music in iTunes:
#include <iostream>
#include <Windows.h>
int main()
{
//get the itunes windows
HWND windowHandle = FindWindow(NULL,L"iTunes");
//since the play button alternates between two captions, play and pause, two handles must be created
HWND playHandle = FindWindowEx(windowHandle,NULL,L"Button",L"play");
HWND pauseHandle = FindWindowEx(windowHandle,NULL,L"Button",L"pause");
//if a handle exists then click it
if (playHandle) SendMessage(playHandle,BM_CLICK,NULL,NULL);
if (pauseHandle) SendMessage(pauseHandle,BM_CLICK,NULL,NULL);
return 0;
}
Next up, is entering a message in a console application, press send and have it sent to a recipient on Skype!
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
int main()
{
LPCWSTR windowName = L"Skype™ - alexdiru";
HWND windowHandle = FindWindow(NULL,windowName);
if (!windowHandle) cout << "Window not found: " << windowName << endl;
//get the text box you type in
HWND textHandle = (HWND)0x000204DC;
//if a handle exists then type "hello"
if (textHandle) SendMessage(textHandle,WM_SETTEXT,NULL,(LPARAM)"hello");
else cout << "Error" << endl;
return 0;
}
I have got as far to write to the Skype text box, though writing “hello” here results in “敨汬o” being entered in the Skype box… At least the ‘o’ is correct. Maybe this is a problem Skype has, I shall try and enter text into notepad:
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
int main()
{
HWND windowHandle = (HWND)0x00030976;
if (!windowHandle) cout << "Window not found" << endl;
//get the text box you type in
HWND textHandle = (HWND)0x00020992;
//if a handle exists then type "hello"
if (textHandle) SendMessage(textHandle,WM_SETTEXT,NULL,(LPARAM)"hello");
else cout << "Error" << endl;
return 0;
}
This results in the same error. However changing the 4th parameter in the SendMessage function from (LPARAM)”hello” to (LPARAM)L”hello” displays the “hello” correctly. Therefore for Skype, this code works correctly:
lass="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;">#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
int main()
{
//get skype window
HWND windowHandle = (HWND)0x00010478;
if (!windowHandle) cout << "Window not found" << endl;
//get the text box you type in
HWND textHandle = (HWND)0x000204DC;
//if a handle exists then type "hello"
if (textHandle) SendMessage(textHandle,WM_SETTEXT,NULL,(LPARAM)L"hello");
else cout << "Textbox not found" << endl;
return 0;
}
Now I need to ability to be able to send the message on Skype. There seems to be no way to get the handle for the Send Message button on Skype using Spy++. So maybe passing an Enter to the textbox will send the message.
Sending VK_RETURN as a message didn’t work. I searched around and found a method that did:
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
HWND getSkypeConversationBox() { return (HWND)0x000204DC; }
int main()
{
//get the text box you type in
HWND textHandle = getSkypeConversationBox();
if (!textHandle) cout << "Skype Conversation Box not found" << endl;
SendMessage(textHandle,WM_SETTEXT,NULL,(LPARAM)L"hello"); //message
PostMessage(textHandle,WM_KEYDOWN,VK_RETURN,NULL); //return key
return 0;
}
Thus the code to allow the user to specify their own message:
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
HWND getSkypeConversationBox() { return (HWND)0x000204DC; }
//converts string to wstring
//code from stackoverflow.com/questions/27220/how-to-convert-stdstring-to-lpcwstr-in-c-unicode
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
int main()
{
//get the text box you type in
HWND textHandle = getSkypeConversationBox();
if (!textHandle) cout << "Skype Conversation Box not found" << endl;
//message entering
string message;
cout << "Enter your message:" << endl;
getline(cin,message);
SendMessage(textHandle,WM_SETTEXT,NULL,(LPARAM)(s2ws(message)).c_str()); //message
PostMessage(textHandle,WM_KEYDOWN,VK_RETURN,NULL); //return key
return 0;
}
Advertisemen
Tidak ada komentar:
Posting Komentar