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 Unicode Strings

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

Joined: 10 Jun 2016
Posts: 25

PostPosted: Thu Jul 28, 2016 4:37 pm    Post subject: Comparing Unicode Strings Reply with quote

So I did a little research and managed to write a script that is supposed to compare two Unicode strings but it doesn't seem to work.
Code:
code:
  fstp dword ptr [esi+5C]  //original code

  push eax
  push [esi+4]
  push string
  call kernel32.lstrcmpW
  test eax,eax
  jnz original_code
  pop eax

  mov [esi+5C],(float)50  //modify original value

original_code:
  pop eax
  mov esi,[esi+44]
  jmp return

string:
db 'M',0,'a',0,'n',0,'a',0,'_',0,'S',0,'t',0,0

Breakpoint at test eax, eax show that ZF is 0 and value of eax is FFFFFFFF... so totally opposite to what it should be for it to work.

The thing I'm not sure about is if I declared the string properly... otherwise I dunno where's the problem.

Attaching ss of breakpoint and structure dissect of addresses which should set the ZF. If anybody has an idea what may be wrong I would feel obliged.



Przechwytywanie_dao2.JPG
 Description:
Breakpoint
 Filesize:  77.79 KB
 Viewed:  9475 Time(s)

Przechwytywanie_dao2.JPG



Przechwytywanie_dao1.JPG
 Description:
Structure dissect
 Filesize:  144.87 KB
 Viewed:  9474 Time(s)

Przechwytywanie_dao1.JPG


Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Thu Jul 28, 2016 5:00 pm    Post subject: Reply with quote

First of all, the breakpoint triggers before the instruction has been executed, but your problem lies in the fact that CE didn't correctly guess the elements in that structure. The string is actually "Mana_Stamina", which you would see if you browsed that memory region.

Try fixing that and see if it works.

_________________
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
Punz1A4
Cheater
Reputation: 0

Joined: 10 Jun 2016
Posts: 25

PostPosted: Thu Jul 28, 2016 6:02 pm    Post subject: Reply with quote

Quote:
First of all, the breakpoint triggers before the instruction has been executed
Thanks, didn't know that Very Happy
As for the Mana_Stamina thing - yeah, my bad it's like that in memory region though declaring
Code:
string:
db 'M',0,'a',0,'n',0,'a',0,'_',0,'S',0,'t',0,'a',0,'m',0,'i',0,'n',0,'a',0,0
didn't change anything. Tried doing it with bytes instead of 'letters' aswell. It still doesn't work :/
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Jul 28, 2016 6:25 pm    Post subject: Reply with quote

May need 1 more ",0" at the end, just to be safe.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4700

PostPosted: Thu Jul 28, 2016 6:32 pm    Post subject: Reply with quote

The second argument (the first one you push) is also incorrect. Putting square brackets around a register (usually) gets the value at the address that register stores. In other words, you're pushing the first two characters of that string and not the address of the string.

One way to fix it:
Code:
...
lea eax,[esi+4]
push eax
push whereverMyStringIs
call kernel32.lstrcmpW
...

_________________
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
Punz1A4
Cheater
Reputation: 0

Joined: 10 Jun 2016
Posts: 25

PostPosted: Thu Jul 28, 2016 7:18 pm    Post subject: Reply with quote

Huge thanks dude - loading address instead of value helped Very Happy
If anybody would ever be interested I also had to add one more jump (jumpafter), cause otherwise popping eax too many times caused the game to crash.

Again huge thanks Penguin.
Code:
code:
  fstp dword ptr [esi+5C]  //original code

  push eax

  lea eax,[esi+4]
  push eax
  push string
  call kernel32.lstrcmpW
  test eax,eax
  jz jumpafter
  pop eax

original_code:
  mov esi,[esi+44]
  jmp return

jumpafter:
  pop eax
  mov [esi+5C],(float)50  //modify original value
  jmp original_code

string:
db 'M',0,'a',0,'n',0,'a',0,'_',0,'S',0,'t',0,'a',0,'m',0,'i',0,'n',0,'a',0,0
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Jul 28, 2016 7:49 pm    Post subject: Reply with quote

Could've just removed your first pop all together. Smile
Back to top
View user's profile Send private message
Punz1A4
Cheater
Reputation: 0

Joined: 10 Jun 2016
Posts: 25

PostPosted: Fri Jul 29, 2016 12:26 pm    Post subject: Reply with quote

Yeah, my brain really started to shut down though after the time I've spend looking in memory viewer Razz

Also I had to add one more 0 to the string for some reason when I wanted to declare 2nd one. Otherwise script was crashing the game.
Code:
string_mana_stamina:
db 'M',0,'a',0,'n',0,'a',0,'_',0,'S',0,'t',0,'a',0,'m',0,'i',0,'n',0,'a',0,0,0

string_health:
db 'H',0,'e',0,'a',0,'l',0,'t',0,'h',0,0
dunno why
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Jul 29, 2016 3:52 pm    Post subject: Reply with quote

Because unicode strings are two bytes, meaning they are null terminated by two zeroes.
Back to top
View user's profile Send private message
Xblade Of Heaven
Master Cheater
Reputation: 0

Joined: 16 Oct 2005
Posts: 395
Location: DEAD

PostPosted: Fri Jul 29, 2016 4:18 pm    Post subject: Reply with quote

2 bytes cmp unicode string, 2+2+2+2,etc....

Code:
cmp dword ptr[eax+4],'M'
je ...
cmp dword ptr[eax+6],'a'
je ...
cmp dword ptr[eax+8],'n'
je ...
cmp dword ptr[eax+a],'a'
je ...

etc...

_________________
Welcome to the Hell.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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