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 


ASM compare against multiple values

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Birdi
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 98
Location: Migrating

PostPosted: Wed Sep 15, 2021 2:38 am    Post subject: ASM compare against multiple values Reply with quote

Just something I've been wondering about recently, is there a simpler way to check multiple specific values in ASM than actually checking individually?

ex:
Code:

cmp eax,1
je @f
cmp eax,2
je @f
cmp eax,3
je @f
cmp eax,4
jne code
@@:
//something
jmp return
code:
...


or loop (not sure if this is formatted correctly, just typing from phone)

Code:

mov ebx,0
@@:
add ebx,1
cmp eax,ebx
je @f
cmp ebx,5
jl @b
@@:
...


..but if a loop is not applicable, is there an easier/better way than checking specific values something may be?

_________________
Trying to learn!
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 95

Joined: 06 Jul 2014
Posts: 3073

PostPosted: Wed Sep 15, 2021 12:25 pm    Post subject: Reply with quote

If you know any system programming language (C, C++, Rust...), throw code into a compiler and see what comes out.

e.g. this C++ code:
Code:
void foo();
void bar();

void injection(int a) {
    if (a == 1 || a == 2 || a == 3 || a == 4)
        foo();
    else
        bar();
}
Using x86-64 gcc 11.2, unoptimized (-O0), it produces more or less the same code you wrote. Optimized (-O2), it generates this:
Code:
injection(int):
  sub  edi, 1
  cmp  edi, 3
  ja   .L2
  jmp  foo()
.L2:
  jmp  bar()
This sub/cmp/jcc pattern is generally what you'll see for comparing whether or not an integer is in a certain range- in this case, 1 to 4 inclusive.
_________________
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
Birdi
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 98
Location: Migrating

PostPosted: Wed Sep 15, 2021 12:45 pm    Post subject: Reply with quote

Honestly I never thought about doing something like that, thanks for the suggestion Penguin!
_________________
Trying to learn!
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 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