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 


Convert hex string from memory to ASCII and rewrite

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Banjo Patterson
Cheater
Reputation: 1

Joined: 15 May 2018
Posts: 36

PostPosted: Sun Dec 02, 2018 4:40 am    Post subject: Convert hex string from memory to ASCII and rewrite Reply with quote

Hey guys,

I've been beating my pathetic ape brain against the wall because I can't work this one out so I thought I'd turn to the pros. What I'd like to do is simply read a hex value from memory, and rewrite it to memory so that I can display it in game via a script I've made. For example, my value at 07821000 is 1B8AEAB8, I'd like this to appear next to a unit's name in-game, however I'm not sure how to do so.
I need to somehow convert e.g. 1B8AEAB8 into 0x31 0x42 0x38 0x41 0x45 0x41 0x42 0x38 so that I can rewrite this to memory somewhere so that it appears in ASCII as it's hex representation (so that the game can successfully read this in as a string). Alas, I am not familiar enough with assembly or LUA to really figure this one out. I would love and appreciate any assistance!

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

Joined: 06 Jul 2014
Posts: 4718

PostPosted: Sun Dec 02, 2018 9:34 am    Post subject: Reply with quote

Banjo Patterson wrote:
1B8AEAB8 into 0x31 0x42 0x38 0x41 0x45 0x41 0x42 0x38
I don't know how you got those bytes from that value.
If you're just converting a byte array to a string, Lua would probably be easiest:
Code:
function byteArrayToString(bt)
  local t = {}
  for i,v in ipairs(bt) do
    t[i] = ('%02X'):format(bt[i])
  end
  return table.concat(t, ' ')
end

Use readBytes / writeString to access the game's memory. Read celua.txt for documentation.

_________________
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
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Dec 02, 2018 9:45 am    Post subject: Reply with quote

Pretty sure that's the string "1B8AEAB8" in ascii. In which case you can probably use something like this in lua "unitname .. tostring(unit_address)" and writeString... somewhere with enough space for the string that will then be used by the game, that's the hard part.

in pure asm you'd probably want to call C's sprintf, yes, knowing C can help in asm hacking too if nothing else because you can compile C code and look at the assembly code the compiler turned it into instead of having to actually be good at assembly lol.

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Banjo Patterson
Cheater
Reputation: 1

Joined: 15 May 2018
Posts: 36

PostPosted: Sun Dec 02, 2018 3:01 pm    Post subject: Reply with quote

Thanks for the replies guys. Parkour, I got those bytes as they are the ASCII code representation of each letter of hex in that value. Love your replies as always, just quickly tested your suggestion there and it's worked straight away for me. Writing exactly what I needed to memory. Now that the hex representation is on the ASCII side there the game will be able to read it and just print straight to the screen (after I reverse the order first)


eg.PNG
 Description:
 Filesize:  2.12 KB
 Viewed:  2324 Time(s)

eg.PNG


Back to top
View user's profile Send private message
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