Sign in to follow this  
nuclear123

Console Attachment problem

Recommended Posts

what im doing is injecting a dll into my program. This dll is then allocating a console and outputting debug information. The problem is when im done with my console and i close it the program also closes with it. it's almost like the console becomes one with the program. Any help on how to resolve this issue? i am using the following code to make and write to my console



[code]
AllocConsole();
freopen("CONOUT{:content:}quot;, "wb", stdout);

printf(" DEBUG CONSOLE YAY ");


fclose(stdout);
FreeConsole();[/code]

Share this post


Link to post
Share on other sites
You can try using [url="http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx"]CreateProcess[/url]() followed by [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681952(v=VS.85).aspx"]AttachConsole[/url] instead. That should create them in separate processes.

Share this post


Link to post
Share on other sites
if i use createprocess() then it will have it's own address space. I still want access to the program im wanting to debug's addresspace as well. Will this still work? Also createprocess won't work with a dll correct? the debug console code would need to be in a .exe?

Share this post


Link to post
Share on other sites
You have two options with consoles. One is to create one yourself in the process. When the process dies, so will the console. A second option is to attach to the parent console, if any. If you then run the program from the command line, it will attach to that console, which will persist when the program ends.

I believe Seraph was advocating the latter, except with a stub executable that would call CreateProcess() on the executable you want to inject. I do not believe Seraph was not suggesting you invoke CreateProcess() inside the injected process, so I won't try to address your questions (I don't know the answers anyway).

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

Sign in to follow this