Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. hook [modified]

hook [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    farshad f
    wrote on last edited by
    #1

    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

    D A 2 Replies Last reply
    0
    • F farshad f

      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

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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 accordingly

      if (! (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

      F 1 Reply Last reply
      0
      • F farshad f

        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

        A Offline
        A Offline
        Ali Rafiee
        wrote on last edited by
        #3

        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

        F 1 Reply Last reply
        0
        • D David Crow

          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 accordingly

          if (! (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

          F Offline
          F Offline
          farshad f
          wrote on last edited by
          #4

          thank u david

          1 Reply Last reply
          0
          • A Ali Rafiee

            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

            F Offline
            F Offline
            farshad f
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups