 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu Feb 18, 2016 9:35 am Post subject: Questions about "call rand".Thanks. |
|
|
Hi there. I have some questions(sorry for my English):
1. If I call "rand", what is the range of the random number? Is it from 0 - 65535 or something? Moreover, can i define the range?
2. Please take a look at the following code:
| Code: | call rand
or eax,1
cmp eax,0 |
What does each line mean? I am new to programming, so more detailed explanations help a lot. From my understanding, the first line calls rand to get a random number, and then save it in eax. The third line compare the value in eax with 0, and then return a false or true? Also, I don't know what the second line means.
3. Is it possible to make a randomizer in AA?
Thanks a lot.
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Thu Feb 18, 2016 11:39 am Post subject: |
|
|
OR performs a bitwise or.
In essence, it sets EAX equal to 1 or 0 depending on whether or not the first bit inside EAX already equals 1 or 0.
RAND returns several possible values. However, those values must either be even or odd.
The OR basically determines if the returned value is odd (1) or even (0).
This is how you do the 50/50 comparison you asked about in your previous post.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4709
|
Posted: Thu Feb 18, 2016 11:49 am Post subject: |
|
|
1. I suppose that depends on what "rand" function you call. If you're talking about the one in the MSVCRT library, then I think that is the case (Google it for more info).
2. call rand pushes the address of the next instruction onto the stack and jumps to wherever the symbol "rand" is located. Assuming "rand" is expecting to get called, it will have a "ret" statement eventually, which will pop that aforementioned address off the stack and jump back to it, presumably with something stored in eax in this case.
or eax,1 performs a bitwise or operation on the eax register and the immediate value 1. Basically, this just makes eax an odd number.
cmp eax,0 compares eax with 0 and sets EFLAGS accordingly. This is next to useless combined with the previous instruction since eax will always be an odd number.
3. ...that is a randomizer. If you want to look at more:
https://en.wikipedia.org/wiki/List_of_random_number_generators
Writing one in assembly isn't any different than writing one in any other language. It just may take more time.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Last edited by ParkourPenguin on Thu Feb 18, 2016 12:20 pm; edited 1 time in total |
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu Feb 18, 2016 12:08 pm Post subject: |
|
|
| Zanzer wrote: | OR performs a
In essence, it sets EAX equal to 1 or 0 depending on whether or not the first bit inside EAX already equals 1 or 0.
RAND returns several possible values. However, those values must either be even or odd.
The OR basically determines if the returned value is odd (1) or even (0).
This is how you do the 50/50 comparison you asked about in your previous post. |
Thanks for the reply. However, I keep getting the same result from that piece of code. It looks like it's not random.
As for ParkourPenguin:
Thanks for the reply. Another question:
Shouldn't "call rand" return a random number? Such as 13. So now eax equals to 13, right? If so, how does "or eax 1" change the value in eax to 1 or 0? Shouldn't be at least 13 or 1? I'm so confused.
Last question:
If "or eax 1" always returns an odd number, then how does that piece of code considered a randomizer?
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4709
|
Posted: Thu Feb 18, 2016 12:33 pm Post subject: |
|
|
I had a momentary lapse of reason when reading that ASM and mistook the bitwise or operator for the bitwise and operator. I apologize for any confusion and have edited my previous post to correct the mistake.
Let's say that call makes eax 6, or 0110 in binary. Then, only focusing on the first nibble, the or instruction would do this:
| Code: | EAX = 0110
1 = 0001
EAX or 1 = 0111 = 7 |
Note that using or instead of and makes that cmp nearly pointless. I believe that's meant to be and instead.
| fmanager wrote: | | If "or eax 1" always returns an odd number, then how does that piece of code considered a randomizer? | Can you guess what the odd number is with absolute certainty every time it's run? If not, then it's pseudo-random. If you can, then try calling srand and pass it some parameter like the current time (i.e. GetTickCount from kernel32.dll).
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Thu Feb 18, 2016 12:43 pm Post subject: |
|
|
| ParkourPenguin wrote: | I had a momentary lapse of reason when reading that ASM and mistook the bitwise or operator for the bitwise and operator. I apologize for any confusion and have edited my previous post to correct the mistake.
Let's say that call makes eax 6, or 0110 in binary. Then, only focusing on the first nibble, the or instruction would do this:
| Code: | EAX = 0110
1 = 0001
EAX or 1 = 0111 = 7 |
Note that using or instead of and makes that cmp nearly pointless. I believe that's meant to be and instead.
| fmanager wrote: | | If "or eax 1" always returns an odd number, then how does that piece of code considered a randomizer? | Can you guess what the odd number is with absolute certainty every time it's run? If not, then it's pseudo-random. If you can, then try calling srand and pass it some parameter like the current time (i.e. GetTickCount from kernel32.dll). |
IT WORKED after I changed"or" to "and"!!! BIG BIG THANKS! I have been working on this problem for days! Thank you so much!
Now, this is the 50/50 randomizer(or 50% randomizer), anyway to make it 25% or less? Will nested "call rand" work? Thanks again.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4709
|
Posted: Thu Feb 18, 2016 3:59 pm Post subject: |
|
|
If you're just concerned about powers of 2, then AND it with more bits taken into consideration. Namely, something AND 3 would give a 25% chance of it being 0. Something AND 7 would give a 12.5% chance of it being equal to 0.
If you don't want it to be limited to powers of 2, then you could use DIV to divide EAX by something and test if the remainder is 0. For example, if you want a 1 in 10 chance of something happening:
| Code: | call rand
xor edx,edx
mov ecx,#10
div ecx
test edx,edx
// do something based on whether edx == 0 |
If you don't want it to be an exact 1-in-X chance (e.g. 2-in-5 chance), then compare edx with a value and do something based on whether it's greater than or less than that value.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Fri Feb 19, 2016 11:23 am Post subject: |
|
|
| ParkourPenguin wrote: | If you're just concerned about powers of 2, then AND it with more bits taken into consideration. Namely, something AND 3 would give a 25% chance of it being 0. Something AND 7 would give a 12.5% chance of it being equal to 0.
If you don't want it to be limited to powers of 2, then you could use DIV to divide EAX by something and test if the remainder is 0. For example, if you want a 1 in 10 chance of something happening:
| Code: | call rand
xor edx,edx
mov ecx,#10
div ecx
test edx,edx
// do something based on whether edx == 0 |
If you don't want it to be an exact 1-in-X chance (e.g. 2-in-5 chance), then compare edx with a value and do something based on whether it's greater than or less than that value. |
Thanks a lot.
|
|
| Back to top |
|
 |
|
|
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
|
|