Deviare2 hook WriteFile API twice for only one write
<p>Deviare2 is a professional API Hook Library on MS Windows. It's easy use and powerful. But when I want to hook <code>WriteFile</code> using a C# dummy writer ,I found it hooked <code>WriteFile</code> twice. I try to use API Monitor to hook dummy writer, I found API Monitor just hook one for every write call. That's strange!</p>
<p>hook code:</p>
<pre><code>spyMgr = new NktSpyMgr();
        
NktProcess _process = GetProcess(&quot;DummyWriter.exe&quot;);

while (_process == null)
{
    Console.WriteLine(&quot;wait for process start...&quot;);
    System.Threading.Thread.Sleep(10);
    _process = GetProcess(&quot;DummyWriter.exe&quot;);
}
        
hookDllGetClassObj = spyMgr.CreateHook(&quot;kernel32.dll!WriteFile&quot;, (int)(eNktHookFlags.flgOnlyPreCall));

hookDllGetClassObj.Attach(_process, true);

hookDllGetClassObj.Hook(true);
hookDllGetClassObj.OnFunctionCalled += OnDllGetClassObjectCalled;
</code></pre>
<p>dummy write:</p>
<pre><code>string key = &quot;&quot;;

Task.Factory.StartNew(() =&gt; {
    int index=1;
    while (key == &quot;&quot;)
    {
        using (StreamWriter sw = new StreamWriter(&quot;d:\\dummy.txt&quot;,true))
        {
            string str = string.Format(&quot;{0}:oh gotcha!&quot;, index);
            Console.WriteLine(str);
            sw.WriteLine(str);
            index++;
        }

        Thread.Sleep(500);
    }
});

key = Console.ReadLine();
</code></pre>