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 


Why doesn't this auto assemble script work

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

Joined: 18 Nov 2021
Posts: 6

PostPosted: Tue Dec 07, 2021 2:45 pm    Post subject: Why doesn't this auto assemble script work Reply with quote

I little over a week I made a post with another problem (called "Help at code injection"), which mostly solved the problem. Although I was told to use vmaxsd, which worked, but not what I needed, so I used vminsd instead, which I think should work, but then CE says that it can't be compiled.
Here's the code I tried using, followed by the error which is thrown:
Code:

[Enable]
alloc(newmem,2048,0458935D)
label(returnhere)
label(originalcode)
label(exit)
alloc(mynumber,8)

newmem:
vminsd xmm0,xmm0,[mynumber]
vmovsd [rcx+68],xmm0


originalcode:
vmovsd [rcx+68],xmm0

exit:
jmp returnhere

0458935D:
jmp newmem
returnhere:



[Disable]
dealloc(newmem)
dealloc(mynumber)
0458935D:
vmovsd [rcx+68],xmm0
//Alt: db C5 FB 11 04 19

Code:
Error in line 9 (vminsd xmm0,xmm0,[ffffffffffffffff]) :This instruction can't be compiled


The guy in the former post didn't know why vminsd didn't work either, so I tried using my past code, but with some changes. Here's that code:

Code:

[Enable]
alloc(newmem,2048,02CB51A8)
label(returnhere)
label(originalcode)
label(exit)
alloc(mynumber,8)

mynumber:
  dq (double)3.0 ; declare double

newmem:
  comisd xmm0,[mynumber] ; compare two double float numbers (I tried cmp and fcom aswell instead of comisd, neither of which worked)
  jg originalcode: ; jump if greater than
  vmovsd [rcx+rbx],[mynumber] ; move (double) 3

originalcode:
  vmovsd [rcx+rbx],xmm0 ; move (double) 3

exit:
  jmp returnhere

02CB51A8:
jmp newmem
returnhere:


[Disable]
dealloc(newmem)
02CB51A8:
vmovsd [rcx+rbx],xmm0
//Alt: db C5 FB 11 04 19

Error:
Code:

Error in line 9 (comisd xmm0,[ffffffffffffffff]) :This instruction can't be compiled


The purpose of the code is to compare xmm0 (which is a value (double) from 0 to 4 with 3, if it's larger than 3, I was to set it to 3, so that it's new maximum value is 3.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4297

PostPosted: Tue Dec 07, 2021 4:32 pm    Post subject: Reply with quote

Trying to directly address a memory location like [mynumber] might fail in 64-bit code (see RIP-relative addressing). There's no guarantee mynumber is within 2GiB of that instruction to allow for RIP-relative addressing. That's what the third parameter to alloc is for.

comisd sets the ZF and CF flags in EFLAGS according to the result (also PF but it's only set for unordered results). You need to use the above/below jcc variants to check those flags. The greater/less jcc variants check the ZF, SF, and OF flags.

"jg originalcode" jumps if greater than. Jumping means the cpu will change the path of execution and start executing code at that location. In this case, you trying to jump if xmm0 > 3 skips you trying to write 3 to that address. This effectively means the larger value between 3 and xmm0 gets written to the address.

In general instructions can't directly move from one memory location to another: i.e. "vmovsd [rcx+rbx],[mynumber]" won't work. You need to use a register, e.g. xmm0, as an intermediary.

Directly after you try to move 3 into that memory location, you still execute the original code that writes the original value to the memory location, undoing your write.


What's wrong with foregoing AVX and using SSE2 (minsd)? It should work AFAIK.
https://forum.cheatengine.org/viewtopic.php?p=5775332#5775332

And as I've said in that previous thread, you should probably be using an aobscan.

_________________
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
HyggeAlien
How do I cheat?
Reputation: 0

Joined: 18 Nov 2021
Posts: 6

PostPosted: Wed Dec 08, 2021 11:25 am    Post subject: Reply with quote

English is not my primary language, sorry for the trouble that has caused. What do you mean by foregoing AVX? And minsd doesn't work for some reason, it wont compile, or is that simply because of that thing where:
Quote:
In general instructions can't directly move from one memory location to another: i.e. "vmovsd [rcx+rbx],[mynumber]" won't work. You need to use a register, e.g. xmm0, as an intermediary.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4297

PostPosted: Wed Dec 08, 2021 12:44 pm    Post subject: Reply with quote

HyggeAlien wrote:
What do you mean by foregoing AVX?
vminsd, vmaxsd, vmovsd, etc. are instructions that come from AVX- the Advanced Vector Extensions. minsd, maxsd, movsd, etc. are instructions that come from one of the SSE instruction sets (minsd is SSE2).
The game is using AVX. You should try to use whatever the game is using, but since CE can't assemble the AVX instruction vminsd, you should try to use the SSE2 instruction minsd instead.

HyggeAlien wrote:
And minsd doesn't work for some reason, it wont compile

This assembles fine for me attached to the 64-bit tutorial:
Code:
globalalloc(foo,4096)
label(mynumber)

foo:
  minsd xmm0,[mynumber]
  movsd [rcx+rbx],xmm0

align 10 cc
mynumber:
  dq (double)3.0

If it doesn't work for you, it's probably because mynumber is too far away for the instruction to access it. Use the third alloc parameter, or make mynumber a label with an align before it like you see in the example above.

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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