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 


comparing signed qword

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
OldCheatEngineUser
Whateven rank
Reputation: 3

Joined: 01 Feb 2016
Posts: 514

PostPosted: Sat Aug 12, 2017 9:24 pm    Post subject: comparing signed qword Reply with quote

Code:
{cmp - fcom - cmpsd - cmppd} qword ptr [reg+off],some signed qword bytes

of course if its 64-bit process i would use comisd and matter finish, so any ideas?
all above instructions were tested.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 10

Joined: 09 Aug 2013
Posts: 326

PostPosted: Sat Aug 12, 2017 11:28 pm    Post subject: Reply with quote

I'm sure there are better methods but for something that'll work

https://stackoverflow.com/questions/12944690/working-with-qwords

mentions a way to add/subtract arbitrary length values. if A-B == 0 then they're equal, if A-B > 0 then A > B else A < B and A-B is negative

putting that together gives something like

Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>4</ID>
      <Description>"Auto Assemble script"</Description>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>globalalloc(test,1024)
[ENABLE]
label(data)
label(strings)
label(equal)
label(greater)
label(less)
label(docall)

test:
  // load first vlaue
  mov eax, [data+4]
  mov edx, [data]
  // add second
  sub edx, [data+8]
  sbb eax, [data+C]
  // save result
  mov [data+10], edx
  mov [data+14], eax
  // check
  mov ecx, edx
  or ecx, eax
  cmovz ecx, [strings+0] //equal
  je docall
  // if positive A greater
  // positive if edx &lt; 0x80000000
  cmp eax,80000000
  cmovb ecx, [strings+4] // positive, greater
  cmovnb ecx, [strings+8] //negative, less
docall:
  push 0 // uType OK
  push 0 // caption
  push ecx // text
  push 0 // hwnd
  call MessageBoxA
  ret
data:
  dq #55
  dq #635
  dq 1
equal:
  db 'They are eq',0
greater:
  db 'First is gtr, pos',0
less:
  db 'First is les, neg',0
strings:
  dd equal
  dd greater
  dd less

registerSymbol(data)

createThread(test)
[DISABLE]
unregisterSymbol(data)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>5</ID>
          <Description>"No description"</Description>
          <LastState Value="55" RealAddress="00140053"/>
          <ShowAsSigned>1</ShowAsSigned>
          <VariableType>8 Bytes</VariableType>
          <Address>data</Address>
        </CheatEntry>
        <CheatEntry>
          <ID>7</ID>
          <Description>"No description"</Description>
          <LastState Value="635" RealAddress="0014005B"/>
          <ShowAsSigned>1</ShowAsSigned>
          <VariableType>8 Bytes</VariableType>
          <Address>data+8</Address>
        </CheatEntry>
        <CheatEntry>
          <ID>6</ID>
          <Description>"No description"</Description>
          <LastState Value="-580" RealAddress="00140063"/>
          <ShowAsSigned>1</ShowAsSigned>
          <VariableType>8 Bytes</VariableType>
          <Address>data+10</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 3

Joined: 01 Feb 2016
Posts: 514

PostPosted: Sat Aug 12, 2017 11:47 pm    Post subject: Reply with quote

ops!
i apologize FreeER, forgot to mention its double data type.
a signed double value:
dec -32 hex 0xC040000000000000

OldCheatEngineUser wrote:
Code:
{cmp - fcom - cmpsd - cmppd}


tried to compare it using these instructions, but CE gave me syntax error.

i dont know if its a bug or what.

seems i cant use any of:
Code:
{cmp - fcom - cmpsd - cmppd}

with:
Code:
qword ptr [reg+off]


of course i have a solution in my mind, but i dont want it.
which is converting qword to dword and then compare it.
i guess i should load it then convert it and then store it back to the original location and do my compare.

once again, i apologize.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
ParkourPenguin
Grandmaster Cheater Supreme
Reputation: 52

Joined: 06 Jul 2014
Posts: 1795
Location: Arcadian Suburbia

PostPosted: Sun Aug 13, 2017 7:36 am    Post subject: Reply with quote

Look at the example using fucomip in this post.
_________________
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
OldCheatEngineUser
Whateven rank
Reputation: 3

Joined: 01 Feb 2016
Posts: 514

PostPosted: Sun Aug 13, 2017 8:40 am    Post subject: Reply with quote

thanks PP.

ill test it now, and edit my post after testing.

EDIT AFTER 10 MINS
fucomip give me syntax error, changed it to fucomp.

but still this wont give me what i want, and what is unordered.

i need to compare to see if [register+offset] is equal to -32 as a double data type.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 10

Joined: 09 Aug 2013
Posts: 326

PostPosted: Sun Aug 13, 2017 9:44 am    Post subject: Reply with quote

This seems to work, without the st(1) for the fucomip instruction you do get a compile error.

Code:

<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>217</ID>
      <Description>"compare doubles using fpu"</Description>
      <Options moHideChildren="1"/>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>// x86 signed qword compare
// https://stackoverflow.com/questions/12944690/working-with-qwords
// http://forum.cheatengine.org/viewtopic.php?p=5730174#5730174

globalalloc(test,1024)
[ENABLE]
label(data)
label(strings)
label(equal)
label(greater)
label(less)
label(docall)

test:
  // load second value so that first is in ST(0)
  fld qword ptr [data+8]
  // load first into ST(0)
  fld qword ptr [data]
  // check
  fucomip st(1)
  cmovz ecx, [strings+0] //equal
  je docall
  cmova ecx, [strings+4] // positive, greater
  cmovna ecx, [strings+8] //negative, less
docall:
  push 0 // uType OK
  push 0 // caption
  push ecx // text
  push 0 // hwnd
  call MessageBoxA
  ret
data:
  dq (double)-55
  dq (double)-353
equal:
  db 'They are eq',0
greater:
  db 'First is gtr',0
less:
  db 'First is les',0
strings:
  dd equal
  dd greater
  dd less

registerSymbol(data)

createThread(test)
[DISABLE]
unregisterSymbol(data)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>218</ID>
          <Description>"No description"</Description>
          <LastState Value="-55" RealAddress="016F0036"/>
          <VariableType>Double</VariableType>
          <Address>data</Address>
        </CheatEntry>
        <CheatEntry>
          <ID>220</ID>
          <Description>"No description"</Description>
          <LastState Value="-353" RealAddress="016F003E"/>
          <VariableType>Double</VariableType>
          <Address>data+8</Address>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


Though if you have to deal with rounding issues like -32.00002412 or whatever then I'm not sure if you'd need more code... I googled to get this lol

Of course if you don't have to deal with rounding and you just need to know if it is or isn't equal to 0xC040000000000000 (not greater/less) then you could just break that into the 2 dwords C0400000 and 0 and check that way.
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 3

Joined: 01 Feb 2016
Posts: 514

PostPosted: Sun Aug 13, 2017 10:29 am    Post subject: Reply with quote

thanks FreeER, yes fucomip without st(1) gives some errors.
i didnt know that, at least i learned something.

oh and thanks for your googling, and its not rounded.
FreeER wrote:
Code:
  // load second value so that first is in ST(0)
  fld qword ptr [data+8]
  // load first into ST(0)
  fld qword ptr [data]
  // check
  fucomip st(1)
  cmovz ecx, [strings+0] //equal

btw im not much familiar with stack level st 0,1,2,..7.
i was digging into this thing while ago, but i couldnt get much concept.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 10

Joined: 09 Aug 2013
Posts: 326

PostPosted: Sun Aug 13, 2017 11:02 am    Post subject: Reply with quote

The FPU uses a "stack" much like the stack you push and pop registers to except that it's limited to, I believe 8, values.

ST(0) is the value at the top of the stack ST(1) is the value under ST(0), etc. Many instructions implicitly use the top of the stack and sometimes the top two instructions on the stack, while a few do allow you to specify one or two positions in the stack directly using the ST(x) syntax.

fld is equivalent to some thing like "FpuPush" (made up instruction but).

It's not something I've spent much time trying to understand but I've picked up a couple bits of knowledge about it lol. I find the SSE concept much easier to understand since it works more like registers, but it's just got so many different instructions that uses them in more advanced (packed) ways that it can still get confusing lol
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 3

Joined: 01 Feb 2016
Posts: 514

PostPosted: Sun Aug 13, 2017 11:19 am    Post subject: Reply with quote

FreeER wrote:
I believe 8, values.

ST(0) is the value at the top of the stack ST(1) is the value under ST(0)

yea that what learned too, st(0) - st(7) and what pushed first gonna be on the top level which 0.

stack is more complex along with heap than registers.

there is many instructions i seen, c3 c2 c1 m... idk what else every level have complex set of instructions.

the idea of your code is great, tried to implement it, but i cant understand why do we need strings!

Code:
  fld qword ptr [data+08] // loading -1024
  fld qword ptr [data] // loading -32
  fucomip st(1) // comparing st(0),st(1) which is -1024, -32
  jg code // -32 should jump because its greater tho
  fld dword ptr [esi+000004C0]


but it messed up my game idk why lol.
ill work on it more, if no luck then ill give up lol.

please tell me about the strings, thanks tho.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
FreeER
Master Cheater
Reputation: 10

Joined: 09 Aug 2013
Posts: 326

PostPosted: Sun Aug 13, 2017 11:39 am    Post subject: Reply with quote

OldCheatEngineUser wrote:
but i cant understand why do we need strings!
You don't, I just used a message box to have feedback Smile Instead of loading strings you could jump to different instructions or whatever you want Smile

I think fucomip ST(1) only pops one of the values, not both so try

Code:
fucomip st(1) // comparing st(0),st(1) which is -1024, -32
fstp st(0) // remove the top of the stack


You can open the fpu stack and watch it when you step through the code to be sure however. It's also theoretically possible that the stack is full at that point in the program and you're losing 1 or 2 values by loading 2 for the check, it's not usually an issue but again debugging would help you determine that for sure.
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 3

Joined: 01 Feb 2016
Posts: 514

PostPosted: Sun Aug 13, 2017 11:55 am    Post subject: Reply with quote

ah i see, i didnt use the string hehe.

FreeER wrote:
I think fucomip ST(1) only pops one of the values, not both so try

maybe destination value st(0) because it was pushed and loaded first, this make sense to me.

FreeER wrote:
You can open the fpu stack and watch it when you step through the code to be sure however. It's also theoretically possible that the stack is full at that point in the program and you're losing 1 or 2 values by loading 2 for the check, it's not usually an issue but again debugging would help you determine that for sure.

true, i might have to debug it or just to see fpu registers and what values are there.
but im not ready to step-thro using hareware BP, and i think you are right about "stack is full" because on that function i saw many values/addresses were loading and being pushed on the stack.

im losing hope.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
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