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 


How can i convert hex decimal to string or vise versa in ASM

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
TwinShards
Newbie cheater
Reputation: 0

Joined: 23 Jan 2023
Posts: 11

PostPosted: Thu Jan 30, 2025 1:13 am    Post subject: How can i convert hex decimal to string or vise versa in ASM Reply with quote

I've tried rly hard to find my answer with no success.

So how can i, for example, convert this integer: 1008466724768 to be a string or vise versa? I only need this to compare an address containing the 8 bytes value.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 467

Joined: 09 May 2003
Posts: 25673
Location: The netherlands

PostPosted: Thu Jan 30, 2025 4:47 am    Post subject: Reply with quote

looks like a pointer, so you'll have to read the memory at the address is points to and try to interpret that
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
TwinShards
Newbie cheater
Reputation: 0

Joined: 23 Jan 2023
Posts: 11

PostPosted: Thu Jan 30, 2025 11:58 am    Post subject: Reply with quote

1008466724768 was just an example, and no what i am trying to compare is not a pointer.

I have an address which contain 1008466724768 as hex decimal (aka EACD4D07A0)

and an address which will contain at some point 1008466724768 as a string

I need to convert one or the other so i can cmp them.

Update:

Considering cheat engine itself already does that, i figured i could probably just search to find the OpCode that does the job.

I was able to find what i was looking for. For those looking for the same thing:
My current CE version is 7.4

Use a 2nd CE window to hook on the other one and in memory viewer, Search > Find Memory.

The AOB should be: 48 83 C6 01 48 89 CA 48 B8 CD CC CC CC CC CC CC CC 48 F7 E2 48 C1 EA 03 48 89 D7 48 6B D7 0A 48 89 C8 48 29 D0 48 83 C0 30 88 06 48 89 F9 48 85 FF 75 CD
(rcx initially contain 000000EACD4D07A0)

The OpCode above convert Hex 000000EACD4D07A0 to string 8674276648001 then just flip the string to 1008466724768.


Last edited by TwinShards on Thu Jan 30, 2025 2:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 149

Joined: 06 Jul 2014
Posts: 4627

PostPosted: Thu Jan 30, 2025 2:36 pm    Post subject: Reply with quote

Calling a library function like `strtoll` would be the easiest option. If you don't know all the details of calling conventions to call the function yourself in assembly, use {$ccode}:
Code:
[ENABLE]
globalalloc(foo,4096)
label(out_int)
label(my_hex_string)

foo:
  push rbp
  mov rbp,rsp
  sub rsp,20
  mov rax,my_hex_string
{$ccode hexstring=rax}
extern long long out_int;
long long strtoll(const char* str, char** str_end, int base);

out_int = strtoll((const char *)hexstring, 0, 16);
{$asm}
  mov rsp,rbp
  pop rbp
  ret

align 4 CC
out_int:
  dq 0
my_hex_string:
  db 'B24F301A930100' 0

registersymbol(out_int)
registersymbol(my_hex_string)
createthread(foo)

[DISABLE]
You can also write to the register parameters. e.g.
Code:
{$ccode hexstring=rax output=rcx}
long long strtoll(const char* str, char** str_end, int base);

output=strtoll(...)
{$asm}
// rcx is now the converted 8-byte int
...

_________________
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
TwinShards
Newbie cheater
Reputation: 0

Joined: 23 Jan 2023
Posts: 11

PostPosted: Thu Jan 30, 2025 2:53 pm    Post subject: Reply with quote

Thank for the help Dark Byte & ParkourPenguin! I updated my 2nd post.
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 programming 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