View previous topic :: View next topic |
Author |
Message |
Kamd Cheater Reputation: 1
Joined: 02 May 2018 Posts: 28
|
Posted: Tue Aug 13, 2019 7:46 pm Post subject: How to convert hex bytes to string? |
|
|
How can I convert hex bytes (used in AOB scanning) into a string? For example:
Code: | hexbytes = '68 65 6C 6C 6F'
str = HexToString(hexbytes)
-- str should be "hello" |
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Tue Aug 13, 2019 8:04 pm Post subject: |
|
|
Code: | function HexToString(hb)
hb = hb:gsub("%s+", "")
hb = string.gsub(hb, "%s+", "")
return (hb:gsub('..', function (cc)
return string.char(tonumber(cc, 16)) end))
end
hexbytes = '68 65 6C 6C 6F'
str = HexToString(hexbytes)
print(str) |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
Csimbi I post too much Reputation: 92
Joined: 14 Jul 2007 Posts: 3102
|
Posted: Wed Aug 14, 2019 2:48 am Post subject: |
|
|
@Kamd
So, the place where you read those bytes in the first place.
Is there a zero at the end?
If so, just read it as a string.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Wed Aug 14, 2019 5:21 am Post subject: |
|
|
Even if there's not readString takes the number of bytes to read.
_________________
|
|
Back to top |
|
|
Csimbi I post too much Reputation: 92
Joined: 14 Jul 2007 Posts: 3102
|
Posted: Wed Aug 14, 2019 5:47 am Post subject: |
|
|
FreeER wrote: | Even if there's not readString takes the number of bytes to read. |
No, readString does not take the number of bytes to read.
readString takes the maximum number of characters to read.
Meaning, it will stop reading at the NULL character, or, at MaxLength, whichever comes first.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Wed Aug 14, 2019 7:48 am Post subject: |
|
|
true, same difference here assuming you only care about the first 5 bytes.
You'd give 5 and it'd stop whether there's a 0 after or not
_________________
|
|
Back to top |
|
|
Csimbi I post too much Reputation: 92
Joined: 14 Jul 2007 Posts: 3102
|
Posted: Wed Aug 14, 2019 11:26 am Post subject: |
|
|
Well, yes.
If you know for a fact that there is a terminating NULL and you don't care how long string you get, you could put there 255
Either way, depending on the use case, the original poster might get away without having to use a hex-to-string converter.
|
|
Back to top |
|
|
|