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 


Suggestion: AA for variable values?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
jgoemat
Master Cheater
Reputation: 23

Joined: 25 Sep 2011
Posts: 264

PostPosted: Sat Feb 06, 2021 4:36 pm    Post subject: Suggestion: AA for variable values? Reply with quote

I've been having to deal with some code that changes occasionally. Working on my MonoHelper that generates scripts, it uses the exact bytes at the time of generation to create a script that doesn't require any extra lua. Sometimes a value might change occasionally like the amount of stack reserved at the start of a function I hook. Here's an example where the 'sub rsp,30' might be 'sub rsp,38' due to JIT differences without any other meaningful change:

Code:
define(hook,"XUiM_Recipes:GetRecipeIsUnlocked")
define(bytes,55 48 8B EC 48 83 EC 30 01 00 00)

[enable]

assert(hook, bytes)
alloc(newmem,$1000, hook)
{
  RCX: XUiM_Recipes (this)
  RDX: XUi xui
  R8: Recipe _recipe

  Returns (RAX) System.Boolean
}

newmem:
  mov al,1
  ret //  return true

  // original code
  push rbp
  mov rbp,rsp
  sub rsp,130
  jmp hook+b

hook:
  jmp newmem

[disable]

hook:
  db bytes

dealloc(newmem)


As a work-around I can edit the script to use readmem and create a symbol for the relocated code (or guess I could maybe use globalalloc), but it makes the code uglier:

Code:
define(hook,"XUiM_Recipes:GetRecipeIsUnlocked")
define(bytes,55 48 8B EC 48 83 EC * * 00 00)

[enable]

assert(hook, bytes)
alloc(newmem,$1000, hook)
alloc(relocated_XUiM_Recipes_GetRecipeIsUnlocked)

{
  RCX: XUiM_Recipes (this)
  RDX: XUi xui
  R8: Recipe _recipe

  Returns (RAX) System.Boolean
}

newmem:
  mov al,1
  ret //  return true

  // original code
relocated_XUiM_Recipes_GetRecipeIsUnlocked:
  readmem(hook,$b)
  jmp hook+b

hook:
  jmp newmem

registersymbol(relocated_XUiM_Recipes_GetRecipeIsUnlocked)

[disable]

hook:
  readmem(relocated_XUiM_Recipes_GetRecipeIsUnlocked,$b)

unregistersymbol(relocated_XUiM_Recipes_GetRecipeIsUnlocked)
dealloc(newmem)


Part of the problem is defining a symbol name that will be unique across scripts, and cluttering up the user-defined symbols. I notice that 'newmem' doesn't need to be defined as a symbol to be deallocated at least in the disable section but I don't know how CE does that or if it is just kept in a special list. It would be nice if any label created in the `[enable]` section could be used in the `[disable]` section. That would allow script-local variables so it could be renamed 'relocatedCode' or something, the same name could be used in different scripts, and it wouldn't have to do the symbol registering.

I realize that in this instance the jmp doesn't actually overwrite the '30 01 00 00' so I could use a smaller bytes AOB and just do the readmem in the source, but something generic for generating AA scripts when that isn't the case would be nice...
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25804
Location: The netherlands

PostPosted: Mon Feb 08, 2021 4:27 pm    Post subject: This post has 1 review(s) Reply with quote

ok, disable can now access symbols created in the enable section
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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