View Full Version : VB.NET and Random PID
Talmar
24th June 2005, 04:46
I am using the VB.NET Trainer Template to make my hack which relys on:
pstrWindowName =
to attach itself to BF2; since BF2's Process ID changes every time I launch the game, the hack no longer works. So, for my two questions:
1. Is it possible to still use 'pstrWindowName' but instruct it so that the name can be 'BF2 (v1.0.2442.0, *), where the '*' can be anything?
2. If I cannot do question 1, what code will I need to change to in order for my hack to attach itself to BF2?
Bear in mind, I am still very green when it comes to VB.NET :lam:
Thanks in advance!
Spontaneous
24th June 2005, 05:22
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Dim hWnd As Long, pid As Long, phandle As Long
hWnd = FindWindow(vbNullString, "'BF2 (v1.0.2442.0")
GetWindowThreadProcessId hWnd, pid
Most hacks will use the FindWindow API to get the pid. You want the window title to be the window class name which is the 2nd value, where the first value is vbNullString not *
Talmar
24th June 2005, 05:33
So, how would I apply that to the exisitng 'modTTIntializeProc.vb' Module:
Module modTTInitializeProc
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As IntPtr) As Boolean
Private PROCESS_ALL_ACCESS As Integer = &H1F0FFF
Public pstrWindowName As String
'--------------------------------------------
'Function InitProc
'Args: strWindowName (String Data Type -
'the window name of the game whose memory
'you will be editing with this trainer.
'Returns: The process handle
'Description: This function uses FindWindow
'and a few other api functions to obtain the
'handle of the program so we can edit
'its memory.
'--------------------------------------------
Public Function InitProc(ByVal strWindowName As String) As IntPtr
'Obtain the window handle
Dim hWnd As IntPtr = FindWindow(vbNullString, strWindowName)
'If there is a handle (game found)
Dim pID As Integer
'Obtain the process id
GetWindowThreadProcessId(hWnd, pID)
'Obtain the handle of the process
Dim intTemp As IntPtr
intTemp = OpenProcess(PROCESS_ALL_ACCESS, False, pID)
InitProc = intTemp
End Function
End Module
Kosire
24th June 2005, 06:16
Just call it like:
handle = InitProc("BF2 (v1.0.2442.0)")
Talmar
24th June 2005, 06:21
Just call it like:
handle = InitProc("BF2 (v1.0.2442.0)")
Could you please be more specifc; where would I add that line?
Also, I don't know if you are aware of this, but to be more specific, the PID is added to the WindowName:
pstrWindowName = "BF2 (v1.0.2442.0, pid: 3752)"
where this was not the case with BF1942:
pstrWindowName = "BF1942 (Ver: Tue, 19 Oct 2004 14:58:45)"
and that is where I am stuck.
Kosire
24th June 2005, 06:34
I was just going off Spont's post saying the window class name is BF2 (v1.0.2442.0).
You could just test by going
Dim handle as long
handle = InitProc("BF2 (v1.0.2442.0)")
someLabel.text = handle
just to see if that approach does in fact work.
Talmar
24th June 2005, 06:50
Sorry, still lost.... :hlp1:
I am using MaxPower's VB.NET Trainer Template if that helps.
Spontaneous
24th June 2005, 13:30
I never liked maxpowers vb.net trainer template so :P Anyways, the (window title, pid) you have is wrong. How the API works is (window title, window class). If what you get is right(I havent checked myself) the PID would be BEFORE the comma along with the window title. In a way its too bad max powers webpage is down as I know he did some coding to show you how to do a * so that you didnt have to fix the window title every patch of the game.
Kosire
24th June 2005, 13:38
http://www.mpcforum.com/showpost.php?p=688981&postcount=10
In VB:
handle = getHprocExe("BF2.exe")
Call writeprocessmemory(handle, ...)
Spontaneous
24th June 2005, 13:51
Yea you could use Hproc, personally I dont like going that way.
Sparten
24th June 2005, 13:56
Yea you could use Hproc, personally I dont like going that way.
what is the differance, the goal is to get a handle to the process, and with the windowtitle changing on every load it sure is a lot easyer to get the handle from the exe name.
Spontaneous
24th June 2005, 14:02
Well you know me and saving CPU cycles when I can. Thats why my code for Omega is so much like a puzzle. Havent you ever noticed in all the different source codes I gave you, I never once used hproc? Using hproc has to do 1 to 2 more steps to get the PID then searching window title/class. Granted its not really enough cpu cycles to make a difference but thats just me. Its also quite easy to do a * for window title so how really using hproc is not all that much easier.
Talmar
25th June 2005, 02:47
Well, I am still at a loss here; could you please explain what code I need to modify here to support wildcards (*):
Module modTTInitializeProc
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As IntPtr) As Boolean
Private PROCESS_ALL_ACCESS As Integer = &H1F0FFF
Public pstrWindowName As String
'--------------------------------------------
'Function InitProc
'Args: strWindowName (String Data Type -
'the window name of the game whose memory
'you will be editing with this trainer.
'Returns: The process handle
'Description: This function uses FindWindow
'and a few other api functions to obtain the
'handle of the program so we can edit
'its memory.
'--------------------------------------------
Public Function InitProc(ByVal strWindowName As String) As IntPtr
'Obtain the window handle
Dim hWnd As IntPtr = FindWindow(vbNullString, strWindowName)
'If there is a handle (game found)
Dim pID As Integer
'Obtain the process id
GetWindowThreadProcessId(hWnd, pID)
'Obtain the handle of the process
Dim intTemp As IntPtr
intTemp = OpenProcess(PROCESS_ALL_ACCESS, False, pID)
InitProc = intTemp
End Function
End Module
Kosire
25th June 2005, 02:50
Just use the hetHProc Module I posted above, its so much easier.
Call like i said above:
handle = getHprocExe("BF2.exe")
Call writeprocessmemory(handle, ...)
Don't waste your time for the sake of 30ms faster code.
Sparten
25th June 2005, 02:59
and handle = getHprocExe("BF2.exe") only needs to be called once on every game load, not on every call to WriteProcessMemory(), else you could get a memory leak...
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.