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 


LUA jump range Question?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
mop
Advanced Cheater
Reputation: 7

Joined: 05 Mar 2009
Posts: 55

PostPosted: Mon Feb 24, 2025 5:18 am    Post subject: LUA jump range Question? Reply with quote

i dont use lua much but wanted to know when i used the following code

Code:
{$lua}
if syntexcheck then return end


[ENABLE]

ScanX1 = "lib_burst_generated.dll.text+A22C3A"
registerSymbol("bloop" ,ScanX1)
--local scan1 = AOBScan("45 89 44 1B 40 48 83 C4 28 5B 5D 5F 5E 41 5E 41 5F C3 CC CC CC CC 41 57 41 56 41 55 41 54 56 57 55 53 48 83 EC 58 F6 82 D2 01 00 00 01")
--registerSymbol("bloop" ,scan1)

mem = allocateMemory(0x1000)
registerSymbol("newmem" ,mem)

autoAssemble([[
  label(return)

  newmem:
    mov [r11+rbx+40],r8d
    jmp return

  bloop:
    jmp newmem
  return:
]])

[DISABLE]
writeBytes(ScanX1, 0x45, 0x89, 0x44, 0x1B, 0x40)

unregisterSymbol("newmem")
unregisterSymbol("bloop")
deAlloc(mem, 0x1000)

ScanX1 = nil
mem = nil


i get a 14 byte jmp



Code:
7FF800D63C3A - FF25 00000000 000092F821020000 - jmp 221F8920000



but then i use

Code:
[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat

 
 
aobscanmodule(INJECT,lib_burst_generated.dll,45 89 44 1B 40 48 83 C4 28 5B 5D 5F 5E 41 5E 41 5F C3 CC CC CC CC 41 57 41 56 41 55 41 54 56 57 55 53 48 83 EC 58 F6 82 D2 01 00 00 01) // should be unique
alloc(newmem,$1000,INJECT)

label(code)
label(return)

newmem:
mov r8d,(float)1

code:
  mov [r11+rbx+40],r8d
  jmp return

INJECT:
  jmp newmem
return:
registersymbol(INJECT)

[DISABLE]
//code from here till the end of the code will be used to disable the cheat
INJECT:
  db 45 89 44 1B 40

unregistersymbol(INJECT)
dealloc(newmem)



i get a 5 byte jmp

Code:
7FF800D63C3A - E9 C1C35CFF           - jmp 7FF800330000


how can i set it so lua jumps near by like the asm script, i dont quite undurstand why the lua "mem = allocateMemory(0x1000)" creates a jump so far

i belive there is a paramater for alloc "AllocateNearThisAddress" which might help create a jump near by

is there a way to do this with lua allocateMemory(), or is this intended?

--

i have also tried to put alloc(newmem,$1000,bloop) inside autoAssemble() for the lua this works but then dealloc for the lua does not seem to work so well but a issue for another day

--

mainly want to to know why the 2 scripts lua an asm jump so differently and if there is a way to get lua function to jmp near
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4654

PostPosted: Mon Feb 24, 2025 2:07 pm    Post subject: Reply with quote

`jmp <address>` can only jump to addresses within a signed 32-bit displacement relative to RIP. Basically, the address must be within +-2GiB of the `jmp` instruction. It's possible for CE to assemble a pseudoinstruction that can jump farther than 2GiB, but that pseudoinstruction takes up 14 bytes.
That's what the second parameter to `allocateMemory` is for. It is an address CE should allocate memory at (see `VirtualAllocEx`). You should probably call `enumMemoryRegions` to find some free memory nearby, but CE tries to find a free block on its own if the first call to `VirtualAllocEx` fails, so maybe passing the address of the injection point is fine.

If you're calling `autoAssemble` from inside a {$lua} block inside an auto assembler script, you're probably doing something wrong. In this case, you shouldn't be using a {$lua} block at all. Everything could've been done from the AA script itself.
{$lua} blocks can return a string that gets substituted into the AA script in place of the {$lua} block. e.g. you can do `AOBScanUnique(aobstring, '+X')` to only scan through executable memory and pass the result back to the AA script by returning the string `define(foo,<result>)`.

mop wrote:
Code:
--local scan1 = AOBScan("45 89 44 1B 40 48 83 C4 28 5B 5D 5F 5E 41 5E 41 5F C3 CC CC CC CC 41 57 41 56 41 55 41 54 56 57 55 53 48 83 EC 58 F6 82 D2 01 00 00 01")
--registerSymbol("bloop" ,scan1)
`AOBScan` returns a stringlist, not an address. Try `AOBScanUnique` instead
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 468

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

PostPosted: Mon Feb 24, 2025 4:37 pm    Post subject: Reply with quote

allocateMemory has as 2nd parameter the preferred region to allocate at. If you don't specify it, it will be a random location, likely further than 2GB
_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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