Jump to content
Tuts 4 You
C++

DebugActiveProcess API in delphi

Recommended Posts

C++

Hello i've been reading up on some APIs and I came accross this api. I was trying to code a small debugger from it that attaches itself to a process but it seems a bit difficult to implement. Found some examples but they are not coded in delphi. Can anyone show a delphi example on how to use to attach to process? (DebugActiveProcess)

Share this post


Link to post
Share on other sites
C++

I was thinking to get handle of process by using findwindow api then OpenProcess with DebugActiveProcess api but it doesn't find handle. :mellow:

Share this post


Link to post
Share on other sites
Hero
3 hours ago, C++ said:

I was thinking to get handle of process by using findwindow api then OpenProcess with DebugActiveProcess api but it doesn't find handle. :mellow:

I'm not quite sure I followed. When you have a window handle, you use the following api to get the process identifier: GetWindowThreadProcessId. Naturally you provide this process identifier as an argument when you call DebugActiveProcess or OpenProcess.

Edited by Hero

Share this post


Link to post
Share on other sites
C++
2 hours ago, Hero said:

I'm not quite sure I followed. When you have a window handle, you use the following api to get the process identifier: GetWindowThreadProcessId. Naturally you provide this process identifier as an argument when you call DebugActiveProcess or OpenProcess.

I overlooked and corrected. Sorry was not fully clear of the information provided. Now here's the main problem why I was assuming I was not getting handle. After I got handle of process and to enter a debug loop. Process got stuck here  WaitForDebugEvent(De,  INFINITE);  and never passes there. Even if I manually close target. It still hangs at WaitForDebugEvent(De,  INFINITE); . If I created the process everything runs perfectly fine but trying to attach to a process that is already running with api DebugActiveProcess, everything hangs at WaitForDebugEvent . As I stated  even when closing the target. My program is still there hanging at WaitForDebugEvent(De, INFINITE);

 

I even tried openprocess with all 3 of these flags 

//PROCESS_ALL_ACCESS,
//DEBUG_PROCESS,
//DEBUG_ONLY_THIS_PROCESS,

Shows found process but still hangs at WaitForDebugEvent(De, INFINITE);

 

I also PM you with my code to see also what I did

I hope I made it clearer ;)

Share this post


Link to post
Share on other sites
C++

:D I figured it out. It was my mistake sorry.  If you check my code you will also see my mistake . Thanks again for help really appreciate it. 

Edited by C++
Slight correction

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×