首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在vb.net中将另一个程序的调用挂接到winapi函数

在vb.net中将另一个程序的调用挂接到winapi函数
EN

Stack Overflow用户
提问于 2010-10-22 17:30:11
回答 3查看 4.1K关注 0票数 0

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

EN

回答 3

Stack Overflow用户

发布于 2010-10-24 16:59:05

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

请记住在安装了deviare之后,添加在visual studio的添加引用页面的com选项卡下找到的所有6个deviare引用。

代码语言:javascript
运行
复制
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
EN

Stack Overflow用户

发布于 2012-08-05 22:26:28

我正在将Easyhook c#代码转换成vb.net。目前,我得到了错误代码5的消息,挂钩的应用程序正在被windows关闭,例如,帮助保护您的计算机等。如果有人能在这方面提供帮助,我将不胜感激。到目前为止我得到的是..。

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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
票数 1
EN

Stack Overflow用户

发布于 2010-10-23 03:29:52

easyhook库

尝试使用the EasyHook library

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3995522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档