Sign in to follow this  
Followers 0
intelPiggy

Memory Function

3 posts in this topic

I'm trying to read a memory of 2bytes instead of 4 using

Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')

If Not IsArray($ah_Handle) Then

SetError(1)

Return 0

EndIf

Local $v_Buffer = DllStructCreate($sv_Type)

If @Error Then

SetError(@Error + 1)

Return 0

EndIf

DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')

If Not @Error Then

Local $v_Value = DllStructGetData($v_Buffer, 1)

Return $v_Value

Else

SetError(6)

Return 0

EndIf

EndFunc

what do i have to change so that u can read 2bytes instead of 4bytes?

Share this post


Link to post
Share on other sites



or anyone know how to read just 2 bytes of memory?

awaiting for help here :)

Share this post


Link to post
Share on other sites

;--Memory Functions--
Func _OpenProcess($hWnd, $use_pid=0)
    If $use_pid = 0 Then
        Local $pid = DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $hWnd, "int_ptr", 0)
        If IsArray($pid) Then
            $pid = $pid[2]
        Else
            SetError(-1)
            Return
        EndIf
    Else
        Local $pid = $hWnd
    EndIf
    
    Local $pHandle = DllCall("kernel32.dll", "int", "OpenProcess", "int", 0x1F0FFF, "int", 0, "int", $pid)
    If IsArray($pHandle) And $pHandle[0] > 0 Then
        $pHandle = $pHandle[0]
    Else
        SetError(-2)
        Return
    EndIf
    
    Return $pHandle
EndFunc

Func _CloseHandle($pHandle)
    DllCall("kernel32.dll", "int", "CloseHandle", "int", $pHandle)
EndFunc

Func _ReadMemory($pHandle, $Address, $size)
    Local $ret = DllCall("kernel32.dll", "int", "ReadProcessMemory", "int", $pHandle, "int", $Address, "int_ptr", 0, "int", $size, "int", 0)
    If IsArray($ret) Then
        If $ret[0] = 1 Then
            $ret = $ret[3]
        Else
            SetError(-2)
            Return
        EndIf
    Else
        SetError(-1)
        Return
    EndIf

    
    Return $ret
EndFunc

Func _ReadFloat($pHandle, $Address)
    Local $floatReturn = 0
    Local $float = DllStructCreate("float")
    Local $ret = DllCall("kernel32.dll", "int", "ReadProcessMemory", "int", $pHandle, "int", $Address, "ptr", DllStructGetPtr($float), "int", 4, "int", 0)
    If IsArray($ret) Then
        If $ret[0] = 1 Then
            $floatReturn = DllStructGetData($float, 1)
        Else
            SetError(-1)
        EndIf
    Else
        SetError(-2)
    EndIf
    
    Return $floatReturn
EndFunc

Func _ReadString($pHandle, $Address, $length)
    Local $ret, $tmpStr = ""
    For $i = 0 To $length - 1
        $ret = DllCall("kernel32.dll", "int", "ReadProcessMemory", "int", $pHandle, "int", $Address + $i, "int_ptr", 0, "int", 1, "int", 0)
        If IsArray($ret) Then
            If $ret[0] = 1 Then
                If $ret[3] > 0 Then
                    $tmpStr = $tmpStr & Chr($ret[3])
                Else
                    ExitLoop
                EndIf
            Else
                SetError(-2)
                Return
            EndIf
        Else
            SetError(-1)
            Return
        EndIf
    Next
    
    Return $tmpStr
EndFunc

Func _WriteMemory($pHandle, $Address, $value, $size)
    Local $ret = DllCall("kernel32.dll", "int", "WriteProcessMemory", "int", $pHandle, "int", $Address, "int_ptr", $value, "int", $size, "int", 0)
    If IsArray($ret) Then
        If $ret[0] = 1 Then
            Return True
        Else
            SetError(-2)
            Return False
        EndIf
    Else
        SetError(-1)
        Return False
    EndIf
    
    Return True
EndFunc

Func _WriteFloat($pHandle, $Address, $value)
    Local $float = DllStructCreate("float")
    DllStructSetData($float, 1, $value)
    Local $ret = DllCall("kernel32.dll", "int", "WriteProcessMemory", "int", $pHandle, "int", $Address, "ptr", DllStructGetPtr($float), "int", 4, "int", 0)
    If IsArray($ret) Then
        If $ret[0] = 1 Then
            Return True
        Else
            SetError(-2)
            Return False
        EndIf
    Else
        SetError(-1)
        Return False
    EndIf
EndFunc

Func _WriteString($pHandle, $Address, $string)
    Local $ret
    Local $length = StringLen($string)
    For $i = 0 To $length       
        $ret = DllCall("kernel32.dll", "int", "WriteProcessMemory", "int", $pHandle, "int", $Address + $i, "int_ptr", Asc(StringMid($string, $i + 1, 1)), "int", 1, "int", 0)
        If IsArray($ret) Then
            If $ret[0] = 0 Then
                SetError(-2)
                Return False
            EndIf
        Else
            SetError(-1)
            Return False
        EndIf
    Next
    
    Return True
EndFuncoÝ÷ غ(«ky§fzj+É«­¢+ÙÕ¹}I5µ½Éä ÀÌØíÁ!¹±°ÀÌØíÉÍÌ°ÀÌØíÍ¥é¤(%1½°ÀÌØíÉÐô±±
±° ÅÕ½Ðí­É¹°Ìȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½ÐíIAɽÍÍ5µ½ÉäÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØíÁ!¹±°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØíÉÍÌ°ÅÕ½Ðí¥¹Ñ}ÁÑÈÅÕ½Ðì°À°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÀÌØíÍ¥é°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°À¤(%%%ÍÉÉä ÀÌØíÉФQ¡¸($%%ÀÌØíÉÑlÁtôÄQ¡¸($$$ÀÌØíÉÐôÀÌØíÉÑlÍt($%±Í($$%MÑÉÉ½È ´È¤($$%IÑÕɸ($%¹%(%±Í($%MÑÉÉ½È ´Ä¤($%IÑÕɸ(%¹%

Fill out size "2"


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
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
Sign in to follow this  
Followers 0