uian2000 / delphi-detours-library

Automatically exported from code.google.com/p/delphi-detours-library
0 stars 1 forks source link

Feature request: support for multiple hooks of the one method #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is a possibly-quite-complex feature request, but would be very useful.

The problem is this: multiple bits of code, written by several unrelated 
people, want to hook the same method.  (For example, CnPack hooks a method in 
the IDE, and other IDE plugins also want to hook the same method in the IDE.)

Uninstalling a hook overwrites the other hooks, so this relies on everyone very 
carefully installing a hook once, and uninstalling once only when the program 
exits (eg their DLL is unloaded) and hoping that other affected hooks aren't 
needed after that point. If anyone uninstalls (removes) a hook during normal 
program execution, it removes all hooks installed by other people too.

So - is it possible to create a list of hooks, and have DDetour's create and 
remove methods add to a list, each one of which is called by DDetours?  That 
way many hooks can co-exist.

I would suggest:
 - for each item (hook) in the list, being able to add a "before calling the trampoline" event, which can cancel calling the original
 - then call the original if it was not canceled
 - then for each item (hook) in the list, add a "after calling the trampoline" event, which is given the trampoline's result if it was a function

I know this would be complicated to implement, and not used very often.  But it 
is a cool idea, and in the cases where it is used, it would be very useful.

Original issue reported on code.google.com by vintaged...@gmail.com on 16 Aug 2014 at 11:34

GoogleCodeExporter commented 9 years ago
Hi , 
I have to say that the idea is cool , but the mechanism to implement it is 
complex .

The first drawback for hooking the same function is : if the last installed 
hook does not call trampoline , the previous installed will not recieve the 
hook .

The second drawback is : when tourning to multi thread , if the first installed 
hook is released 
and the second one is accessing the hook , the app will crach .it's ok to stop 
the thread from working while removing the hook .. but it can lead to the 
performance to shot down.

The last drawback is that when somes plugins hook the same function using other 
library than DDL or some others techniques => this can cause conflict between 
the too engine .

Original comment by ismspi...@gmail.com on 17 Aug 2014 at 11:48

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r40.

Original comment by ismspi...@gmail.com on 22 Nov 2014 at 6:59