C++ Posted February 7, 2018 Share Posted February 7, 2018 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) Link to comment
C++ Posted February 9, 2018 Author Share Posted February 9, 2018 I was thinking to get handle of process by using findwindow api then OpenProcess with DebugActiveProcess api but it doesn't find handle. Link to comment
Hero Posted February 9, 2018 Share Posted February 9, 2018 (edited) 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. 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 February 9, 2018 by Hero Link to comment
C++ Posted February 9, 2018 Author Share Posted February 9, 2018 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 Link to comment
C++ Posted February 9, 2018 Author Share Posted February 9, 2018 (edited) 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 February 9, 2018 by C++ Slight correction Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now