easyhookでexttextoutwをフックしたい
EasyHook-Tutorialsのサンプルを変更して、exttextoutwをフックするようにプログラムを書きました。しかし、notepad.exeで実行してもhookのメッセージが表示されません。
なにが悪いのでしょうか?
変更したコードは下記のとおりです。
FileMonitorHook以外は変更しておりません。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace FileMonitorHook
{
public class InjectionEntryPoint: EasyHook.IEntryPoint
{
ServerInterface _server = null;
Queue<string> _messageQueue = new Queue<string>();
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public long left;
public long top;
public long right;
public long bottom;
}
public InjectionEntryPoint(
EasyHook.RemoteHooking.IContext context,
string channelName)
{
_server = EasyHook.RemoteHooking.IpcConnectClient<ServerInterface>(channelName);
_server.Ping();
}
public void Run(
EasyHook.RemoteHooking.IContext context,
string channelName)
{
_server.IsInstalled(EasyHook.RemoteHooking.GetCurrentProcessId());
var ExtTextOutHook = EasyHook.LocalHook.Create(
EasyHook.LocalHook.GetProcAddress("Gdi32.dll", "ExtTextOutW"),
new ExtTextOut_Delegate(ExtTextOut_Hook),
this);
_server.ReportMessage("ExtTextOut hook installed");
EasyHook.RemoteHooking.WakeUpProcess();
try
{
// Loop until FileMonitor closes (i.e. IPC fails)
while (true)
{
System.Threading.Thread.Sleep(500);
string[] queued = null;
lock (_messageQueue)
{
queued = _messageQueue.ToArray();
_messageQueue.Clear();
}
if (queued != null && queued.Length > 0)
{
_server.ReportMessages(queued);
}
else
{
_server.Ping();
}
}
}
catch
{
}
ExtTextOutHook.Dispose();
EasyHook.LocalHook.Release();
}
#region ExtTextOutW Hook
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet = CharSet.Unicode,
SetLastError = true)]
delegate bool ExtTextOut_Delegate(
IntPtr hdc,
int x,
int y,
uint fuOptions,
[In] ref RECT lprc,
string lpString,
uint cbCount,
[In] IntPtr lpDx);
[DllImport("Gdi32.dll",
CharSet = CharSet.Unicode,
SetLastError = true, CallingConvention = CallingConvention.StdCall)]
static extern bool ExtTextOutW(
IntPtr hdc,
int x,
int y,
uint fuOptions,
[In] ref RECT lprc,
string lpString,
uint cbCount,
[In] IntPtr lpDx);
bool ExtTextOut_Hook(
IntPtr hdc,
int x,
int y,
uint fuOptions,
[In] ref RECT lprc,
string lpString,
uint cbCount,
[In] IntPtr lpDx)
{
try
{
lock (this._messageQueue)
{
this._messageQueue.Enqueue("ExtTextOut_Hook called");
}
}
catch
{
}
return ExtTextOutW(
hdc,
x,
y,
fuOptions,
ref lprc,
lpString,
cbCount,
lpDx);
}
#endregion
}
}