HookAPI crashes without calling InitializeMadCHook

c++ / delphi package - dll injection and api hooking

HookAPI crashes without calling InitializeMadCHook

Postby _NN_ » Wed Jul 11, 2018 1:30 pm

Is it possible to just fail and return FALSE instead of producing Access Violation when HookAPI is called without InitializeMadCHook ?
_NN_
 
Posts: 53
Joined: Mon Jan 21, 2013 4:00 pm

Re: HookAPI crashes without calling InitializeMadCHook

Postby madshi » Wed Jul 11, 2018 2:10 pm

It's difficult, especially when using the Delphi LIB, because if you don't call InitializeMadCHook(), the whole Delphi RTL is not even initialized at all.

It would not be difficult to make HookAPI() not crash, it's just one API, but I'd have to add the same check to each and every exported function, and in Delphi that's a lot more than madCHook.h contains. So a lot of work and added code, just to protect against incorrect usage? Not sure if I like that...
madshi
Site Admin
 
Posts: 9830
Joined: Sun Mar 21, 2004 5:25 pm

Re: HookAPI crashes without calling InitializeMadCHook

Postby _NN_ » Wed Jul 11, 2018 2:24 pm

You can add it inline in the header if you don't want to touch Delphi source.
I understand it is incorrect usage, but I spent several minutes trying to understand why I have crash in some irrelevant address.
_NN_
 
Posts: 53
Joined: Mon Jan 21, 2013 4:00 pm

Re: HookAPI crashes without calling InitializeMadCHook

Postby madshi » Wed Jul 11, 2018 4:02 pm

Well, FWIW, I always recommend to use one of the demo projects as the starting point for your own projects. That way you already have the basic framework set up correctly, including compiler and linker settings etc.
madshi
Site Admin
 
Posts: 9830
Joined: Sun Mar 21, 2004 5:25 pm

Re: HookAPI crashes without calling InitializeMadCHook

Postby _NN_ » Thu Jul 12, 2018 7:09 am

This discussion goes to direction who is responsible to check the caller or the callee.
My opinion that callee will do as much checks as possible, while you say it is not really necessary.

I already made a class which does this automatically, so I won't forget :)
Btw, perhaps you need some C++ API on top of your header which will take care of all this initializations.
Is it something that you would accept as patch ?
_NN_
 
Posts: 53
Joined: Mon Jan 21, 2013 4:00 pm

Re: HookAPI crashes without calling InitializeMadCHook

Postby madshi » Wed Jul 18, 2018 8:05 am

I'm not sure if I'd like a C++ API. I like a simple and short API. And if I distribute your C++ API, I also become responsible for maintaining it and fixing bugs in it. And if I add or change APIs, I also have to do all that in the C++ API files in addition to the current C header.

Anyway, how complicated is your C++ API? Does it fit into a single e.g. *.h file?
madshi
Site Admin
 
Posts: 9830
Joined: Sun Mar 21, 2004 5:25 pm

Re: HookAPI crashes without calling InitializeMadCHook

Postby _NN_ » Wed Jul 18, 2018 11:11 am

Currently I removed all wrappers since the code is very simple.
Maybe in the future I'll do wrapping which will initialize madCodeHook automatically on first call if wasn't initialized before or smth like that.
_NN_
 
Posts: 53
Joined: Mon Jan 21, 2013 4:00 pm


Return to madCodeHook

Who is online

Users browsing this forum: No registered users and 9 guests