Results 1 to 9 of 9

Thread: Process handle

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default Process handle

    Can someone tell me why this doesn't work? Sorry this is yet another project I'm working on for work haha.
    Anywho, I don't see why the code wouldn't work because I know I use something very similar when I read\write process memory. Anywho, the program works, but it only works when the program I'm trying to gain access to is already open, if it's not already open then the code doesn't work and I don't see why hmm..
    Anywho here is the code. Pretty simple.
    PHP Code:
    // MHC-CM.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <cstdlib>

    int _tmain(int argc_TCHARargv[])
    {
        
    HWND hWnd FindWindow("TfrmConfirmCacheMaintenance","Confirmation");    

        while(
    1)
        {
            
    Sleep(100);
            
            
    top:

            if(!(
    hWnd))
            {
                
    Sleep(1000);
                goto 
    top;
            }
            else if(
    hWnd)
            { 
                
    DWORD ProcessID
                
    GetWindowThreadProcessIdhWnd, &ProcessID ); 
                
    HANDLE Process OpenProcessPROCESS_ALL_ACCESSFALSEProcessID ); 

                if(
    Process)
                {
                    
    keybd_event(VK_RIGHTNULLNULLNULL);
                    
    keybd_event(VK_RIGHTNULLKEYEVENTF_KEYUPNULL);
                    
    keybd_event(VK_RETURNNULLNULLNULL);
                    
    keybd_event(VK_RETURNNULLKEYEVENTF_KEYUPNULL);

                    goto 
    top;

                    
    CloseHandle(Process);
                }
            }
        }
        return 
    0;

    Basically I am trying to gain access to a messagebox for an application. The messagebox window has the class title\ name which is what I use here
    Code:
    FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
    The message box prompts "Yes" or "No I will do it next time."

    I want to force the cache maintenance for the user every time it comes up. Now What I tried doing is debugging the application and find the function that controls the message box, but the problem is that it's a HUGE exe (40+ mb) and it's packed. I couldn't figure out how to unpack it, and when I try to BP it in runtime, it crashes even with all the protection for ollydbg. I figured just writing a simple app would be the easiest way, but my original idea was to just set an unconditional jump so it always ends up doing the cache maintenance even if the user presses "No".

    Anywho, what do you recommend\suggest? BTW, the program I'm trying to modify is coded in Borland Delphi 6.0-7.0.

  2. #2

    Default

    maybe because you only try to find the window at process startup? -_-

  3. #3
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Oh GOD I'm pathetic. Thanks I got it now haha.

  4. #4
    Administrator JoTo's Avatar
    Join Date
    May 2010
    Location
    www.scapp.net
    Posts
    1,953

    Default

    I like your goto's they remind me of good old Basic, though they are not really nescessary here or ? I mean u use them to jump back while your inside the loop, when u would remove them u would get anyway to that jump point when the loop makes it turn. Question I have, is this a win32 application, and does it contain a window or just a shell, I mean does the Windows command window pop up when u run it ?

  5. #5
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    You're right the goto's weren't necessary. I rewrote it and now everything works perfectly. Here is the new code. Oh, and yes, I was thinking like wtf it's not making the jump so lets force it with a old school goto haha.
    PHP Code:
    // MHC-CM.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <cstdlib>

    int _tmain(int argc_TCHARargv[])
    {
        
    // Stealth mode so we don't see the command prompt window
        
    HWND stealth FindWindowA("ConsoleWindowClass",NULL);
        
    FreeConsole();

        while(
    1)
        {
            
    //Cache Maintenance Window
            
    HWND hWnd1 FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
            
    //Purge Maintenance Window
            
    HWND hWnd2 FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
            
    Sleep(100);

            
    //This portion checks for the Cache Maintenance Message Box
            
    if(hWnd1)
            { 
                
    //Cache Maintenance Window
                
    DWORD ProcessID1
                
    GetWindowThreadProcessIdhWnd1, &ProcessID1 ); 
                
    HANDLE Process1 OpenProcessPROCESS_ALL_ACCESSFALSEProcessID1 ); 

                if(
    Process1)
                {
                    
    //Emulated keypresses
                    /*
                    keybd_event(VK_RIGHT, NULL, NULL, NULL);
                    keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
                    */
                    
    keybd_event(VK_RETURNNULLNULLNULL);
                    
    keybd_event(VK_RETURNNULLKEYEVENTF_KEYUPNULL);

                    
    CloseHandle(Process1);
                }
            }

            
    //This portion checks for the Purge Maintenance Message Box
            
    else if(hWnd2)
            { 
                
    //Purge Maintenance Window
                
    DWORD ProcessID2
                
    GetWindowThreadProcessIdhWnd2, &ProcessID2 ); 
                
    HANDLE Process2 OpenProcessPROCESS_ALL_ACCESSFALSEProcessID2 ); 

                if(
    Process2)
                {
                    
    //Emulated keypresses
                    /*
                    keybd_event(VK_RIGHT, NULL, NULL, NULL);
                    keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
                    */                
                    
    keybd_event(VK_RETURNNULLNULLNULL);
                    
    keybd_event(VK_RETURNNULLKEYEVENTF_KEYUPNULL);

                    
    CloseHandle(Process2);
                }
            }
        }
        return 
    0;

    Question I have, is this a win32 application, and does it contain a window or just a shell, I mean does the Windows command window pop up when u run it ?
    Yes the command prompt window comes up, but I learned this little trick that hides it & it works flawlessly.
    Code:
        // Stealth mode so we don't see the command prompt window
        HWND stealth = FindWindowA("ConsoleWindowClass",NULL);
        FreeConsole();
    You can see it used in my code above!

    NOTE: I know both my window handles are the same, that's because I can't get the handle on the purge maintenance yet because I can't get it to come up atm. Just figured I would mention that if people are like wtf.. why are you doing the same thing twice haha. Once I get the class & title name then I'll update hWnd2 and voila!

  6. #6
    Administrator JoTo's Avatar
    Join Date
    May 2010
    Location
    www.scapp.net
    Posts
    1,953

    Default

    ah ok, thx for info, your stuff actually helps me understanding more c/c++ (I must admit I wouldn't be able to code it on my own from scratch, but pssss thats a secret ). The goto made me think about to write a clone with .net, for my understanding: is it that u actually are searching for the message box of the application, if it is found then you simply send the return key to it ?

  7. #7
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    That is correct yes. And I would have never guessed that you weren't self confident in c\++. I for sure thought you knew it well, atleast the basics. Well I'm glad my code helps you understand the concept and learning from it. I have to continue doing these small programs because if I stop for a long time I start to forget alot and you can tell haha. To be completly honest I am not very proficient in c\++ either, but I'm guessing that's quite noticeable by now haha. I just keep trying and seeing how far I can go.

  8. #8

    Default

    just set your app as windows application instead of console app, then u dont have to hide the console?

    and if you are determined of doing it like this, u dont need this line:
    HWND stealth = FindWindowA("ConsoleWindowClass",NULL);

    because the FreeConsole already detaches the console for you.

  9. #9
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Oh haha, thanks for the tidbit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •