fix dll injection and d3dhook when done from an autoattach openprocess call

make the trainer position update constantly now (every 2 seconds)
add an extra parameter to reinitializeSymbolhandler so it can run without having to wait
made the exe trainer generator detect the usage of "xmplayer." as well
This commit is contained in:
cheatengine@gmail.com 2014-05-15 16:35:59 +00:00
parent 695609ae51
commit f9f18c111e
7 changed files with 76 additions and 31 deletions

View File

@ -1101,6 +1101,10 @@ begin
try try
getprocaddressptr:=pointer(symhandler.getAddressFromName('Kernel32!GetProcAddress',true)); getprocaddressptr:=pointer(symhandler.getAddressFromName('Kernel32!GetProcAddress',true));
except except
{$ifdef cpu64}
if not processhandler.is64Bit then
raise exception.create('Dll injection failed: symbol lookup error');
{$endif}
GetProcAddressPtr:=GetProcAddress(h,'GetProcAddress'); GetProcAddressPtr:=GetProcAddress(h,'GetProcAddress');
end; end;
@ -1110,6 +1114,10 @@ begin
LoadLibraryPtr:=pointer(symhandler.getAddressFromName('Kernel32!LoadLibraryA',true)); LoadLibraryPtr:=pointer(symhandler.getAddressFromName('Kernel32!LoadLibraryA',true));
except except
//failed getting the address of LoadLibraryA, use old method //failed getting the address of LoadLibraryA, use old method
{$ifdef cpu64}
if not processhandler.is64Bit then
raise exception.create('Dll injection failed: symbol lookup error');
{$endif}
LoadLibraryPtr:=GetProcAddress(h,'LoadLibraryA'); LoadLibraryPtr:=GetProcAddress(h,'LoadLibraryA');
end; end;

View File

@ -2858,11 +2858,22 @@ begin
end; end;
function reinitializeSymbolhandler(L: PLua_state): integer; cdecl; function reinitializeSymbolhandler(L: PLua_state): integer; cdecl;
var waittilldone: boolean;
begin begin
if lua_gettop(L)>=1 then
waittilldone:=lua_toboolean(L,1)
else
waittilldone:=true;
lua_pop(L, lua_gettop(L)); lua_pop(L, lua_gettop(L));
result:=0; result:=0;
symhandler.reinitialize(true); symhandler.reinitialize(true);
if waitTillDone then
symhandler.waitforsymbolsloaded; symhandler.waitforsymbolsloaded;
end; end;
function enumModules(L:PLua_state): integer; cdecl; function enumModules(L:PLua_state): integer; cdecl;

View File

@ -106,7 +106,7 @@ enumModules(processid OPTIONAL):
getAddress(string, local OPTIONAL): returns the address of a symbol. Can be a modulename or an export. set Local to true if you wish to querry the symboltable of the ce process getAddress(string, local OPTIONAL): returns the address of a symbol. Can be a modulename or an export. set Local to true if you wish to querry the symboltable of the ce process
getModuleSize(modulename): Returns the size of a given module (Use getAddress to get the base address) getModuleSize(modulename): Returns the size of a given module (Use getAddress to get the base address)
reinitializeSymbolhandler(): reinitializes the symbolhandler. E.g when new modules have been loaded reinitializeSymbolhandler(waittilldone: BOOLEAN OPTIONAL, default=TRUE): reinitializes the symbolhandler. E.g when new modules have been loaded
reinitializeDotNetSymbolhandler(modulename OPTIONAL): Reinitializes only the DotNet part of the symbol list. (E.g After an ILCode has been JITed) (6.4+) reinitializeDotNetSymbolhandler(modulename OPTIONAL): Reinitializes only the DotNet part of the symbol list. (E.g After an ILCode has been JITed) (6.4+)
errorOnLookupFailure(state): If set to true (default) address lookups in stringform will raise an error if it can not be looked up. This includes symbolnames that are not defined and pointers that are bad. If set to false it will return 0 in those cases errorOnLookupFailure(state): If set to true (default) address lookups in stringform will raise an error if it can not be looked up. This includes symbolnames that are not defined and pointers that are bad. If set to false it will return 0 in those cases

View File

@ -366,6 +366,7 @@ type
TD3DHook=class(TObject) TD3DHook=class(TObject)
private private
hooked: boolean;
fonKeyDown: TD3DKeyDownEvent; fonKeyDown: TD3DKeyDownEvent;
fonclick: TD3DClickEvent; fonclick: TD3DClickEvent;
sharename: string; sharename: string;
@ -459,7 +460,8 @@ function safed3dhook(size: integer=16*1024*1024; hookwindow: boolean=true): TD3D
implementation implementation
uses frmautoinjectunit, autoassembler, MainUnit, frmSaveSnapshotsUnit, frmsnapshothandlerUnit; uses frmautoinjectunit, autoassembler, MainUnit, frmSaveSnapshotsUnit,
frmsnapshothandlerUnit, symbolhandler;
procedure TD3DMessageHandler.handleSnapshot; procedure TD3DMessageHandler.handleSnapshot;
begin begin
@ -1490,6 +1492,8 @@ begin
messagehandler.Free; messagehandler.Free;
end; end;
if hooked then
begin
beginCommandListUpdate; beginCommandListUpdate;
@ -1512,6 +1516,8 @@ begin
endTextureUpdate; endTextureUpdate;
end;
UnmapViewOfFile(shared); UnmapViewOfFile(shared);
closehandle(fmhandle); closehandle(fmhandle);
@ -1618,6 +1624,8 @@ begin
//now inject the dll //now inject the dll
symhandler.reinitialize;
symhandler.waitforsymbolsloaded(true, 'kernel32.dll');
if processhandler.is64Bit then if processhandler.is64Bit then
injectdll(cheatenginedir+'d3dhook64.dll') injectdll(cheatenginedir+'d3dhook64.dll')
else else
@ -1713,6 +1721,8 @@ begin
end; end;
hooked:=true;
end; end;
function safed3dhook(size: integer=16*1024*1024; hookwindow: boolean=true): TD3DHook; function safed3dhook(size: integer=16*1024*1024; hookwindow: boolean=true): TD3DHook;

View File

@ -540,7 +540,7 @@ begin
s:=lowercase(mainform.frmLuaTableScript.assemblescreen.Text); s:=lowercase(mainform.frmLuaTableScript.assemblescreen.Text);
cbSpeedhack.checked:=pos('speedhack_',s)>0; cbSpeedhack.checked:=pos('speedhack_',s)>0;
cbXMPlayer.checked:=pos('xmplayer_',s)>0; cbXMPlayer.checked:=(pos('xmplayer_',s)>0) or (pos('xmplayer.',s)>0);
cbKernelDebug.checked:=pos('dbk_',s)>0; cbKernelDebug.checked:=pos('dbk_',s)>0;
cbD3DHook.checked:=pos('created3dhook',s)>0; cbD3DHook.checked:=pos('created3dhook',s)>0;

View File

@ -2339,6 +2339,8 @@ begin
{$endif} {$endif}
//check the symbols //check the symbols
// if (symbolloaderthread<>nil) then
if (symbolloaderthread<>nil) then if (symbolloaderthread<>nil) then
begin begin

View File

@ -1157,9 +1157,17 @@ begin
if rbStopWhenAttached.checked then if rbStopWhenAttached.checked then
begin begin
l.add('function onOpenProcess(processid)');
l.add('function onOpenProcess_xmplayer(processid)');
l.add(' xmplayer.stop()'); l.add(' xmplayer.stop()');
l.add(' if xmplayer_originalOnOpenProcess~=nil then');
l.add(' xmplayer_originalOnOpenProcess(processid)');
l.add(' end'); l.add(' end');
l.add('end');
l.add('xmplayer_originalOnOpenProcess=onOpenProcess');
l.add('onOpenProcess=onOpenProcess_xmplayer');
end end
else else
begin begin
@ -1251,6 +1259,18 @@ begin
l.add('D3DHook.position=5'); l.add('D3DHook.position=5');
l.add('');
l.add('function D3DHook.UpdatePosition()');
l.add(' if D3DHook.position==2 then --Top Right');
l.add(' SetD3DMenuPosition(h.Width-BackgroundSprite.Width, 0)');
l.add(' elseif D3DHook.position==3 then --Bottom Left');
l.add(' SetD3DMenuPosition(0, h.Height-BackgroundSprite.Height)');
l.add(' elseif D3DHook.position==4 then --Bottom Right');
l.add(' SetD3DMenuPosition(h.Width-BackgroundSprite.Width, h.Height-BackgroundSprite.Height)');
l.add(' elseif D3DHook.position==5 then --Center');
l.add(' SetD3DMenuPosition((h.Width / 2)-(BackgroundSprite.Width / 2), (h.Height / 2)-(BackgroundSprite.Height/2))');
l.add(' end');
l.add('end');
l.add(''); l.add('');
l.add('function onOpenProcess()'); l.add('function onOpenProcess()');
l.add(' if (D3DHook.oldOnOpenProcess~=nil) then'); l.add(' if (D3DHook.oldOnOpenProcess~=nil) then');
@ -1381,19 +1401,13 @@ begin
l.add(''); l.add('');
l.add(' end'); //end of for loop l.add(' end'); //end of for loop
l.add(' SetD3DMenuPosition(0,0) --initialize the background sprite (Top Right)'); l.add('');
l.add(' D3DHook.UpdatePosition()');
l.add(' if D3DHook.position==2 then --Top Right'); l.add(' --create a timer to update the position');
l.add(' SetD3DMenuPosition(h.Width-BackgroundSprite.Width, 0)'); l.add(' local t=createTimer()');
l.add(' elseif D3DHook.position==3 then --Bottom Left'); l.add(' t.OnTimer=D3DHook.UpdatePosition');
l.add(' SetD3DMenuPosition(0, h.Height-BackgroundSprite.Height)'); l.add(' t.Interval=2000 --every 2 seconds');
l.add(' elseif D3DHook.position==4 then --Bottom Right'); l.add(' t.Enabled=true');
l.add(' SetD3DMenuPosition(h.Width-BackgroundSprite.Width, h.Height-BackgroundSprite.Height)');
l.add(' elseif D3DHook.position==5 then --Center');
l.add(' SetD3DMenuPosition((h.Width / 2)-(BackgroundSprite.Width / 2), (h.Height / 2)-(BackgroundSprite.Height/2))');
l.add(' end');
l.add(''); l.add('');
l.add(' if D3DHook.hasCheckbox then'); l.add(' if D3DHook.hasCheckbox then');
l.add(' h.OnClick=D3DHookSpriteClick'); l.add(' h.OnClick=D3DHookSpriteClick');