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 


Cheat Engine Forum Index
PostGo back to topic
panraven
Grandmaster Cheater
Reputation: 61
Joined: 01 Oct 2008
Posts: 958

PostPosted: Mon Dec 26, 2022 10:46 am    Post subject: Pointer Offset Resolver

In response to <How to deal with addresses with the same pointer> this extension is made.
This will resolve symbol of the form 'ofs_{some_name}' as an offset of {some_name} with respect to a [base] and associated [size] range so that
[base] <= {some_name} < [base] + [size],
given that {some_name}, [base] is already known,
if {some_name} = [base] + offset, and 0<= offset < [size], then
ofs_{some_name} = offset

Run once somewhere in your *.ct
Use update_resolver to update the defines, eg
update_resolver {PSP=1000000},
where PSP is the known base, 1000000 is the size range from the base for the offset to calc.
Code:

local base_defines, resolved, resolved_timeout = {
  PSP = 1024*1024*2 --[[2M memory]]
}, {}, {}
local ofs_prefix, default_size, default_timeout = 'ofs_', 1024, 30 --sec
if __pointer_resolve then unregisterSymbolLookupCallback(__pointer_resolve)end
__pointer_resolve = registerSymbolLookupCallback(function(sym)
  sym = sym:match('^'..ofs_prefix..'([_@#%w]+)$')
  if sym then
    local r, to = resolved[sym], resolved_timeout[sym]
    if not r or to and to > os.clock() then
      local target_addr = getAddressSafe(sym)
      if not target_addr then
        if r then resolved[sym], resolved_timeout[sym] = nil end
        return nil
      end
      for base,sz in pairs(base_defines)do
        local base_addr = getAddressSafe(base)
        if base_addr and
           target_addr >= base_addr and
           target_addr < base_addr + sz
        then
          r = target_addr - base_addr
          resolved[sym], resolved_timeout[sym] = r, os.clock()+default_timeout
          break
        end
      end
    end
    return r or nil
  end
end, slNotModule)

local function upd_tbl(t, nxt, ...)
  if type(t)~='table' or type(nxt)~='table' then return t end
  for k,v in pairs(nxt) do t[k]=v end
  return upd_tbl(t, ...)
end

function update_resolver(...)
  return upd_tbl(base_defines, ...)
end


NOTE:
1. the prefix 'ofs_' can be customized, and timeout etc;
2. symbol (and above prefix) should only contain letter,number, and symbol _ #@;
3. the 'ofs_' symbol may not be update if it has been registered;
_________________
- Retarded.
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
AylinCE
Review: Approve
Post reference:
ReviewPosted: Mon Dec 26, 2022 5:08 pm


Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites