Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to find First window of newly created process

Featured Replies

Posted

Hello,

My question is simple. How we can detect the first window of a program which is created by CreateProcessA api? My objective is simple

1. create process with CreateProcessA api

2. Wait for first window to appear (same like advance loader generator)

3. Suspend thread and patch bytes.

Can someone please help me to know how I can wait till the first window appear?

The easiest method would be to hook the window creation API being used. (ie. CreateWindowA / CreateWindowW / CreateWindowExA / CreateWindowExW)

Or, if you don't want to hook anything, you can constantly call EnumWindows and look for windows owned by the parent process id you are looking at. When a handle finally appears you know it created something.

  • Author
2 hours ago, atom0s said:

The easiest method would be to hook the window creation API being used. (ie. CreateWindowA / CreateWindowW / CreateWindowExA / CreateWindowExW)

Or, if you don't want to hook anything, you can constantly call EnumWindows and look for windows owned by the parent process id you are looking at. When a handle finally appears you know it created something.

Hi,

So I go for the second method that you say. Now, the problem is It is not found any window regarding the created process. Here is my code.

Quote

var
  SI : TStartupInfo;
  PI : TProcessInformation;
  flag : Boolean;


function EnumWindowProc(hwnd : HWND; lParam : LPARAM):Boolean;stdcall;
var
  proid : cardinal;
begin
  GetWindowThreadProcessId(hwnd, proid);
  if proid = PI.dwProcessId then
  begin
    flag = True;       //in my case it never gone trigged
    Result := False;
    Exit;
  end; 
  Result := True;  
end;

begin
  CreateProcessA(PChar('target.exe'), nil, nil, nil, False, 0, nil, nil, SI, PI);
  EnumWindows(@EnumWIndowProc, 0);
  if flag then
     SuspendThread(Pi.hThread);
end;

2

 

Hi

1 - you should wait some time before enum windows ! (about 100~500 ms for quick apps ;) ) or check it in other thread with infinite loop (exit thread after found window in this case).

2 - you can use "FindWindow" API if you have window title (fixed one !)

3 - if your target is packed you can check bytes before patch (easier than finding window ,  etc...) !

 

 

BR,

h4sh3m

  • Author
16 minutes ago, h4sh3m said:

Hi

1 - you should wait some time before enum windows ! (about 100~500 ms for quick apps ;) ) or check it in other thread with infinite loop (exit thread after found window in this case).

2 - you can use "FindWindow" API if you have window title (fixed one !)

3 - if your target is packed you can check bytes before patch (easier than finding window ,  etc...) !

 

 

BR,

h4sh3m

Hi,

So, My objective is too make a loader same like Advance Loader Generator. As we know Advance Loader Generator, generate loader in vb format. I am not good with that to reverse that If someone can reverse a loader which is generated by ALG and tell me how it find the first window.

You will need to call EnumWindows in a loop to keep looking for the windows until one is found. Calling it once can result in your EnumWindows call happening too fast and missing the window creation. Instead, call it in a loop for either an infinite amount of time or a set amount of time you want to consider a 'timeout'. 

Also, the dwCreationFlags parameter to CreateProcessA should contain a valid creation param value. 0 is generally not what you should be using. If you want to just regularly launch the process, you should be using NORMAL_PRIORITY_CLASS (or 0x00000020 in its hex form). 

  • Author

Thanks a lot @atom0s

As you said I have to call EnumWindows function in a loop. So, I just make a while loop and keep calling EnumWindows procedure until I found the window that I need. It works same as I want.

Again Thanks

  • 2 years later...

hi bro you can give me it source code 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.