Fake virus program

Hi everyone! I made a fake virus program, please try it out. Please tell me where I can improve, and how I can do that. It may not work on some computers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//#define WINVER 0x0500
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    //INPUT ip;

    cout<<"Hello! You are being hacked... I strongly suggest you close your sticky notes   right now."<<endl;
    Sleep(5000);
    cout<<"In five seconds, you will be controlled. If you want to survive, close this     program now."<<endl;
    Sleep(5000);
    cout<<"Very well. You chose to be controlled."<<endl;
    Sleep(1000);
    for(int i=0;i<20;++i){
        SetCursorPos(1330,10); //move cursor to the X button
        mouse_event(MOUSEEVENTF_LEFTDOWN,1330,10,0,0); //click
        mouse_event(MOUSEEVENTF_LEFTUP,1330,10,0,0); //click
        Sleep(100);
    }
    cout<<"Ha ha ha!!!"<<endl;
    Sleep(1000);
    HWND foreground=GetForegroundWindow();
    ShowWindow(foreground,SW_HIDE); //hide console window


    /*ip.type = INPUT_KEYBOARD;      All this is for auto typing, but I figured out that it was pretty useless unless it manages to open notepad or something, so I just commented it out
    ip.ki.wScan = 0;
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;

    ip.ki.wVk = 0x41;
    ip.ki.dwFlags = 0;
    SendInput(1, &ip, sizeof(INPUT));

    ip.ki.dwFlags = KEYEVENTF_KEYUP;
    SendInput(1, &ip, sizeof(INPUT));*/


    int x,y;
    for(int i=0;i<10000;i++){
        x=rand()%1000;
        y=rand()%800;
        SetCursorPos(x,y); //move cursor to random position
        mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0); //click
        mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0); //click
        mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0); //click
        mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0); //click
    }
    return 0;
}

Thanks!!!
Last edited on
elite hackzor
For starters you could avoid using using namespace std; and simply use either using std::cout; (cout could be endl or anything in the namespace) or type std:: before each time. This will avoid naming conflicts which namespaces are there to prevent.

You should also avoid magic numbers.
What is a magic number?
An arbitrary constant value that is not assigned to a variable and is used multiple times without any indication as to what it is and why you picked it.

Examples:
1
2
3
4
5
6
7
8
9
10
Sleep(5000); //5 seconds?
Sleep(1000); //1 second?
for(int i=0;i<20;++i) //20?
SetCursorPos(1330,10); //move cursor to the X button //1330? 10?
        mouse_event(MOUSEEVENTF_LEFTDOWN,1330,10,0,0); //click 1330? 10?
        mouse_event(MOUSEEVENTF_LEFTUP,1330,10,0,0); //click 1330? 10?
        Sleep(100); //.1sec?
for(int i=0;i<10000;i++) //10000?
        x=rand()%1000; /1000?
        y=rand()%800; //800? 


http://en.wikipedia.org/wiki/Magic_number_(programming)
Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants
Last edited on
Why should I avoid using them? What's wrong?
Well if someone else or you ever look back at the code then you/they will be wondering why those arbitrary values were picked. You can do what ever you want its up to you but I personally avoid magic numbers. Also, if you ever make changes to your program you are going to be in a load of hurts. For example:

say you have an array you are using that has a size of 7 and later you decide you want to change the size to 10 now you are going to have problems if you are using this magic number '7' instead of using a variable called size and using that.

http://stackoverflow.com/questions/47882/what-is-a-magic-number-and-why-is-it-bad
A hypothetical about magic numbers:

1
2
call_a_function( 10 );
call_another( 10 );


If I change one of those tens, do I need to change the other? We can't tell unless we look at the code in the functions, and the abstraction of the code is a main reason for the function in the first place.
Last edited on
Yes, I get it.
Are there any other problems?
looks good, will try this :D
Thanks
Sorry my antivirus caught it....
Just kidding; that bloody thing just clicked every icon on my desktop :-D.

Anyway I am not expert on windows api but shouldn't the lines be in order 47-49-48-50 (for double-click)?
Maybe you could do function to call instead
1
2
3
4
5
6
7
8
9
10
11
12
void click(int x, int y)
{
   mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0);
   mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
}

void doubleClick(int x, int y)
{
   for(int i=0; i<2; i++) {
      click(x,y);
   }
}


What you could possibly improve is for the function to get somehow your window resolution and set that numbers to lines 44-45.

Also do you really need SetCursorPos(x,y); if mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0); already have the position information in them?
Yes I do need SetCursorPos(x,y);, sometimes it doesn't actually click the right place when I do mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0);.
Topic archived. No new replies allowed.