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 


Pointer Offset Resolver

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

Joined: 01 Oct 2008
Posts: 957

PostPosted: Mon Dec 26, 2022 10:46 am    Post subject: Pointer Offset Resolver This post has 1 review(s) Reply with quote

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;



ce_pointer_ofs_resolve.jpg
 Description:
 Filesize:  32.48 KB
 Viewed:  9400 Time(s)

ce_pointer_ofs_resolve.jpg



_________________
- Retarded.
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 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