Jump to content

Memory Read Speed Tests


Knight
 Share

Recommended Posts

I do alot of memory reading and writing when I make bots and trainers for games with autoit. There is three posted functions that I have found written by Outshynd, w0uter, and Cameri. Each one different then the other.

Outshynd's was the first written one and the one I used alot at the beginning; but because of the need of the external dll, it became obsolete when w0uter released his _Mem Functions. Few months later, Cameri released his version which was similiar but not a copy of w0uter's and had more functionality because you could control whether it read byte, char, float, double, etc.. I have used Cameri's functions ever since he posted his, but I wanted to find out whose functions actually went the fastest because when making bots and trainers for games you could be accessing the memory thousands of times a minute to create a godly bot.

I used this test to find out which of the three UDFs would be the fastest.

You will need to use the beta version of AutoIt and have the external DLL made by Outshynd (At link below) to run the script. You must have mineweeper open on the beginner setting so it reads that there is 10 mines.

Sources:

Cameri: http://www.autoitscript.com/forum/index.ph...06entry116506

Outshynd: http://www.autoitscript.com/forum/index.ph...indpost&p=76981

w0uter: http://www.autoitscript.com/forum/index.ph...indpost&p=86817

;Begin Speed Test
$Address = 0x1005330;1byte
$Process = "winmine.exe"
$PID = ProcessExists($Process)

$i = 0
$w0uter = TimerInit()
$v_Open = _MemOpen(0x10, False, $PID)
Do
    If _MemRead($v_Open, $Address, 1) = 10 Then 
        $i += 1
    EndIf
Until $i = 10000
$v_Close = _MemClose($v_Open)
$w0uterOut = TimerDiff($w0uter)

$i = 0
$Cameri = TimerInit()
$v_Open = _MemOpen(0x10, False, $PID)
Do
    If _ReadProcessMemory($v_Open, $Address, 'byte', 1) = 10 Then 
        $i += 1
    EndIf
Until $i = 10000
$v_Close = _MemClose($v_Open)
$CameriOut = TimerDiff($Cameri)

$i = 0
$Outshynd = TimerInit()
Do
    If _ReadByte($Process, $Address) = 10 Then 
        $i += 1
    EndIf
Until $i = 10000
$OutshyndOut = TimerDiff($Outshynd)

MsgBox(0, "Results from Speed Test", _
            "w0uter: " & $w0uterOut / 1000 & " seconds " & @LF _
            & "Cameri: " & $CameriOut / 1000 & " seconds " & @LF _
            & "Outshynd: " & $OutshyndOut / 1000 & " seconds " _
)

;w0uter's _Mem Functions
Func _MemOpen($i_dwDesiredAccess, $i_bInheritHandle, $i_dwProcessId)
    
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $i_dwDesiredAccess, 'int', $i_bInheritHandle, 'int', $i_dwProcessId)
    If @error Then
        SetError(1)
        Return 0
    EndIf
    
    Return $ai_Handle[0]
EndFunc;==> _MemOpen()

Func _MemRead($i_hProcess, $i_lpBaseAddress, $i_nSize, $v_lpNumberOfBytesRead = '')
    
    Local $v_Struct = DllStructCreate ('byte[' & $i_nSize & ']')
    DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $i_hProcess, 'int', $i_lpBaseAddress, 'int', DllStructGetPtr ($v_Struct, 1), 'int', $i_nSize, 'int', $v_lpNumberOfBytesRead)
    
    Local $v_Return = DllStructGetData ($v_Struct, 1)
    
    DllStructDelete ($v_Struct)
    
    Return $v_Return
    
EndFunc;==> _MemRead()

Func _MemClose($i_hProcess)
    
    $av_CloseHandle = DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $i_hProcess)
    Return $av_CloseHandle[0]
    
EndFunc;==> _MemClose()
;End of w0uter's _Mem Functions

;Cameri's Memory Functions
;$s_Type can be any of the struct types specified in DllStructCreate in your help file.
Func _ReadProcessMemory($i_hProcess, $i_lpBaseAddress, $s_Type ,$i_nSize)
   Local $hDll = DllOpen("kernel32.dll")
   If @error Then
      SetError(1)
      Return 0
   EndIf
   Local $v_Struct = DllStructCreate ($s_Type&'[' & $i_nSize & ']')
   Local $v_lpNumberOfBytesRead = ''
   DllCall($hDll, 'int', 'ReadProcessMemory', 'int', $i_hProcess, 'int', $i_lpBaseAddress, 'int', DllStructGetPtr ($v_Struct, 1), 'int', $i_nSize, 'int', $v_lpNumberOfBytesRead)
   If @error Then
      SetError(1)
      Return 0
   EndIf
   Local $v_Return = DllStructGetData ($v_Struct, 1)
   DllStructDelete ($v_Struct)
   DllClose($hDll)
   Return $v_Return
EndFunc
;End Cameri's memory functions

;Outshynd's Memory Reading Functions
;------------------------------------
; READ MEMORY FUNCTIONS
;------------------------------------
;Read a byte from memory using ProcessID -- example
Func _ReadByte($EXEname, $Address)
    $ProcessID = ProcessExists($EXEname)
    If Not $ProcessID = 0 Then
        $ret = dllcall("AU3ReadWriteMemory.dll", "int", "ReadByte", "long", $ProcessID, "long", $Address)
        If @error Then
            Return -2
        Else
            Return $ret[0]
        EndIf
    Else
        Return -2
    EndIf
EndFunc

;Read two bytes from memory using ProcessID -- example
Func _ReadTwoBytes($EXEName, $Address)
    $ProcessID = ProcessExists($EXEName)
    If Not $ProcessID = 0 Then
        $ret = DllCall("AU3ReadWriteMemory.dll", "int", "ReadTwoBytes", "long", $ProcessID, "long", $Address)
        If @error Then
            Return -2
        Else
            Return $ret[0]
        EndIf
    Else
        Return -2
    EndIf
EndFunc

;Read four bytes from memory using ProcessID -- example
Func _ReadFourBytes($EXEName, $Address)
    $ProcessID = ProcessExists($EXEName)
    If Not $ProcessID = 0 Then
        $ret = DllCall("AU3ReadWriteMemory.dll", "long", "ReadDWord", "long", $ProcessID, "long", $Address)
        If @error Then
            Return -2
        Else
            Return $ret[0]
        EndIf
    Else
        Return -2
    EndIf
EndFunc
;End of Outshynd's memory functions

Conclusion:

w0uter: 4.56363643835388 seconds

Cameri: 5.69076347828986 seconds

Outshynd: 44.9404252669484 seconds

w0uter's run the fastest in 5 checks I have done, with Cameri's trailing pretty close. I have decided to keep using Cameri's functions because of the ability to read what type of memory rather then only bytes, even though it is slightly slower.

-JKnight

Edited by Knight
Link to comment
Share on other sites

modded my func to match cameri's more and added a dllopen call for speed.

(test was a TINY bit unfair since i had to add "$i_hProcess = $i_hProcess[1]" to cameri's code)

results:

mine: 2405.40017971556

cameri: 3254.91388112431

Func _MemOpen($i_dwProcessId, $i_dwDesiredAccess = 0x1F0FFF, $i_bInheritHandle = 0)
    
    Local $av_Return[2] = [DllOpen('kernel32.dll')]
    Local $ai_Handle = DllCall($av_Return[0], 'int', 'OpenProcess', 'int', $i_dwDesiredAccess, 'int', $i_bInheritHandle, 'int', $i_dwProcessId)
    If @error Then
        DllClose($av_Return[0])
        SetError(1)
        Return 0
    EndIf
    $av_Return[1] = $ai_Handle[0]
    Return $av_Return
EndFunc;==> _MemOpen()

Func _MemRead($i_hProcess, $i_lpBaseAddress, $s_Type = 'byte', $i_nSize = 1)
    
    Local $v_Struct = DllStructCreate ($s_Type & '[' & $i_nSize & ']')
    DllCall($i_hProcess[0], 'int', 'ReadProcessMemory', 'int', $i_hProcess[1], 'int', $i_lpBaseAddress, 'int', DllStructGetPtr ($v_Struct, 1), 'int', $i_nSize, 'int', '')
    Local $v_Return = DllStructGetData ($v_Struct, 1)
    DllStructDelete ($v_Struct)

    Return $v_Return
    
EndFunc;==> _MemRead()

Func _MemClose($i_hProcess)
    
    $av_CloseHandle = DllCall($i_hProcess[0], 'int', 'CloseHandle', 'int', $i_hProcess[1])
    DllClose($i_hProcess[0])
    Return $av_CloseHandle[0]
    
EndFunc;==> _MemClose()
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...