Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placing hooks from .net dll cause hook connection to die #37

Open
Grivus opened this issue Jul 6, 2018 · 0 comments
Open

Placing hooks from .net dll cause hook connection to die #37

Grivus opened this issue Jul 6, 2018 · 0 comments

Comments

@Grivus
Copy link

Grivus commented Jul 6, 2018

Hi all!
I have met the problem while using Deviare2 and looking for someone who could explain the observed behavior.

Let's consider following scheme of a project:

  1. The .exe c# application(1), that creates NktSpyMgr object and place some hooks.
  2. The .dll c# .net library(2) running in the process of application(1), that receives NktSpyMgr object from it and also place some hooks through it.
  3. Some 3rd-party .exe application(3) we are hooking through NktSpyMgr

The problem I met is after several calls to the hooks handlers inside .net library(2) some of the hooks in this library(2) (sometimes all of them) will not trigger anymore, despite the corresponding winapi is called.

I have inspected the case a bit and found that the part of Deviare2 code that injected into the application(3) is working OK and trigger transport sending message to the client (CDvAgentMgr::OnUserHook code works well).
The client successfully received that message and trying to call the handler inside spymgr.cpp CNktSpyMgrEngineImpl::OnHookCalled

In the successfull case the call to handler will be inside lpHookImpl->Fire_OnFunctionCalled(cIHook, cIProc, cIHookCallInfo);

Next the hookevents.h Fire_OnFunctionCalled is triggered, and it tries to enumerate connections, but it seems that all connections are dead in the case of the error.

I have prepared the sample project based on COM sample to demonstrate the problem, it could be downloaded here
It works much similiar to the COM sample: it runs notepad.exe, the one should click File->Save first time, the hooks from dll will be triggered (a lot of times maybe), then close the dialog and click File->Save second time, and some of the hooks from dll will not be triggered (winapi calls to the hooked functions will go normally).

Am I do something completely wrong by design, or is this a bug? What could cause such a strange behavior?

UPD: Save dialog (not Open) should be used to reproduce the issue with sample.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant