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 


mini AA Macro

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting -> Lua Extensions
View previous topic :: View next topic  
Author Message
panraven
Grandmaster Cheater
Reputation: 24

Joined: 01 Oct 2008
Posts: 627

PostPosted: Fri Mar 04, 2016 4:02 pm    Post subject: mini AA Macro Reply with quote

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~



miniMacro.CT
 Description:

Download
 Filename:  miniMacro.CT
 Filesize:  7.72 KB
 Downloaded:  391 Time(s)


_________________
- Retarded.
dropbox
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 -> Lua Extensions 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