winsocket 関数を呼び出す (古い) アプリケーションを入手しました。
struct hostent* FAR gethostbyname(
__in const char *name
);
現在、通常の名前呼び出しではなく、ws32_dll.#52としてインポートされます。
私の意図は、ホスト検索が発生したときにメッセージボックスを開くようなことをできるようにすることです (これはアプリの開始時にあるはずです)。
#52 を指すプラグマ コメントを使用して C++ dll を作成し、それをアプリ ディレクトリに配置しようとしました (「exe.local」および「exe.manifest」ファイルを含めてリダイレクトしようとしましたが、c:\ が読み込まれました)。代わりに windows\system32。
その後、プロセス自体を起動する ac# プロジェクトを作成し (したがって、プロセス オブジェクトから PID を取得)、それに easyhook dll を追加しました。
http://www.codeproject.com/KB/DLL/EasyHook64.aspxで例を確認しました。
呼び出しを次のように変更します。
FileMon.FileMonInterface Interface;
LocalHook CreateFileHook;
Stack<String> Queue = new Stack<String>();
public Main(
RemoteHooking.IContext InContext,
String InChannelName)
{
// connect to host...
Interface =
RemoteHooking.IpcConnectClient<FileMon.FileMonInterface>(InChannelName);
}
public void Run(
RemoteHooking.IContext InContext,
String InChannelName)
{
// install hook...
try
{
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("ws2_32.dll", "gethostbyname"),
new DCreateFile(GetHostByName_Hooked),
this);
CreateFileHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
catch (Exception ExtInfo)
{
Interface.ReportException(ExtInfo);
return;
}
Interface.IsInstalled(RemoteHooking.GetCurrentProcessId());
// wait for host process termination...
try
{
while (true)
{
Thread.Sleep(500);
// transmit newly monitored file accesses...
if (Queue.Count > 0)
{
String[] Package = null;
lock (Queue)
{
Package = Queue.ToArray();
Queue.Clear();
}
Interface.OnCreateFile(RemoteHooking.GetCurrentProcessId(), Package);
}
else
Interface.Ping();
}
}
catch
{
// NET Remoting will raise an exception if host is unreachable
}
}
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet = CharSet.Auto,
SetLastError = true)]
delegate IntPtr DGetHostByName(
String name);
// just use a P-Invoke implementation to get native API access
// from C# (this step is not necessary for C++.NET)
[DllImport("ws2_32.dll",
CharSet = CharSet.Auto,
SetLastError = true,
CallingConvention = CallingConvention.StdCall)]
static extern IntPtr gethostbyname(
String name);
// this is where we are intercepting all file accesses!
static IntPtr GetHostByName_Hooked(
String name)
{
try
{
Main This = (Main)HookRuntimeInfo.Callback;
MessageBox.Show("hi!");
}
catch
{
}
// call original API...
return GetHostByName(
name);
}
}
}
(ここに書くとタイプミスがあったかもしれませんが、プロジェクトは @ home で正常にコンパイルされました)。
問題は、このメソッドをフックするために何をする必要があるのか わからないということです<->アプリケーション自体。
つまり.. c# easyhook (アプリが「foo.exe」であると仮定) を使用してフッキングを行うには何が残っていますか? easyhook 用のカスタム dll を作成する必要がありますか?(その場合、内部にどのような内容を定義する必要がありますか?)
私はそれを少し見つけました... helloworld フックの場合は「複雑」です。
前もって感謝します ;)