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 


"4byte" length.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
pirateninja
Newbie cheater
Reputation: 0

Joined: 20 Aug 2005
Posts: 10

PostPosted: Thu May 25, 2006 7:35 pm    Post subject: "4byte" length. Reply with quote

Unsatisfied with the Cheat Engine's trainer maker, I decided to use the addresses I found using CE to make my own trainer in VB. I can do bytes, longs, and doubles, but Not 4byte. Using WriteProcessMemory, the length of a byte is 1, the length of an integer is 2, and the length of a long is 4. What length would I use for a 4byte?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25812
Location: The netherlands

PostPosted: Fri May 26, 2006 1:10 am    Post subject: Reply with quote

hehe, nice joke
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
pirateninja
Newbie cheater
Reputation: 0

Joined: 20 Aug 2005
Posts: 10

PostPosted: Fri May 26, 2006 9:31 am    Post subject: Reply with quote

It wasn't a joke Sad . I know vb is slow but im not doing any freeze-values so it doesn't need to be that fast. It's just that there's more complex stuff going on than pressing a button and changing a value, which can't be done with CE's trainer maker. A byte is the length of 1, so logic would tell me that a 4byte would be 4, but long is 4.
Back to top
View user's profile Send private message
Turtle
Advanced Cheater
Reputation: 7

Joined: 25 Jul 2004
Posts: 85

PostPosted: Fri May 26, 2006 9:44 am    Post subject: Reply with quote

I don't think that the data type matters, if it's 4 bytes, it's 4 bytes.

For example you can have a 4 byte integer, long, float ..etc, the point is when you convert any of those to hex they will all be in this format anyway: 00 00 00 00

As you can see, 4 bytes.


To help you understand this better, download L. Spiro's program, and then go to the tools menu, and click on the converter.

Now enter values in the boxes of the different data types, and as you do look at the "Hex" box, and you will see the 4 bytes being changed as you enter values for the other data types. For example if you enter 17 in the integer box, the hex box will show 11 00 00 00.

L. Spiro's program: http://www.memoryhacking.com/


Last edited by Turtle on Fri May 26, 2006 10:20 am; edited 4 times in total
Back to top
View user's profile Send private message
pirateninja
Newbie cheater
Reputation: 0

Joined: 20 Aug 2005
Posts: 10

PostPosted: Sat May 27, 2006 3:28 pm    Post subject: Reply with quote

Well, using 4 as length is not working. It gives me an overflow error when trying to write a legit 4byte value into a length4 address, meaning that it's not big enough.


I rewrote my code. Can someone advise me on how I should modify this to support 4byte and Text vars? (This is all inside a module)

Code:

Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF

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 WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Const rwBYTE = 1
Public Const rwINTEGER = 2
Public Const rwLONG = 4
Public Const rwDOUBLE = 8
Dim hwnd As Long
Dim ProcessID As Long
Dim ProcessHandle As Long


Public Function GetDecHexStr(ByVal xDecimal As Double) As String ''used for converting numbers into hex
    Dim sReturnStr As String
    Dim lQuotient As Long
    iRemainder = xDecimal Mod 16
    lQuotient = xDecimal \ 16
    While lQuotient > 0
        sReturnStr = sReturnStr + GetHexDigit(iRemainder)
        xDecimal = lQuotient
        iRemainder = xDecimal Mod 16
        lQuotient = xDecimal \ 16
    Wend
    If iRemainder > 0 Then
        sReturnStr = sReturnStr + GetHexDigit(iRemainder)
    End If
    GetDecHexStr = StrReverse(sReturnStr)
End Function


Public Function GetHexDigit(ByVal iDigit As Integer) As String ''used for converting hex into numbers
    Dim sReturnStr As String
    Select Case iDigit
    Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
        sReturnStr = CStr(iDigit)
    Case "10"
        sReturnStr = "A"
    Case "11"
        sReturnStr = "B"
    Case "12"
        sReturnStr = "C"
    Case "13"
        sReturnStr = "D"
    Case "14"
        sReturnStr = "E"
    Case "15"
        sReturnStr = "F"
    End Select
    GetHexDigit = sReturnStr
End Function

Public Function Init(WindowName As String) ''needs to be called on run, stores the vars needed for other functions
    hwnd = FindWindow(vbNullString, WindowName)
    If hwnd = 0 Then
        MsgBox "Could not find process window!", vbCritical, "Error"
        Exit Function
    End If
End Function
   
Public Function ReadValue(Address As Long, Length As Byte) As String ''Returns value at Address with lengh of Length
Dim Value As String
    GetWindowThreadProcessId hwnd, ProcessID
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    If ProcessHandle = 0 Then
        MsgBox "Could not get a process handle!", vbCritical, "Read error"
        Exit Function
    End If
    ReadProcessMem ProcessHandle, Address, Value, Length, 0&
    ReadByte = Value
    CloseHandle ProcessHandle
End Function

Public Function WriteValue(Adress As Long, Value As String, Length As Byte) As String ''Writes to the address Adress with length Legth and writes in it the value Value
    GetWindowThreadProcessId hwnd, ProcessID
    ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID)
    If ProcessHandle = 0 Then
        MsgBox "Could not get a process handle!", vbCritical, "Write error"
        Exit Function
    End If
    WriteProcessMem ProcessHandle, Address, Value, Length, 0&
    CloseHandle ProcessHandle
End Function

Public Function PointerReadValue(Pointer As Long, Offset As Long, Length As Byte) As String ''Reads address from Pointer, adds it to Offset, returns value with length Length
Dim addr1 As Long
Dim addr2 As Long
Dim Value As Double
addr1 = ReadValue(Pointer, rwLONG)
addr2 = GetDecHexStr(Val(addr1) + Val(Offset))
Value = ReadValue(addr2, Length)
PointerReadValue = Value
End Function

Public Function PointerWriteValue(Pointer As Long, Offset As Long, Value As String, Length As Byte) As String ''Reads address from pointer, adds it to offset, stores value with length into pointervalue+offset.
Dim addr1 As Long
Dim addr2 As Long
addr1 = ReadValue(Pointer, rwLONG)
addr2 = GetDecHexStr(Val(addr1) + Val(Offset))
WriteValue addr2, Value, Length
End Function

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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