【问题标题】:hooking another program's calls to winapi functions in vb.net在 vb.net 中挂钩另一个程序对 winapi 函数的调用
【发布时间】:2010-10-22 09:30:11
【问题描述】:

我一直在尝试在 vb.net 中构建游戏机器人。主要问题之一是访问游戏在屏幕上打印的文本,因此我一直在尝试将游戏调用与 windows api drawtext 和 textout 函数挂钩。很长一段时间以来,我一直在寻找如何在 vb.net 中设置挂钩的示例,但没有任何运气。我发现用老式的 vb、C++ 和 C# 翻译示例是不可能的。为了方便起见,我想使用免费提供的 deviare 和/或 easyhook 库。有人可以帮忙吗?

【问题讨论】:

  • 在这种情况下,它是一个扑克机器人。

标签: vb.net winapi hook


【解决方案1】:

我发现了基于 deviare 论坛中隐藏的 deviare hooking dll 的工作 vb.net 代码。

请记住在安装 deviare 后添加在 Visual Studio 添加引用页面的 com 选项卡下找到的所有 6 个 deviare 引用。

Public Class Form1

'To print to a textbox in the gui you will have to call textbox.invoke
Private _mgr As Deviare.SpyMgr
Private WithEvents _hook As Deviare.Hook
Private _proc As DeviareTools.IProcess

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    _mgr = New Deviare.SpyMgr()
    _hook = _mgr.CreateHook("user32.dll!ShowWindow")
    _hook.Attach(_mgr.Processes)
    _hook.AddProcessFilter(0, "notepad", 1)
    _hook.Hook()

Private Sub OnFunctionCalled(ByVal proc As DeviareTools.IProcess, ByVal callInfo As DeviareParams.ICallInfo, ByVal rCall As Deviare.IRemoteCall) Handles _hook.OnFunctionCalled

Debug.Print("Caught function call in " & proc.Name) 'view in imediate window

End Sub

end class

【讨论】:

    【解决方案2】:

    我正在将 Easyhook c# 代码转换为 vb.net。目前,我收到错误代码 5 消息,并且挂钩的应用程序正在被 Windows 关闭,例如以帮助保护您的计算机等。如果有人可以提供帮助,我将不胜感激。到目前为止我所拥有的是......

    Imports EasyHook
    Imports System
    Imports System.Diagnostics
    Imports System.Runtime.Remoting
    Imports System.Windows.Forms
    Imports System.Security
    Imports System.Security.Principal
    
    Namespace FileMon
    Friend Class Program
        ' Methods
        Public Shared Sub Main(ByVal args As String())
    
            Dim result As Integer = 0
            If ((args.Length <> 1) OrElse Not Integer.TryParse(args(0), result)) Then
                Console.WriteLine()
                Console.WriteLine("Usage: FileMon %PID%")
                Console.WriteLine()
            Else
                Try
                    Try
                        Console.WriteLine("Registering Application")
                        Console.WriteLine()
                        Config.Register("A FileMon like demo application.", "FileMon.exe", "FileMonInject.dll")
    
                    Catch exception1 As ApplicationException
                        Console.WriteLine("This is an administrative task! " & exception1.ToString)
                        Console.WriteLine()
                        Process.GetCurrentProcess.Kill()
                    End Try
    
                    Console.WriteLine("Creating IPC Server")
                    Console.WriteLine()
                    RemoteHooking.IpcCreateServer(Of FileMonInterface)(Program.ChannelName, WellKnownObjectMode.SingleCall)
                    RemoteHooking.Inject(result, "FileMonInject.dll", "FileMonInject.dll", New Object() {Program.ChannelName})
                    Console.WriteLine("Injected")
                    Console.WriteLine()
                    Console.ReadLine()
    
                Catch exception As Exception
                    Console.WriteLine("There was an error while connecting to target:" & exception.ToString)
                End Try
            End If
        End Sub
    
        ' Fields
        Private Shared ChannelName As String
    End Class
    End Namespace
    

    Imports System
    
    Namespace FileMon
    Public Class FileMonInterface
        Inherits MarshalByRefObject
        ' Methods
        Public Sub IsInstalled(ByVal InClientPID As Integer)
            Console.WriteLine("FileMon has been installed in target " & InClientPID)
        End Sub
    
        Public Sub OnCreateFile(ByVal InClientPID As Integer, ByVal InFileNames As String())
            Dim i As Integer
            For i = 0 To InFileNames.Length - 1
                Console.WriteLine(InFileNames(i))
            Next i
        End Sub
    
        Public Sub Ping()
        End Sub
    
        Public Sub ReportException(ByVal InInfo As Exception)
            Console.WriteLine(("The target process has reported an error:" & InInfo.ToString))
        End Sub
    
    End Class
    End Namespace
    

    【讨论】:

      【解决方案3】:

      easyhook 库

      尝试使用the EasyHook library

      【讨论】:

      • 我没有找到使用 easyhook 和 vb.net 的工作示例
      • @mazoula 将其用作任何其他 .NET 库
      猜你喜欢
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-18
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 2014-10-22
      相关资源
      最近更新 更多