hook [modified]
-
hi i coded a hook dll,but when i wanna add a file and write the result i dont know what happens.my file is wrong or somtimes it's empty (but messagebos shows the right result !!!!!!!) here is my code: #include "a.h" #include #include #include #include #include #include #include #include #include #include #include #include int x=0; int stream; FILE* fout; static BOOL bHooked = FALSE; static HHOOK CBT=0,CBT1=0; static HINSTANCE hInst; static int count; char szModName[1024]; char szModName1[1024]; char nul[1024]; char win[1024]; void GetWinDir(void); LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam); //LRESULT CALLBACK CBTProc1(int code, WPARAM wParam, LPARAM lParam); BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: hInst=hinstDLL; count=0; break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; default: break; } return TRUE; } DLL_EXPORT void BagaHooku(void) { if(!bHooked) { CBT = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, hInst, (DWORD)NULL); /// CBT1 = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc1, hInst, (DWORD)NULL); bHooked = TRUE; } } DLL_EXPORT void ScoateHooku(void) { if(bHooked) { UnhookWindowsHookEx(CBT); // UnhookWindowsHookEx(CBT1); } } LRESULT CALLBACK CBTProc(int nCode,WPARAM wParam,LPARAM lParam) { if ((nCode==HCBT_ACTIVATE)||(nCode==HCBT_SYSCOMMAND)||(nCode==HCBT_QS)||(nCode==HCBT_CREATEWND)) //if (nCode==HCBT_DESTROYWND) { //MessageBox (NULL, TEXT ("send processes"), TEXT ("HelloMsg"), 0) ; HANDLE hProc; HMODULE hMods[1024]; DWORD n; DWORD dwProcessId ; DWORD lpExitCode; DWORD dwSize,dwType,dwDisp; HKEY Regentry; char *host1; char host[1024]; char rezerva[1024]; //MessageBox (NULL, TEXT ("send processes"), TEXT ("HelloMsg"), 0) ; GetWindowThreadProcessId((HWND)wParam, &dwProcessId); hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)dwProcessId); if(EnumProcessModules(hProc, hMods, sizeof(hMods), &n)) { if (n>0) GetModuleFileNameEx(hProc, hMods[0], szModName, sizeof(szModName)); } GetExitCodeProcess(hProc,&lpExitCode); if(!(host1=strrchr(szModName,'\\'))) strcpy(host,szModName); else strcpy(host,host1
-
hi i coded a hook dll,but when i wanna add a file and write the result i dont know what happens.my file is wrong or somtimes it's empty (but messagebos shows the right result !!!!!!!) here is my code: #include "a.h" #include #include #include #include #include #include #include #include #include #include #include #include int x=0; int stream; FILE* fout; static BOOL bHooked = FALSE; static HHOOK CBT=0,CBT1=0; static HINSTANCE hInst; static int count; char szModName[1024]; char szModName1[1024]; char nul[1024]; char win[1024]; void GetWinDir(void); LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam); //LRESULT CALLBACK CBTProc1(int code, WPARAM wParam, LPARAM lParam); BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: hInst=hinstDLL; count=0; break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; default: break; } return TRUE; } DLL_EXPORT void BagaHooku(void) { if(!bHooked) { CBT = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, hInst, (DWORD)NULL); /// CBT1 = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc1, hInst, (DWORD)NULL); bHooked = TRUE; } } DLL_EXPORT void ScoateHooku(void) { if(bHooked) { UnhookWindowsHookEx(CBT); // UnhookWindowsHookEx(CBT1); } } LRESULT CALLBACK CBTProc(int nCode,WPARAM wParam,LPARAM lParam) { if ((nCode==HCBT_ACTIVATE)||(nCode==HCBT_SYSCOMMAND)||(nCode==HCBT_QS)||(nCode==HCBT_CREATEWND)) //if (nCode==HCBT_DESTROYWND) { //MessageBox (NULL, TEXT ("send processes"), TEXT ("HelloMsg"), 0) ; HANDLE hProc; HMODULE hMods[1024]; DWORD n; DWORD dwProcessId ; DWORD lpExitCode; DWORD dwSize,dwType,dwDisp; HKEY Regentry; char *host1; char host[1024]; char rezerva[1024]; //MessageBox (NULL, TEXT ("send processes"), TEXT ("HelloMsg"), 0) ; GetWindowThreadProcessId((HWND)wParam, &dwProcessId); hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)dwProcessId); if(EnumProcessModules(hProc, hMods, sizeof(hMods), &n)) { if (n>0) GetModuleFileNameEx(hProc, hMods[0], szModName, sizeof(szModName)); } GetExitCodeProcess(hProc,&lpExitCode); if(!(host1=strrchr(szModName,'\\'))) strcpy(host,szModName); else strcpy(host,host1
You'd get a lot more help if you'd narrow this down to just a handful of lines. No one likes to wade through complete programs, or even several pages of code, to locate a problem. Try:
void main( void )
{
char host[1024], szModName[1024], *host1; // initialize these accordinglyif (! (host1 = strrchr(szModName, '\\\\'))) strcpy(host, szModName); else strcpy(host, host1 + 1); FILE \*fout = fopen("out.txt", "a+"); fwrite(host, 1, strlen(host), fout); fclose(fout);
}
Now step through each of these until you locate the offending statement.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
hi i coded a hook dll,but when i wanna add a file and write the result i dont know what happens.my file is wrong or somtimes it's empty (but messagebos shows the right result !!!!!!!) here is my code: #include "a.h" #include #include #include #include #include #include #include #include #include #include #include #include int x=0; int stream; FILE* fout; static BOOL bHooked = FALSE; static HHOOK CBT=0,CBT1=0; static HINSTANCE hInst; static int count; char szModName[1024]; char szModName1[1024]; char nul[1024]; char win[1024]; void GetWinDir(void); LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam); //LRESULT CALLBACK CBTProc1(int code, WPARAM wParam, LPARAM lParam); BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: hInst=hinstDLL; count=0; break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: break; default: break; } return TRUE; } DLL_EXPORT void BagaHooku(void) { if(!bHooked) { CBT = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, hInst, (DWORD)NULL); /// CBT1 = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc1, hInst, (DWORD)NULL); bHooked = TRUE; } } DLL_EXPORT void ScoateHooku(void) { if(bHooked) { UnhookWindowsHookEx(CBT); // UnhookWindowsHookEx(CBT1); } } LRESULT CALLBACK CBTProc(int nCode,WPARAM wParam,LPARAM lParam) { if ((nCode==HCBT_ACTIVATE)||(nCode==HCBT_SYSCOMMAND)||(nCode==HCBT_QS)||(nCode==HCBT_CREATEWND)) //if (nCode==HCBT_DESTROYWND) { //MessageBox (NULL, TEXT ("send processes"), TEXT ("HelloMsg"), 0) ; HANDLE hProc; HMODULE hMods[1024]; DWORD n; DWORD dwProcessId ; DWORD lpExitCode; DWORD dwSize,dwType,dwDisp; HKEY Regentry; char *host1; char host[1024]; char rezerva[1024]; //MessageBox (NULL, TEXT ("send processes"), TEXT ("HelloMsg"), 0) ; GetWindowThreadProcessId((HWND)wParam, &dwProcessId); hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)dwProcessId); if(EnumProcessModules(hProc, hMods, sizeof(hMods), &n)) { if (n>0) GetModuleFileNameEx(hProc, hMods[0], szModName, sizeof(szModName)); } GetExitCodeProcess(hProc,&lpExitCode); if(!(host1=strrchr(szModName,'\\'))) strcpy(host,szModName); else strcpy(host,host1
are you sure you are looking at the correct out.txt file? because this code looks fine: (isolated that is) fout = fopen("out.txt", "a+"); fwrite(host, 1,strlen(host), fout); fclose(fout); Is this a Unicode project? AliR. Visual C++ MVP
-
You'd get a lot more help if you'd narrow this down to just a handful of lines. No one likes to wade through complete programs, or even several pages of code, to locate a problem. Try:
void main( void )
{
char host[1024], szModName[1024], *host1; // initialize these accordinglyif (! (host1 = strrchr(szModName, '\\\\'))) strcpy(host, szModName); else strcpy(host, host1 + 1); FILE \*fout = fopen("out.txt", "a+"); fwrite(host, 1, strlen(host), fout); fclose(fout);
}
Now step through each of these until you locate the offending statement.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
are you sure you are looking at the correct out.txt file? because this code looks fine: (isolated that is) fout = fopen("out.txt", "a+"); fwrite(host, 1,strlen(host), fout); fclose(fout); Is this a Unicode project? AliR. Visual C++ MVP
salam are file ijad mishe.ama mohtaviyatesh gheire marbote.hamihe esme barnameye hoohamo minevise! dar hali ke man mohtavaiyate hosto ba message box ke nehson midam doroste ama vaghti to iflemikhad benevise eshtebah darm miad. to rahi dari ke ijade proceesaro elam kone man enumprocess gozahstam ta prosseaye jari ro nehson bede bad kolehso to ye file mirizam. hala mikham hamishe update bashe baraye hamin hook gozahstam ke age ye processe jadidi ijad shod ya kill shod eb man etela bede ta ono be on file ezafe konam. be nazaret rahe digei ham hast ke proceesa ro monitor konam berizam to file?