panraven Grandmaster Cheater
Reputation: 61
Joined: 01 Oct 2008 Posts: 958
|
Posted: Fri Mar 04, 2016 4:02 pm Post subject: mini AA Macro |
|
|
This is a simple application of the lua function registerAssembler.
Also check this thread http://forum.cheatengine.org/viewtopic.php?t=574426 by mgr.inz.Player
updated:
- fix ; should not count empty line & label
- to abuse syntax highlight, require the command id follow by at least one space and an exclamation mark
Code: | --
-- load module
local minimacro = cerequire 'minimacro'
-- load saved macro from table file
minimacro.Load('mymacro')
-- define by string, can also be defined by function, but cannot save
minimacro.Set('REGBOUND',[=[function(hexaddr,inst)
local reg,vtype,lbound,ubound,ret = inst:match('^ *(.-) *; *(.-) *; *(.-) *; *(.-) *$')
if reg~=nil and reg:len()>0 and lbound:len()>0 and ubound:len()>0 then
local jmpshort = targetIs64Bit() and 'short ' or ''
lbound,ubound = vtype..lbound, vtype..ubound
ret = string.format([[
cmp %s,%s
jge %s@f
mov %s,%s
@@:
cmp %s,%s
jle %s@f
mov %s,%s
@@:
]],reg,lbound,jmpshort,reg,lbound,reg,ubound,jmpshort,reg,ubound)
end
return ret~=nil and ret:gsub('&',hexaddr) or nil
end]=])
-- minimacro.Save('filename') -- to save all string type macro definition into a file
-- load the saved file into table file of the *.ct , like 'mymacro' , so that it can be reload
-- minimacro.List() -- to see what macro defined at this point
-- test
openProcess('cheatengine-x86_64.exe')
print(tostring(autoAssemble([[
globalalloc(testpad,$1000)
define(symbol,1234)
testpad:
Push ! rax;rbx;rcx;rdx;[&]
Pop ! rax;rbx;rcx;rdx;[&]
// & is starting address of the current (custom or not) instruction, changed every lines
Bound ! dword ptr[testpad+40];(float);0.1;100
Bound ! eax;#;1;10000
mul ! push symbol;pop rbp;jmp & //<-- relative jump, not right
]])))
|
LIMITATION:
since the assembling rely on rough simulation, which the generated bytes is ALWAYS located at 'scratchpad' symbol address, instead of the supplied actual starting address, the mini macro cannot work with relative address offset instruction (ie. e9 xx xx xx xx jjmp ; e8 xx xx xx xx call) that target outside the generated code block.
May be I'm ignorance, it seems ce has not a line assembler in Lua yet .... no, autoAssembler is! But currently the function will actually write the generated bytes to memory, so I'll suggest the autoAssemble function has a simulation mode, ie.
Code: |
autoAssemble(script,false)
-- if second parameter is 'false', the script executed and if successes, instead of writing the generated bytes to memory, it is return as a table for further manipulation. for example, it return {{address1,bytesTable1},{address2,bytesTable2},...}
|
byte~
Description: |
|
 Download |
Filename: |
miniMacro.CT |
Filesize: |
7.72 KB |
Downloaded: |
2218 Time(s) |
_________________
- Retarded. |
|