danielkrupinski / Osiris

Cross-platform game hack for Counter-Strike 2 with Panorama-based GUI.
MIT License
3.35k stars 961 forks source link

[Help] FreeLibrary after restoring hooks #636

Closed mathiasxx94 closed 1 year ago

mathiasxx94 commented 5 years ago

I'm a beginner so sorry if I'm doing something stupid or don't understand something.

The dll is still loaded after restoring the hooks, would be nice to be able to unhook and free library so you can reinject without restarting the game.

As far as I understand the dll is not creating a new thread so FreeLibrary (and not FreeLibraryAndExitThread) should be enough. I tried adding the following in the end of the restore function of the Hooks class:

Sleep(100); // Just to ensure I'm not inside a hooked function when library is freed.
FreeLibrary(GetModuleHandleA("Osiris.dll"));

The game crashes with a memory access violation when I press Unhook, but I don't know enough to proceed any further.

PS: I'm trying to inject a debug build btw, does anyone else have any problems with this?

VuBrian22 commented 5 years ago

If you inject a debug build, it will inject and the GUI will open, however when loading a map in game, you will end up crashing.

mathiasxx94 commented 5 years ago

If you're trying to unhook and inject again use mmap injection.

Thanks works great.

BTW. Do you know how the injected code starts running? There's no DllMain so I can't understand why the functions are hooked.

deprale commented 5 years ago

If you're trying to unhook and inject again use mmap injection.

Thanks works great.

BTW. Do you know how the injected code starts running? There's no DllMain so I can't understand why the functions are hooked.

Osiris.cpp is DllMain.cpp

mathiasxx94 commented 5 years ago

If you're trying to unhook and inject again use mmap injection.

Thanks works great. BTW. Do you know how the injected code starts running? There's no DllMain so I can't understand why the functions are hooked.

Osiris.cpp is DllMain.cpp

I'm probably stupid, but why is that? There's only creation of class objects in Osiris.cpp isn't it?

danielkrupinski commented 5 years ago

@mathiasxx94 Global objects are created by C-RunTime library in compiler-generated dllmain_crt_dispatch function.