Help me with Spammer

Posts 1–4 of 4 · Page 1 of 1
Help me with Spammer
Hey guys, Thanks for visiting here. I need help with my c++ chat spammer coded in Dev c++. I had just started today with coding and i need help with it. Everything seems to work but the keystrokes. The keystrokes only work on Notepad and Microsoft Word and Wordpad. It does not work on Browsers like IE or Chrome. I also tried doing it on adult chats or chatrooms on the Browser and the keystrokes do not enter in the chat.

#include <iostream> #include <stdio.h> #include <Windows.h> #include "winuser - Pastebin.com

Here is the source code. Hopefully someone will help me

Also, this is my first project so please give me feedback on how i did on this project and tell me what parts i should improve on.

Thanks
Just a guess, but keybd_event usually happens in pairs - keydown and keyup. You only have keydown?
Code:
         for(int z=0;z<y;z++)
         {
                         SendMessage(edit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)text.c_str());
                         Sleep(5);
                         keybd_event(VK_RETURN,0x0D, 0, 0); 
         }
try
Code:
  for(int z=0;z<y;z++)
         {
                         SendMessage(edit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)text.c_str());
                         Sleep(5);
                         keybd_event(VK_RETURN,0x0D, 0, 0); // key_down
                         keybd_event(VK_RETURN,0x0D, 1, 0); //key_up. There is a constant defined somewhere.
         }
 
comments

1) Name your variables; x,y is not very informative. I had to analyze the loop for a moment longer than normal. Not a big deal, but not ideal either.
bool spamBot(string text, int x, int y)
{
HWND spamWindow = GetForegroundWindow(); //problem starts here, only keystrokes notepad help!
if(spamWindow == NULL)
return FALSE;
//Handle of notepad control
HWND edit = FindWindowEx( spamWindow, NULL, _T( "Edit" ), NULL );
if(edit == NULL)
return FALSE;
for(int z=0;z<y;z++)
{
.....


2) You did "using namespace std;"
but still prefix things with the namespace : p Not sure if that's good/bad/either.
int main()
{
std::string text;
std::cout << "Insert Desired Text: " << endl;
getline(cin, text);
3) Use if / elseif (instead of 2 sepearate if statements; they're obviously connected)
if (start == "y")
{
cout << "5" << endl;
Sleep(1000);
cout << "4" << endl;
Sleep(1000);
cout << "3" << endl;
Sleep(1000);
cout << "2" << endl;
Sleep(1000);
cout << "1" << endl;
Sleep(1000);
spamBot(text, intervels, numOfTimes);
}
if (start == "n")
{
return 0;
}
So if the user input 'y', then obviously the 2nd if statement's body won't execute -- but it still checks the condition. It's only a couple (?) clock cycles, so not really a big deal, but it's a very easy fix, and it's common to the language, so why not.
If you use else if ( )

then once a branch of the IF has been executed, it won't check the rest of the branches.
Code:
if (start == 'y')
{
...
}
else if (start == 'n')
{
...
}
else
{
//invalid input
}
So if the user types in 'y', it will execute it's body and then leave the entire IF statement, and not check any other cases. (You only had one other case, so again, not a big deal).


4) This will probably never occur?
You're calling main() and restart() recursively (?)

void restart()
{
cout << endl;
cout << endl;
main();
willRestart = "null";
text = "null";
intervels = 0;
numOfTimes = 0;
start = "null";
}
So, before 'restart()' can return, it has to call main --> and technically main could call 'restart()' again, and so on, forever. Eventually you'd run out of stack space (ram).

I guess it's fine, as all recursive functions do that. But if there is ever a situation where a user (or users..) continuously choose to restart, eventually it will crash. Just saying : p It's not likely, but if you could re-structure the code, you might try to do so.

-optional
Code:
if (start == "y")
{
         cout << "5" << endl;
         Sleep(1000);
         cout << "4" << endl;
         Sleep(1000);
         cout << "3" << endl;
         Sleep(1000);
         cout << "2" << endl;
         Sleep(1000);
         cout << "1" << endl;
         Sleep(1000);
                 spamBot(text, intervels, numOfTimes);
}
could become
Code:
if (start == 'y')
{
    for (int i = 5; i > 0; --i)
    {
    cout << i << endl;
    Sleep(1000);
    }
 spamBot(text, intervels, numOfTimes);
}
5 lines, counting the braces on their own line vs. 10. Is maybe more clear the way you have it now.
Ok ill try and ill message you back if it works

EDIT: Well it didn't work but thanks tho. But if you could help me with this again, i would like to say that this works on Notepad only but doesn't work anywhere else for some reason :/
Quote Originally Posted by Epuron View Post
.
Your code example specifically targets Notepad by looking for a window titled "Edit"
..I assume you change that part when you try it with another program/game? Please post the code you use when targeting another application.

HWND spamWindow = GetForegroundWindow(); //problem starts here, only keystrokes notepad help!
if(spamWindow == NULL)
return FALSE;
//Handle of notepad control
HWND edit = FindWindowEx( spamWindow, NULL, _T( "Edit" ), NULL );
if(edit == NULL)
return FALSE;
^^I think you should just use FindWindow(NULL,"caption here") to get the window's handle. Not sure why you're using GetForegroundWindow(); ??

I think the problem is you're calling SendMessage() with the wrong hWnd. ?


Change your code to display debugging errors like "Window not found", or "Unable to obtain handle for window titled *******", instead of just returning false. So you know what's actually happening other than "it doesn't work".
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us