Frage

Ich habe eine (alte) Anwendung, die die Winsocket -Funktion aufruft:

struct hostent* FAR gethostbyname(
  __in  const char *name
);

Es importiert es derzeit als WS32_DLL.#52 Stattdessen der normale Name ruft.

Meine Absicht ist es, bei einer Hostsuche so etwas wie das Öffnen einer MessageBox zu erledigen (was bei der App -Start sein sollte).

Ich habe versucht, eine C ++ - DLL mit den Pragma -Kommentaren zu erstellen, die auf Nr. 52 hinweisen und sie in die App -Dateien aufnehmen (einschließlich einer "exe.local" und "exe.manifest" -Dateien, um es umzuleiten, aber es lud das C: Windows System32 stattdessen.

Danach habe ich das AC# -Projekt erstellt, das den Prozess selbst startet (damit die PID aus dem Prozessobjekt abgerufen wird) und das Easyhook -DLL hinzugefügt.

Ich habe das Beispiel unter: http://www.codeproject.com/kb/dll/easyhook64.aspx

Ändern der Anrufe an:

    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);
    }
}

}

(Möglicherweise haben Tippfehler es hier geschrieben, aber das Projekt kompiliert erfolgreich @ home).

Die Sache ist, dass ich nicht weiß, was ich brauche, um diese Methoden zu tun <-> die Anwendung selbst.

Ich meine ... was links ist, nur das Haken mit C# Easyhook zu machen (vorausgesetzt, die App ist "foo.exe")? Muss ich eine benutzerdefinierte DLL für EasyHook erstellen? (In diesem Fall muss ich in diesem Fall im Inhalt definieren?)

Ich fand es ein bisschen ... "Komplex" für einen Helloworld -Haken, hehe.

Danke im Voraus ;)

War es hilfreich?

Lösung

Am Ende Taugh mir das Buch "Grey Hack Python", wie man das alles mit weniger Zeilen macht, und genau das gleiche, was ich wollte.

Noch kein Exe, aber ... das war's.

Verwenden von PYDBG + Hooks.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top