In cheat engine doing a far jump like i would have done it if it worked looks like so
JMP Qword ptr[04010000] as an example, but i wonder how cheat engine does this.
If i am at lets say 130000000 as an offset for where to inject, cheat engine automatcly
starst to allocated to an address that is around the same address size, how would i do that cause taking this address manualy and adding it to my to jump to code makes the jump work just like id hope to. but the problem is i dont know if and how i can set my own start base for the allocations like cheat enigne can do. this is using injections with CE aa scripts in cheat engine, if i select the tools/allocate memory option in CE it will start to allocate at a 32 bit address span and up. but its like cheat engine sees that i am at a higher address and starts to allocate from around there when i use the injection scripts. if i could do the same i could make it work perhapse.
If you want me to post some code il post it right up.
Code in module i use here in this last test project.
Code:
Imports System.ComponentModel
Module Module1
#Region "Declarations"
Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As IntPtr, ByVal flAllocationType As Integer, ByVal flProtect As Integer) As IntPtr
Declare Function VirtualProtectEx Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As IntPtr, ByVal newProtect As Integer, ByRef oldProtect As Integer) As Boolean
Public Declare Function CloseHandle Lib "KERNEL32" _
(ByVal hObject As Int32) _
As Boolean
Public Declare Function GetAsyncKeyState Lib "USER32" _
(ByVal vKey As Int32) _
As Int16
Public Declare Function IsDebuggerPresent Lib "KERNEL32" () As Boolean
Public Declare Function OpenProcess Lib "KERNEL32" _
(ByVal DesiredAccess As Int32, _
ByVal InheritHandle As Boolean, _
ByVal ProcessId As Int32) _
As Int32
Private Declare Function WriteProcessMemory Lib "kernel32" _
(ByVal Handle As Integer, _
ByVal address As Long, _
ByRef Value As Int32, _
ByVal Size As Integer, _
ByRef lpNumberOfBytesWritten As Long) _
As Long
Private Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal Handle As Int32, _
ByVal address As Int32, _
ByRef Value As Int32, _
Optional ByVal Size As Int32 = 4, _
Optional ByVal lpNumberOfBytesWritten As Int64 = 0) _
As Integer
'PROCESS ACCESS RIGHTS.
Public PROCESS_TERMINATE As Int32 = 1
Public PROCESS_CREATE_THREAD As Int32 = 2
Public PROCESS_VM_OPERATION As Int32 = 8
Public PROCESS_VM_READ As Int32 = 16
Public PROCESS_VM_WRITE As Int32 = 32
Public PROCESS_DUP_HANDLE As Int32 = 64
Public PROCESS_CREATE_PROCESS As Int32 = 128
Public PROCESS_SET_QUOTA As Int32 = 256
Public PROCESS_SET_INFORMATION As Int32 = 512
Public PROCESS_QUERY_INFORMATION As Int32 = 1024
Public PROCESS_SUSPEND_RESUME As Int32 = 2048
Public PROCESS_ALL_ACCESS As Int32 = 4091
'ALLOCATION TYPES.
Public MEM_COMMIT As Int32 = 4096
Public MEM_RESERVE As Int32 = 8192
Public MEM_RESET As Int32 = 524288
Public MEM_TOP_DOWN As Int32 = 1048576
Public MEM_PHYSICAL As Int32 = 4194304
'MEMORY PROTECTION TYPES.
Public PAGE_NOACCESS As Int32 = 1
Public PAGE_READONLY As Int32 = 2
Public PAGE_READWRITE As Int32 = 4
Public PAGE_WRITECOPY As Int32 = 8
Public PAGE_EXECUTE As Int32 = 16
Public PAGE_EXECUTE_READ As Int32 = 32
Public PAGE_EXECUTE_READWRITE As Int32 = 64
Public PAGE_EXECUTE_WRITECOPY As Int32 = 128
Private Const ACCESS_RIGHTS_ALL = &H1F0FFF
Private process_id As Int32 = 0
Public pHandle As Integer = 0
Dim FlagValue As Integer
Public Function GetProcessId(ByVal game_name As String) As Boolean 'Checks to see if the game is running (returns True or False) and sets th pHandle *REQUIRED TO USE*
For Each p As Process In Process.GetProcessesByName(game_name)
process_id = p.Id
pHandle = OpenProcess(56, False, process_id)
Return True
Next
Return False
End Function
#End Region
#Region "Memory Allocations"
Public Function AllocMem() As Integer 'Allocates memory in the process and returns the starting address of the allocated area
Dim pBlob As IntPtr = VirtualAllocEx(pHandle, New IntPtr(), New IntPtr(2048), MEM_COMMIT, PAGE_EXECUTE_READWRITE)
If pBlob = IntPtr.Zero Then
Return 0
MsgBox("The trainer couldn't implant the cheats. Please restart the trainer.", MsgBoxStyle.Critical, "Error")
Else : Return pBlob
End If
End Function
Sub RemoveProtection(ByVal AddressOfStart As Integer) 'Changes the protection of the page with the specified starting address to PAGE_EXECUTE_READWRITE
Dim oldProtect As Integer
If Not VirtualProtectEx(pHandle, New IntPtr(AddressOfStart), New IntPtr(2048), PAGE_EXECUTE_READWRITE, oldProtect) Then Throw New Win32Exception
End Sub
#End Region
#Region "Write"
Public Sub WriteByte(ByVal address As Int64, ByVal Value As Byte) 'Writes a single byte value
WriteProcessMemory(pHandle, address, Value, 1, 0)
End Sub
Public Sub WriteInt32(ByVal address As IntPtr, ByVal Value As Int32) 'Writes a 4 bytes value
WriteProcessMemory(pHandle, address, Value, 4, 0)
End Sub
Public Sub WriteASM(ByVal address As Int64, ByVal Value As Byte()) 'Writes assembly using bytes
For i As Long = LBound(Value) To UBound(Value)
WriteByte(address + i, Value(i))
Next
End Sub
Public Function WritePointer(ByVal Pointer As Long, ByVal Buffer As Int32, ByVal OffSet() As Int32) 'Writes to a pointer
For Each I As Integer In OffSet
ReadProcessMemory(pHandle, Pointer, Pointer)
Pointer += I
Next
WriteProcessMemory(pHandle, Pointer, Buffer, 4, 0)
Return 0
End Function
Public Function WriteAddPointer(ByVal Pointer As Int32, ByVal Buffer As Int32, ByVal OffSet() As Int32) 'Adds a value to a pointer
For Each I As Integer In OffSet
ReadProcessMemory(pHandle, Pointer, Pointer)
Pointer += I
Next
WriteProcessMemory(pHandle, Pointer, ReadInt32(Pointer) + Buffer, 4, 0)
Return 0
End Function
' 8 Bytes in den Przess schreiben
Public Sub Write_Float(ByVal address As Int32, ByVal value As Int64)
Dim process_handle As Int32
process_handle = OpenProcess(ACCESS_RIGHTS_ALL, False, process_id)
If process_handle <> 0 Then
WriteProcessMemory(process_handle, address, value, 8, 0)
End If
CloseHandle(process_handle)
End Sub
' Für die CodeInjection
Public Sub autopatcher(ByVal address As Int32, ByVal value As Byte())
Dim i As Byte
For i = LBound(value) To UBound(value)
WriteByte(address + i, value(i))
Next
End Sub
#End Region
Public Function AllocJump(ByVal source As Int32, ByVal destination As Int32, Optional ByVal Nops As Integer = 0) As Boolean 'Creates a jump from the specified address to a destination address
WriteByte(source, &HE9)
WriteInt32(source + 1, destination - source - 5)
If Nops = 0 Then
Return 0
End If
For i As Int32 = 1 To Nops
WriteByte(source + 4 + i, &H90)
Next
Return 0
End Function
Code:
Public Class Form1
Private Const ProcName = "Outlast"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GetProcessId(ProcName)
'WriteASM(&H140446285, New Byte() {&H90, &H90, &H90, &H90, &H90})
Dim pBlob As UInt64 = VirtualAllocEx(pHandle, New IntPtr(), New IntPtr(2048), MEM_COMMIT, PAGE_EXECUTE_READWRITE)
TextBox1.Text = Hex(pBlob)' i use this to see the address in hex only
Dim caveAddr = pBlob
AllocJump(&H13CF0006, caveAddr) 'This Works fine
End Sub
End Class
I get the following error if i do this
AllocJump(&H13CA00000, caveAddr) This does not work , the address from my code is this high in the address so how do i do the jump?
"constant expression not representable in type 'integer'"
So the question is where in the module i need to change it to work.
I dont know why the code wraped gets outputet in 1 single line here , but i added code marks around it.
ok my bad it seems to be layed oout fine now.
I am willing to pay anyone that is able to solve this, this is driving me nuts.
If ok i can pay for some kind of code that can calculate the right jump from the code i provided to work as i hoped.
I have tried for over a week now.