0

Following on from this question, I need to set some memory values to strings, rather than longs. I noticed from using Cheat Engine that if I set a value of an address to a string via browsing the memory region, there is an integer value, such as "6513249" being "abc".

How would I go about converting a string to this form, for use as a long?

Thanks.

Community
  • 1
  • 1
Kaikz
  • 171
  • 1
  • 1
  • 9

1 Answers1

2

Convert string to byte array with proper encoding using Encoding.GetBytes and than write bytes directly, you may not need to convert to longs afterall.

If you have to convert to longs - make sure you are understand endiannes to know what bytes should be first, again figure out encoding and convert characters (potentially including surrogate pairs) to byte array with Encoding.GetBytes and combine long values out of every 8 bytes by using shift operators (>> and <<) on bytes. It may be easier to wrap resulting byte array in MemeoryStream and than BinaryReader and read long values.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • Alright, getting somewhere now. Using GetBytes returns "abc" as "610062006300" rather than "6513249". Also, I have some values (eg "10") that I need the byte array to equal to, if that makes sense. Having the string "10" put through the byte array results in "3130", and I need it to be the original value. – Kaikz Sep 18 '12 at 05:39
  • Almost forgot: I also need to zero-out an address before I set a value, what would I use for that? – Kaikz Sep 18 '12 at 05:52
  • @Kaikz, whatever you are saying make not much sence because you randomly use strings as string, decimal or hex representation of integer. Please figure out yourslef what encodings you need and sort out what you are trying to write. GetBytes with correct encoding is likley all you need to convert strings to bytes, numbers don't need to be converted. Don't forget that cheats usally becomes obsolete quicky - so make sure your cheating code is easily configurable :) – Alexei Levenkov Sep 18 '12 at 05:54
  • I figured that was the case. derp. The problem is that whenever I set the value of an address, it edits the grey box in [this image](http://cl.ly/JWI4), however I need to change the yellow box. Haha, as much as cheats sound nice, it's more just changing something left out of the game. :) – Kaikz Sep 18 '12 at 06:00