Archief - Tibia: FindWindow failure

Het archief is een bevroren moment uit een vorige versie van dit forum, met andere regels en andere bazen. Deze posts weerspiegelen op geen enkele manier onze huidige ideeën, waarden of wereldbeelden en zijn op sommige plaatsen gecensureerd wegens ontoelaatbaar. Veel zijn in een andere tijdsgeest gemaakt, al dan niet ironisch - zoals in het ironische subforum Off-Topic - en zouden op dit moment niet meer gepost (mogen) worden. Toch bieden we dit archief nog graag aan als informatiedatabank en naslagwerk. Lees er hier meer over of start een gesprek met anderen.

User_BELGIUM

Legacy Member
Een vriend van me zijt met een 'klein' probleempje. Z'n code veroorzaakt fouten. Mssn zien jullie een oplossing van het 'bugt' :p

Hello, I'm creating this program who should read a memory value from a game and put this in a textbox. But for some reason the FindWindow always returns false.
Here's the code. Pls help out.


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


Private Sub cmdGetInfo_Click()
' Declare some variables we need
Dim hwnd As Long ' Holds the handle returned by FindWindow
Dim pid As Long ' Used to hold the Process Id
Dim pHandle As Long ' Holds the Process Handle
Dim intExp As String


' First get a handle to the "game" window
hwnd = FindWindow(vbNullString, "Tibia")
If (hwnd = 0) Then
MsgBox "Window not found!"
Exit Sub
End If

' We can now get the pid
GetWindowThreadProcessId hwnd, pid

' Use the pid to get a Process Handle
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle = 0) Then
MsgBox "Couldn't get a process handle!"
Exit Sub
End If

' Now we can write to our address in memory
ReadProcessMemory pHandle, &H4903C, intExp, 5, 0&

txtOwnExp.Text = intExp

' Close the Process Handle
CloseHandle hProcess
End Sub

Silenger.BE

Legacy Member
Ik denk dat ik je probleem weet,

WIN := FindWindow(nil, PChar('Tibia '));

window caption heeft spaties :) kijk best eens met een window spy prog om de juiste aantal spaties te hebbe. Want ze zouden dit eens kunnen veranderen met nieuwe patch.

EDIT:

Dit is nog leuk, gewoon winsock hook om juiste socket te hebben.
Veranderen van costume en kleur in korte tijd :D

PHP:
        if (ColorFunB.Checked) then
        begin
                //Send
                if ((rGameSocket <> INVALID_SOCKET) and (rGameSocket <> SOCKET_ERROR)) then
                begin
                        Data := Chr($01) + Chr($00) + Chr($1E);
                        Winsock.send(rGameSocket, Data[1], Length(Data), 0);
                        Data := Chr($06) + Chr($00) + Chr($D3);

                        if (SkinFunB.Checked) then
                                Data := Data + Chr($80 + Random(4))
                        else
                                Data := Data + Chr($80 + SkinB.ItemIndex);

                        Data := Data + Chr(Random(255)) + Chr(Random(255)) + Chr(Random(255)) + Chr(Random(255));
                        Winsock.send(rGameSocket, Data[1], Length(Data), 0);
                end;
        end;

Myth

Legacy Member
Hallo.

Ik had intussen al gevonden dat de caption idd "Tibia " is.

Nu maakt hij echter wel fouten bij phandle.

Hier ff de code:

Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long



Private Sub cmdGetInfo_Click()
   ' Declare some variables we need
   Dim hwnd As Long        ' Holds the handle returned by FindWindow
   Dim pid As Long         ' Used to hold the Process Id
   Dim pHandle As Long     ' Holds the Process Handle
   Dim intExp As String
  
   
   ' First get a handle to the "game" window
   hwnd = FindWindow(vbNullString, "Tibia   ")
   If (hwnd = 0) Then
      MsgBox "Window not found!"
      Exit Sub
   End If
   
   ' We can now get the pid
   GetWindowThreadProcessId hwnd, pid
   
   ' Use the pid to get a Process Handle
   pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
   If (pHandle = 0) Then
      MsgBox "Couldn't get a process handle!"
      Exit Sub
   End If
    
   ' Now we can read from our address in memory
   ReadProcessMemory pHandle, &H4903C, intExp, 5, 0&
   
   'Put the value in a textbox
   txtOwnExp.Text = intExp
   
   ' Close the Process Handle
   CloseHandle hProcess
End Sub


Van die winsock snap ik echter niets :p
Ik vind veel tutorials op het net, maar die zijn allemaal om nieuwe sockets te starten. Ik vindt echter nergens hoe je packets kan editen van een bestaande winsock connectie.

Myth

Legacy Member
Door wat help van op een ander forum heb ik het programma foutloos gekregen.
De caption was "Tibia "
En dan moest ik nog wat variables declareren zoals PROCESS_ALL_ACCESS

Alhoewel ik nu geen fouten meer krijg, krijg ik wel een lege value uit het de readprocessmemory functie. De hex zou nochtans moeten kloppen. Ik heb het dubbelgechecked met mijn memory-search programma + ik heb ook dingne geprobeert als health en mana. Nooit krijg ik een waarde.

Enig idee wat fout is?

Silenger.BE

Legacy Member
Over API hooks, denk dat dit niet zal lukke met VB :unsure:

Ik weet niet wat VB doet als je een gewone var passed, want de buffer param van readprocessmemory moet een pointer zijn.

MSDN

EDIT:

Je passed als size 5, een Integer / DWORD / Cardinal zijn 4 bytes groot niet 5.
Het archief is een bevroren moment uit een vorige versie van dit forum, met andere regels en andere bazen. Deze posts weerspiegelen op geen enkele manier onze huidige ideeën, waarden of wereldbeelden en zijn op sommige plaatsen gecensureerd wegens ontoelaatbaar. Veel zijn in een andere tijdsgeest gemaakt, al dan niet ironisch - zoals in het ironische subforum Off-Topic - en zouden op dit moment niet meer gepost (mogen) worden. Toch bieden we dit archief nog graag aan als informatiedatabank en naslagwerk. Lees er hier meer over of start een gesprek met anderen.
Terug
Bovenaan