0

I have been trying to build a game bot in vb.net. One of the main problems is getting access to the text the game prints on the screen so I have been trying to hook the games calls to the windows api drawtext and textout functions. I have been hunting for examples of how to set up a hook in vb.net for a long time without any luck. I have found it impossible to translate examples in old school vb, C++, and C#. For convenience's sake I would like to use the freely available deviare and/or easyhook libraries. Can anyone help?

mazoula
  • 1,221
  • 2
  • 11
  • 20

3 Answers3

2

I found working vb.net code based on the deviare hooking dlls buried in the deviare forums.

please remember to add all 6 deviare references found under the com tab of the add references page of visual studio after installing 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
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
mazoula
  • 1,221
  • 2
  • 11
  • 20
1

I am in the process of converting the Easyhook c# code into vb.net. At the moment I am getting the error code 5 message and the hooked application is being closed by windows eg to help protect your computer etc. If anyone could help with this then I would be grateful. What I have so far is...

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

and

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
Stephen
  • 11
  • 2
0

easyhook libraries

Try to use the EasyHook library

Abyx
  • 12,345
  • 5
  • 44
  • 76