0

我发现了这个错误,因为我在 Windows 内置事件查看器中看到了它:

说明:进程因未处理的异常而终止。异常信息:System.MissingMethodException 堆栈:在 Injection.Main.DrawText_Hooked(...)

我有使用 easyhook 的 ac# 应用程序。我的 dll 关键代码:

        public void Run(RemoteHooking.IContext InContext, String InChannelName)
    {
        // Install system hook to detect calls to DrawTextExW that is made by the client and call the function DrawText_Hooked when ever this happens
        try
        {
            DrawTextExHook = LocalHook.Create(LocalHook.GetProcAddress("user32.dll", "DrawTextExW"), new DDrawTextEx(DrawText_Hooked), this);
            DrawTextExHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
        }....

我处理挂钩函数的代表是:

        int DrawText_Hooked(...)
    {
            Interface.Read(hdc, lpString, cchText, dwDTFormat);

        return DrawTextExW(hdc, lpString, cchText, ref lprc, dwDTFormat, ref dparams);
    }

当我关闭我的主应用程序时,一切正常,除非我使用Interface.Read(...): 在这种情况下,挂钩的应用程序崩溃。我读过它可能是因为Interface.Read(...)一旦我退出我的应用程序就不再存在了,但我不知道如何告诉我的 dll 停止这样做或简单地卸载,这样它就不会尝试这样做Interface.Read(...)并发现它没有t 实际上不再存在。我该怎么做?

4

1 回答 1

0

Two days looking for the answer and after posting it I discover it myself after 10':

What I did was to declare the hook static:

        static LocalHook DrawTextExHook;

So from my main code, on exit, I could call a static method that points it to null, therefore stopping calling my Interface.Read(...).

        public static void stopIt()
    {
        DrawTextExHook = null;
    }
于 2015-08-03T19:15:34.840 回答