Skip to content

Commit

Permalink
Merge pull request cheat-engine#121 from mgrinzPlayer/fix-GetAddressF…
Browse files Browse the repository at this point in the history
…romPointer-for-selfsymhandler

fix GetAddressFromPointer for selfsymhandler
  • Loading branch information
cheat-engine authored Nov 13, 2016
2 parents d0966e8 + f761458 commit 2907355
Showing 1 changed file with 16 additions and 54 deletions.
70 changes: 16 additions & 54 deletions Cheat Engine/symbolhandler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,6 @@ function ES2(pSymInfo:PSYMBOL_INFO; SymbolSize:ULONG; UserContext:pointer):BOOL;
s: string;
self: TSymbolloaderthread;

x: DWORD;
type_symtag: Tsymtagenum;

isparam: boolean;

esde: TExtraSymbolDataEntry;
Expand Down Expand Up @@ -815,12 +812,6 @@ function ES(pSymInfo:PSYMBOL_INFO; SymbolSize:ULONG; UserContext:pointer):BOOL;s
s: string;
sym: PCESymbolInfo;

tempstring: pchar;
x: dword;
i: integer;

pSymInfo2:PSYMBOL_INFO;

ExtraSymbolData: TExtraSymbolData;
begin

Expand Down Expand Up @@ -870,8 +861,6 @@ function ET(pSymInfo:PSYMBOL_INFO; SymbolSize:ULONG; UserContext:pointer):BOOL;s
result:=true;
end;

var test: boolean;

function EM(ModuleName:PSTR; BaseOfDll:dword64; UserContext:pointer):bool;stdcall;
var self: TSymbolloaderthread;
mi: tmoduleinfo;
Expand Down Expand Up @@ -932,16 +921,10 @@ TModInfo=record
c: TCEConnection;

mpl: Tstringlist;
i,j,k,l,m: integer;
i,j: integer;

dotNetdomains: TDotNetDomainArray;
dotNetmodules: TDotNetModuleArray;
dotnettypedefs: TDotNetTypeDefArray;
dotnetmethods: TDotNetMethodArray;

address:qword;
size: integer;
name: string;



Expand Down Expand Up @@ -1512,7 +1495,6 @@ procedure TSymhandler.reinitialize(force: boolean=false);
end;

procedure TSymhandler.Waitforsymbolsloaded(apisymbolsonly: boolean=false; specificmodule: string='');
var checkcondition: pboolean;
begin
symbolloadervalid.beginread;

Expand Down Expand Up @@ -2121,24 +2103,10 @@ function TSymhandler.getExtraDataFromSymbolAtAddress(address: ptruint): TExtraSy
function TSymhandler.getNameFromAddress(address:ptrUint;symbols:boolean; modules: boolean; baseaddress: PUINT64=nil; found: PBoolean=nil; hexcharsize: integer=8):string;
var //symbol :PSYMBOL_INFO;
offset: qword;
s: string;
mi: tmoduleinfo;
si: PCESymbolInfo;
processhandle: thandle;
i: integer;
begin
{$ifdef windows}
if targetself then
begin
processhandle:=getcurrentprocess;
end
else
{$endif}
begin
processhandle:=processhandlerunit.ProcessHandle;
end;


for i:=0 to length(AddressLookupCallbacks)-1 do
begin
if assigned(AddressLookupCallbacks[i]) then
Expand Down Expand Up @@ -2335,14 +2303,9 @@ function TSymhandler.getAddressFromName(name: string; waitforsymbols: boolean; o
offset: integer;
i,j: integer;

slcindex: integer;

p: pchar;
ws: widestring;
pws: pwidechar;
error: boolean;

processhandle: thandle;

tokens: TTokens;
mathstring: string;
Expand Down Expand Up @@ -2421,19 +2384,6 @@ function TSymhandler.getAddressFromName(name: string; waitforsymbols: boolean; o
end;
end;

{$ifdef windows}
if targetself then
begin
processhandle:=getcurrentprocess;
end
else
{$endif}
begin
processhandle:=processhandlerunit.ProcessHandle;
end;



val('$'+name,result,i);
if i=0 then exit; //it's a valid hexadecimal string

Expand Down Expand Up @@ -3040,18 +2990,30 @@ function TSymhandler.GetAddressFromPointer(s: string; var error: boolean):ptrUin
Will return the address of a pointer noted as [[[xxx+xx]+xx]+xx]+xx
If it is a invalid pointer, or can not be resolved, the result is NULL
}
var i: integer;
var i, pointersize: integer;
list: tstringlist;
offsets: array of integer;
baseaddress: ptruint;
off: string;
realaddress, realaddress2: ptrUint;
check: boolean;
count: PtrUInt;
processhandle: THandle;
begin
result:=0;
error:=true;

if not targetself then
begin
processhandle:=processhandlerunit.processhandle;
pointersize:=processhandler.pointersize;
end
else
begin
processhandle:=GetCurrentProcess;
pointersize:={$ifdef cpu32}4{$else}8{$endif};
end;

list:=tstringlist.create;
try
if not ParseAsPointer(s,list) then exit;
Expand Down Expand Up @@ -3081,8 +3043,8 @@ function TSymhandler.GetAddressFromPointer(s: string; var error: boolean):ptrUin
for i:=0 to length(offsets)-1 do
begin
realaddress:=0;
check:=readprocessmemory(processhandle,pointer(realaddress2),@realaddress,processhandler.pointersize,count);
if check and (count=processhandler.pointersize) then
check:=readprocessmemory(processhandle,pointer(realaddress2),@realaddress,pointersize,count);
if check and (count=pointersize) then
realaddress2:=realaddress+offsets[i]
else
exit;
Expand Down

0 comments on commit 2907355

Please sign in to comment.