panraven Grandmaster Cheater Reputation: 59
Joined: 01 Oct 2008 Posts: 957
|
Posted: 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;
Description: |
|
Filesize: |
32.48 KB |
Viewed: |
9400 Time(s) |
|
_________________
- Retarded. |
|