Archive for the 'Read Process Memory' Tag

VB Net - Basic MSN Logging Program

Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form

Public myHandle As Integer
Dim playing As Boolean
Dim timeplaying As Integer
Dim timeinit As Integer

Function WinMinePID() As Integer
Dim Processes() As System.Diagnostics.Process
”Sets the function to -1 for use in the Gamestate function
WinMinePID = -1
”Gets the process using system diagnostics
Processes = System.Diagnostics.Process.GetProcessesByName(”winmine”)
”If the process exists then it sets the function to the process ID, else the function
‘’still = -1
If Processes.Length > 0 Then WinMinePID = Processes(0).Id
End Function
Sub StatExist()
Dim fileExists As Boolean
Dim stats As String = Application.StartupPath & “/stats.txt”
fileExists = My.Computer.FileSystem.FileExists(stats)
If fileExists = True Then
Else
My.Computer.FileSystem.WriteAllText(stats, (0) & ControlChars.NewLine & 0, False)
End If
Dim times As String = Application.StartupPath & “/times.txt”
fileExists = My.Computer.FileSystem.FileExists(times)
If fileExists = True Then
Else
My.Computer.FileSystem.WriteAllText(times, 0, False)
End If
End Sub
Function GameState() As Integer
”Gamestate Function
”<—0 = Normal—>
”<—1 = Mouse Down—>
”<—2 = Lost—>
”<—3 = Won—>
”<—4 = Face Down—>

”Declerations
Dim buffer As String : Dim addr, readlen, pid As Integer
On Error Resume Next
”Set pid to the process ID of minesweeper using the WinMinePID function
pid = WinMinePID()
stat.Text = “Process Not Found”
”Checks that the process exists
If pid = -1 Then Exit Function
‘Open the proccess with permissions (1F0FFF)
myHandle = OpenProcess(&H1F0FFF, False, pid)
buffer = Space(1)
addr = &H1005160
”Reads the memory at the address above
Call ReadProcessMemory(myHandle, addr, buffer, 1, readlen)
stat.Text = “Logging…”
”Sets the function to equal the value stored at the memory location
GameState = Asc(buffer)
End Function
Sub InitialTime()
Dim times As String = Application.StartupPath & “/times.txt”
timeinit = My.Computer.FileSystem.ReadAllText(times)
End Sub
Sub WriteLog()
StatExist()
Dim gs As Integer = (GameState())
If gs = 2 Then
TimeSave()
If playing = True Then playing = False : LostSave()
ElseIf gs = 3 Then
TimeSave()
If playing = True Then playing = False : WonSave()
Dim readlen As Integer
Dim buffer As String = Space(1)
Dim addr As Integer = &H100579C
”Reads the memory at the address above
Call ReadProcessMemory(myHandle, addr, buffer, 1, readlen)
MsgBox(Asc(buffer))
Else
playing = True
End If
End Sub
Function LostLoad() As Double
StatExist()
Dim stats As String = My.Computer.FileSystem.CurrentDirectory & “/stats.txt”
Dim line As String
Dim lineno As Integer = 0
Dim reader As New IO.StringReader(My.Computer.FileSystem.ReadAllText(stats))
While True
lineno += 1
line = reader.ReadLine()
If lineno = 2 Then LostLoad = line : Exit While
End While
End Function
Sub LostSave()
StatExist()
Dim stats As String = My.Computer.FileSystem.CurrentDirectory & “/stats.txt”
Dim Won As Integer = winsl.Text
Dim Lost As Integer = lossesl.Text
Lost += 1
My.Computer.FileSystem.WriteAllText(stats, (Won) & ControlChars.NewLine & Lost, False)
lossesl.Text = Lost

Dim times As String = My.Computer.FileSystem.CurrentDirectory & “/times.txt”

LostLoad()
End Sub
Function WonLoad() As Double
StatExist()
Dim stats As String = My.Computer.FileSystem.CurrentDirectory & “/stats.txt”
Dim line As String
Dim lineno As Integer = 0
Dim reader As New IO.StringReader(My.Computer.FileSystem.ReadAllText(stats))
While True
lineno += 1
line = reader.ReadLine()
If lineno = 1 Then WonLoad = line : Exit While
End While
End Function
Sub WonSave()
StatExist()
Dim stats As String = My.Computer.FileSystem.CurrentDirectory & “/stats.txt”
Dim Won As Integer = winsl.Text
Dim Lost As Integer = lossesl.Text
Won += 1
My.Computer.FileSystem.WriteAllText(stats, (Won) & ControlChars.NewLine & Lost, False)
winsl.Text = Won
WonLoad()
End Sub

Sub TimeSave()
Dim readlen As Integer
Dim buffer As String = Space(1)
Dim addr As Integer = &H100579C
Call ReadProcessMemory(myHandle, addr, buffer, 1, readlen)
Dim times As String = Application.StartupPath & “/times.txt”
timeplaying = buffer + timeinit
MsgBox(timeplaying)
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WriteLog()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
StatExist()
winsl.Text = WonLoad()
lossesl.Text = LostLoad()
InitialTime()
End Sub

Private Sub TextChangde(ByVal sender As Object, ByVal e As System.EventArgs) Handles winsl.TextChanged, lossesl.TextChanged
If WonLoad() = 0 And LostLoad() = 0 Then
wrl.Text = 0 & “%”
Else
Dim oneperc As Double
oneperc = (WonLoad() + LostLoad()) / 100
Dim percent As Double
percent = WonLoad() / oneperc
wrl.Text = percent & “%”
End If

End Sub
End Class

Needs a lot of redoing, it works but its very inefficiently coded