|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
MarkiThePews How do I cheat? Reputation: 0
Joined: 14 Nov 2016 Posts: 4
|
Posted: Mon Nov 14, 2016 1:35 am Post subject: A FUNCTION to find for a string and a FUNCTION to replace it |
|
|
I need a function that find for a string and a function to replace it over and over.
like:
Code: | function findString("string to find")
codes
end
function replaceString("string")
codes
end
-- the target have the string 99999
findString("99999");
replaceString("12345"); -- now it become 12345
replaceString("54321"); -- and now it become 54321 |
this is a script that finds and replaces but destroy the var after (u have to find the String every time u replace (this script is scripted by DaSpamer), make it took too much times:
Code: | function replaceString(string_in,string_out,ignore_length)
if (not ignore_length) then
if (not(string_in and string_out and #string_in >= #string_out)) then
return print("Not recommended to override shorter string with a longer string");
end
end
local bytes_in = {};
local bytes_out = {};
for i=1,(#string_in >= #string_out and #string_in or #string_out) do -- lazy to copy paste same loop for string_out so just looping both and inserting if possible
if (i <= #string_in) then
table.insert(bytes_in,string.format("%x", tonumber(string.byte(string.sub(string_in,i,i)))));
end
if (i <= #string_out) then
-- table.insert(bytes_out,'0x' .. string.format("%x", tonumber(string.byte(string.sub(string_out,i,i)))));
table.insert(bytes_out,tonumber(string.byte(string.sub(string_out,i,i))));
end
end
local object = AOBScan(table.concat(bytes_in," "));
if object then
for entry = 0, object.Count -1 do
writeBytes(object.getString(entry), unpack(bytes_out));
end
object.destroy();
return true
end
return false
end
-- replaceString(String to find(string), string to replace with(string), ignore replace string length(true/false))
-- returns true/false as result
-- if use this like the script that i want, it'll be like:
-- the target have the string 99999
replaceString("99999","12345",false); -- now it become 12345
replaceString("12345","54321",false); -- now it become 54321 |
_________________
Bad grammar, sorry
Last edited by MarkiThePews on Tue Nov 15, 2016 6:11 am; edited 1 time in total |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Mon Nov 14, 2016 1:48 pm Post subject: |
|
|
The attached ct has the requested function AobPatch, together with some aob manipulation function.
test code:
Code: |
-- reuse same patcher until reset
patcher = patcher or AobPatch(s2aob'abc','?? ?? ?? ?? ?? ??',s2aob'efjj')
print(patcher({offset=2},'?'..math.random(1,9),s2aob(''..math.random(0x10000,0x99999),nil,true)))
|
AobPatch return a function that capture information of what to scan, in this case patcher. When patcher called with another aob, it will patch the previous scan result address with the new aob. Wildcard and offset shift supported.
Some aob manipulation functions:
s2aob(s,iswide,zeroTerminated) : convert a string to aob, eg.
s2aob('abc') -> '61 62 63',
s2aob('abc',true,true)->'61 00 62 00 63 00 00 00'
n2aob(n,sz,isBigEndian):
convert a number to aob , depend on sz format, endian support.
sz can be number 1-8 (integer)or 'f' 'd' (floating point),eg
n2aob(2.5,'d',true) ->'40 04 00 00 00 00 00 00'
n2aob(-3,3)->'FD FF FF'
joinaob(...): join some aob to one aob, eg. in some string representation, eg mono string, the string length is precede with the wide string chars, the aob can be made as:
s = 'testwide'
joinaob(n2aob(s:len(),4),s2aob(s,true)) ->
'08 00 00 00 74 00 65 00 73 00 74 00 77 00 69 00 64 00 65 00'
bye~
Description: |
function definition at Lua Windows |
|
Download |
Filename: |
_aobpatcher.CT |
Filesize: |
7.59 KB |
Downloaded: |
445 Time(s) |
_________________
- Retarded. |
|
Back to top |
|
|
MarkiThePews How do I cheat? Reputation: 0
Joined: 14 Nov 2016 Posts: 4
|
Posted: Tue Nov 15, 2016 6:00 am Post subject: How to use this ? |
|
|
panraven wrote: | The attached ct has the requested function AobPatch, together with some aob manipulation function.
test code:
Code: |
-- reuse same patcher until reset
patcher = patcher or AobPatch(s2aob'abc','?? ?? ?? ?? ?? ??',s2aob'efjj')
print(patcher({offset=2},'?'..math.random(1,9),s2aob(''..math.random(0x10000,0x99999),nil,true)))
|
AobPatch return a function that capture information of what to scan, in this case patcher. When patcher called with another aob, it will patch the previous scan result address with the new aob. Wildcard and offset shift supported.
Some aob manipulation functions:
s2aob(s,iswide,zeroTerminated) : convert a string to aob, eg.
s2aob('abc') -> '61 62 63',
s2aob('abc',true,true)->'61 00 62 00 63 00 00 00'
n2aob(n,sz,isBigEndian):
convert a number to aob , depend on sz format, endian support.
sz can be number 1-8 (integer)or 'f' 'd' (floating point),eg
n2aob(2.5,'d',true) ->'40 04 00 00 00 00 00 00'
n2aob(-3,3)->'FD FF FF'
joinaob(...): join some aob to one aob, eg. in some string representation, eg mono string, the string length is precede with the wide string chars, the aob can be made as:
s = 'testwide'
joinaob(n2aob(s:len(),4),s2aob(s,true)) ->
'08 00 00 00 74 00 65 00 73 00 74 00 77 00 69 00 64 00 65 00'
bye~ |
I don't really know lua, idk how to use this, maybe this isn't the thing that i want, read my post more correctly please
_________________
Bad grammar, sorry |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Tue Nov 15, 2016 7:24 am Post subject: |
|
|
Your replaceString function is not a separated function in my script, but what returned by AobPatch.
Can you try:
Code: |
function findString(s)return AobPatch(s2aob(s))end
-- then replaceFunction is like that:
replaceString = findString("99999")
-- now replaceString will remember the address of string '99999' on 1st scan
-- to replace a new string in those address
replaceString("12345") -- scan for address in 1st replace
replaceString("54321") -- reuse address in sequence replace
|
These should what happen in memory
Code: | addr: 00100 00200 00300 00400
init:'99999''12345''54321''99999' <- memory
----- -----
1st :'12345''12345''54321''12345', your: replaceString("99999","12345",false)
:'12345''12345''54321''12345', my: replaceString = findString("99999")
===== ===== replaceString("12345")
----- ----- -----
2nd :'54321''54321''54321''54321', your: replaceString("12345","54321",false);
:'54321''12345''54321''54321', my: replaceString("54321")
===== =====
----- ----- ----- -----
3rd :'99999''99999''99999''99999', your: replaceString("54321","99999",false);
:'99999''12345''54321''99999', my: replaceString("99999")
===== =====
|
Tell me if I'm misunderstood.
bye~
_________________
- Retarded. |
|
Back to top |
|
|
MarkiThePews How do I cheat? Reputation: 0
Joined: 14 Nov 2016 Posts: 4
|
Posted: Tue Nov 15, 2016 10:26 am Post subject: |
|
|
panraven wrote: | Your replaceString function is not a separated function in my script, but what returned by AobPatch.
Can you try:
Code: |
function findString(s)return AobPatch(s2aob(s))end
-- then replaceFunction is like that:
replaceString = findString("99999")
-- now replaceString will remember the address of string '99999' on 1st scan
-- to replace a new string in those address
replaceString("12345") -- scan for address in 1st replace
replaceString("54321") -- reuse address in sequence replace
|
These should what happen in memory
Code: | addr: 00100 00200 00300 00400
init:'99999''12345''54321''99999' <- memory
----- -----
1st :'12345''12345''54321''12345', your: replaceString("99999","12345",false)
:'12345''12345''54321''12345', my: replaceString = findString("99999")
===== ===== replaceString("12345")
----- ----- -----
2nd :'54321''54321''54321''54321', your: replaceString("12345","54321",false);
:'54321''12345''54321''54321', my: replaceString("54321")
===== =====
3rd :'54321''54321''54321''54321', your: replaceString("54321","99999",false);
:'99999''12345''54321''99999', my: replaceString("99999")
===== =====
|
Tell me if I'm misunderstood.
bye~ |
wow really thanks bro! [haven't try it, will try it few hours later]
btw i've found a script that helped me a lot, similar to this but it's aob and it's Auto-assemble: forum(dot)cheatengine(dot)org/viewtopic(dot)php?p=5620925 (but the script can become a lua script easily)
(btw can u make a few codes that transform aob to string ? i'll be really thankful , and also, give me some good lua programming learning sites ):
EDIT: Your script don't work with string (text) ?
_________________
Bad grammar, sorry |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Tue Nov 15, 2016 11:35 am Post subject: |
|
|
oops, yes I'm mistaken. The returned replaceString need covert string to aob too.
Change previous findString with following, hopefully it work:
Code: |
function findString(str2scan)
local replacer = AobPatch(s2aob(str2scan))
return function(str2replace) return replacer(s2aob(str2replace)) end
end
|
@good lua programming learning sites :
For pure lua, may start with the book from offical site https://www.lua.org/pil/contents.html
Here the ce specific lua function : https://raw.githubusercontent.com/cheat-engine/cheat-engine/master/Cheat%20Engine/bin/main.lua which should be the same main.lua in updated the CE Dir.
May look for *.lua *.ct in forum for ce usage of lua.
@transform aob to string
If 'aob' means a lua byte table (eg. something returned from readBytes(addr,10,true)), ce has the functions
byteTableToString(table),
byteTableToWideString(table)
to do the conversion.
bye~
_________________
- Retarded. |
|
Back to top |
|
|
|
|
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
|
|