UninjectLibrary

c++ / delphi package - dll injection and api hooking
Post Reply
Azmodeus
Posts: 60
Joined: Mon May 03, 2004 7:41 am

UninjectLibrary

Post by Azmodeus »

When callin' UninjectLibrary (ALL_SESSIONS, "MyDLLName")

It is always bombing out with an unhandeled exception.

What could be causing this?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Who is bombing out? Your own application? Or all processes? Which OS are we talking about? Which language do you use (C++ / Delphi)?
Azmodeus
Posts: 60
Joined: Mon May 03, 2004 7:41 am

Post by Azmodeus »

Sorry about that.

C++.

The injected dll causes an unhandled exception when the uninject library functino tries to remove it from all processes. End result, not all processes unload the injected library and the memory is stuck/leaked until a reboot.

Besides that, I tried putting a try catch around the uninjectlibrary function and it does not get caught. When debugging it, it tries to access a null pointer it looks like.

The only thing I can think of is that I have allocated a COM object someplace and have not freed it up before trying to uninject the library.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I think you're not really aware about what happens in which process. Look, your executable does the main work of injecting & uninjecting the dll. But the dll does also a lot of work. Also: The dll is not only loaded into your own process, but a copy of it is loaded into all running processes. Now when you say the injected dll causes an exception when it gets removed, all running processes should crash when you uninject the dll. But what you describe doesn't sound like that.

First of all I have to know which process is crashing. Is it your own or is it another process? Or do all processes crash? If it's your own, then most probably your dll is *not* the crash cause, otherwise all processes would crash, not just your exe. Do you see what I mean?

What happens if your exe injects/uninjects one of the precompiled demo hook dlls which ship with madCodeHook? E.g. try using HookProcessCreation. Does that work without crashes?

P.S: Please compile your madCodeHook projects in release mode. Debug mode sometimes makes problems.
Azmodeus
Posts: 60
Joined: Mon May 03, 2004 7:41 am

Post by Azmodeus »

Solved.

This was caused by the dll unloading from the program space before I was finished using it.


Note to self: Do not call Uninject library unless you really mean it.
Post Reply