72649

hooking another program's calls to winapi functions in vb.net

Question:

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?

Answer1:

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

Answer2:

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

Answer3:

<blockquote>

easyhook libraries

</blockquote>

Try to use <a href="http://easyhook.codeplex.com/" rel="nofollow">the EasyHook library</a>

Recommend

  • Secondary Monitor shows part of Primary Monitor
  • Change cursor position in visual basic
  • Display Metadata-thumbnail of Jpeg in picturebox
  • The path is not of a legal form
  • Updating an Access Database via a DataGridView Using OLEDB in VB.NET
  • Custom selection with C# DataGridView
  • Codeigniter Hooks advance
  • Python 2.7 on OS X: TypeError: 'frozenset' object is not callable on each command
  • Why does RichTextBox always contain extra characters before the document start?
  • Google datalab : how to import pickle
  • How to fallback to entirely different index page if user has javascript disable?
  • Manipulating matrices in C through R
  • Django - can't get highchart to display data
  • How to give custom name to Sqoop output files
  • Error while re-opening sound file in python
  • Google Maps getMap returns null
  • Cryptic error when trying to run POW
  • Is there a way to link a linux's thread TID and a pthread_t “thread ID”
  • Exception HRESULT: 0x800455BC in speech recognition in Windows phone 8
  • PWA with multiple pages
  • How to access recipient on sent messages page with mailboxer
  • 'doc_del_count' bigger than 'doc_count' on CouchDB
  • Click on button in another program - FindWindow, C#
  • How to load more than one div at a time
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • Azure webjobs output logs indexing taking very long
  • Best way to dynamically load an xml configuration file into a Flex4/Flash movie at runtime?
  • perl, mysql - fasting way to upload a csv file into mysql?
  • pillow imaging ImportError
  • Implementing “partial void” in VB
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • c# open webrowser in many tab
  • Loading .coffee files via a view in Rails
  • Create DicomImage from scratch using Dcmtk
  • Passing 1 of 3 values to a Sub
  • How to Cache Real-time Data?
  • Very simple C++ DLL that can be called from .net
  • How do you troubleshoot character encoding problems?
  • AT Commands to Send SMS not working in Windows 8.1
  • How to load view controller without button in storyboard?