Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


ReadWritingMemory need help in reading string

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
SDHP
How do I cheat?
Reputation: 0

Joined: 08 Apr 2017
Posts: 2

PostPosted: Sat Apr 08, 2017 2:34 pm    Post subject: ReadWritingMemory need help in reading string Reply with quote

hey,

so i'm working on a little trainer and i want that the Label will show the player name

tried:
Label2.Text = ReadWritingMemory.ReadInteger("t6zm", &H234BFD4, 4).ToString

like how i make it to read string instead of numbers ?

any ideas ?
Back to top
View user's profile Send private message
SDHP
How do I cheat?
Reputation: 0

Joined: 08 Apr 2017
Posts: 2

PostPosted: Sun Apr 09, 2017 3:44 am    Post subject: Reply with quote

Update:
i'm able to change the name but not read it..
Code:
  Public Shared Function ReadMemory(Of T)(ByVal address As Integer) As T
        Return MemoryModule.ReadMemory(Of T)(address, 0, False)
    End Function

    Public Shared Function ReadMemory(ByVal address As Integer, ByVal length As Integer) As Byte()
        Return MemoryModule.ReadMemory(Of Byte())(address, length, False)
    End Function

    Public Shared Function ReadMemory(Of T)(ByVal address As Integer, ByVal value As Object, ByVal unicodeString As Boolean)
        Dim buffer As Byte()
        If (GetType(T) Is GetType(String)) Then
            If unicodeString Then
                buffer = Encoding.Unicode.GetBytes(value.ToString)
            Else
                buffer = Encoding.ASCII.GetBytes(value.ToString)
            End If
        ElseIf (GetType(T) Is GetType(Byte())) Then
            buffer = Encoding.Unicode.GetBytes(value.ToString)
        Else
            buffer = Encoding.ASCII.GetBytes(value.ToString)
        End If
        If Not MemoryModule.UpdateProcessHandle Then
            Return CType(Nothing, T)
        End If
        Dim lpBaseAddress As New IntPtr(address)
        Dim dwSize As New IntPtr(buffer.Length)
        If Not MemoryModule.ReadProcessMemory(MemoryModule.ProcessHandle, lpBaseAddress, buffer, dwSize, IntPtr.Zero) Then
            Return CType(Nothing, T)
        End If
        If (GetType(T) Is GetType(Byte())) Then
            Return Conversions.ToGenericParameter(Of T)(buffer)
        End If
        Dim handle As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
        Dim local2 As T = Conversions.ToGenericParameter(Of T)(RuntimeHelpers.GetObjectValue(Marshal.PtrToStructure(handle.AddrOfPinnedObject, GetType(T))))
        handle.Free()
        Return local2
    End Function
    Public Shared Function WriteMemory(ByVal address As Integer, ByVal value As Object, ByVal [unicode] As Boolean) As Boolean
        Dim bytes As Byte()
        If Not MemoryModule.UpdateProcessHandle Then
            Return False
        End If
        If TypeOf value Is String Then
            If [unicode] Then
                bytes = Encoding.Unicode.GetBytes(value.ToString)
            Else
                bytes = Encoding.ASCII.GetBytes(value.ToString)
            End If
        Else
            bytes = MemoryModule.GetObjectBytes(RuntimeHelpers.GetObjectValue(value))
        End If
        Dim lpBaseAddress As New IntPtr(address)
        Dim nSize As New IntPtr(bytes.Length)
        Return MemoryModule.WriteProcessMemory(MemoryModule.ProcessHandle, lpBaseAddress, bytes, nSize, IntPtr.Zero)
    End Function

 Public Shared Function WriteMemory(ByVal address As Integer, ByVal value As Object) As Boolean
        Return MemoryModule.WriteMemory(address, RuntimeHelpers.GetObjectValue(value), False)
    End Function



And when trying to read the memory with that
Code:
Label2.Text = MemoryModule.ReadMemory(&H234BFD4, AscW((ChrW(0))))


i get this error:
Code:
Error   1   Value of type '1-dimensional array of Byte' cannot be converted to 'String'.


and this is how i write memory:
Code:
MemoryModule.WriteMemory(&H234BFD4, (CrystalClearTextBox9.Text & ChrW(0)), False)

the write one is working fine
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 133

Joined: 25 Jan 2006
Posts: 7055
Location: 127.0.0.1

PostPosted: Sun Apr 09, 2017 12:54 pm    Post subject: Reply with quote

Read a byte array then convert that to a string. The two methods you are trying to read are just a 4 byte value and not a full string.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites