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 


String / Text to AOB

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 38

Joined: 10 Apr 2015
Posts: 1526

PostPosted: Thu Nov 24, 2016 1:51 am    Post subject: String / Text to AOB Reply with quote

Hi there,

This code below will return text / string to byte (ASCII).
Code:

text="my text to byte"
tl=tonumber(string.len(text))
print(tl)
x=1
print(string.byte (text,x,tl))
--- text length =15
--- text byte = 109 121 32 116 101 120 116 32 116 111 32 98 121 116 101


But I need to convert text / string to AOB and here is I need :
1. Is there any function or sample to do it ? If any, need the coverted result with format "AA BB CC DD"
2. ReadString string(s) / text from open process and replace with WriteString

example from above text = "my text to byte" replace to "my word to byte". Both text(s) have same length, I already made a function to check both text length, then just need covert text to AOB and read / write the text.

Thanks and regard
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 157

Joined: 25 Jan 2006
Posts: 8071
Location: 127.0.0.1

PostPosted: Thu Nov 24, 2016 3:59 am    Post subject: Reply with quote

Here you go:
Code:

----------------------------------------------------------------------------------------------------
-- func: string.trimstart
-- desc: Trims the start of a string for whitespace.
----------------------------------------------------------------------------------------------------
function string.trimstart(s, c)
    if (not c) then c = ' '; end
    s = string.reverse(s);
    s = string.trimend(s, c);
    return string.reverse(s);
end

----------------------------------------------------------------------------------------------------
-- func: string.trimend
-- desc: Trims the end of a string for whitespace.
----------------------------------------------------------------------------------------------------
function string.trimend(s, c)
    if (not c) then c = ' '; end
    if (string.sub(s, -1) == c) then
        s = string.sub(s, 0, -2);
        s = string.trimend(s, c);
    end
    return s;
end

----------------------------------------------------------------------------------------------------
-- func: string.trim
-- desc: Trims a string of whitespace.
----------------------------------------------------------------------------------------------------
function string.trim(s, c)
    if (not c) then c = ' '; end
    s = string.trimstart(s, c);
    s = string.trimend(s, c);
    return s;
end

---------------------------------------------------------------------------------------------------
-- func: str2hexstr
-- desc: Converts the given string to a hex array string.
---------------------------------------------------------------------------------------------------
function str2hexstr(str)
    local ret = '';
    for x = 1, #str do
        -- Pull a single character from the string..
        local val = str:sub(x, x);

        -- Convert the character to hex..
        local c = string.byte(val);

        -- Append to the result..
        ret = ret .. string.format('%02X ', c);
    end

    -- Trim and return the result..
    return ret:trim();
end

print(str2hexstr('hello world'));

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 38

Joined: 10 Apr 2015
Posts: 1526

PostPosted: Thu Nov 24, 2016 4:45 am    Post subject: Reply with quote

Thanks atom0s, it work.

Code:

print(str2hexstr('hello world'));

68 65 6C 6C 6F 20 77 6F 72 6C 64
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 Lua Scripting 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