Update DDetours sources to latest (2021-01-01)

This commit is contained in:
Ansgar Becker
2022-12-31 18:29:54 +01:00
parent 7fc5f3bf07
commit 8abb5dbfba
3 changed files with 104 additions and 103 deletions

View File

@ -1,57 +1,57 @@
# Uncomment these types if you want even more clean repository. But be careful. # Uncomment these types if you want even more clean repository. But be careful.
# It can make harm to an existing project source. Read explanations below. # It can make harm to an existing project source. Read explanations below.
# #
# Resource files are binaries containing manifest, project icon and version info. # Resource files are binaries containing manifest, project icon and version info.
# They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
*.res *.res
# #
# Type library file (binary). In old Delphi versions it should be stored. # Type library file (binary). In old Delphi versions it should be stored.
# Since Delphi 2009 it is produced from .ridl file and can safely be ignored. # Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
#*.tlb #*.tlb
# #
# Diagram Portfolio file. Used by the diagram editor up to Delphi 7. # Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
# Uncomment this if you are not using diagrams or use newer Delphi version. # Uncomment this if you are not using diagrams or use newer Delphi version.
#*.ddp #*.ddp
# #
# Visual LiveBindings file. Added in Delphi XE2. # Visual LiveBindings file. Added in Delphi XE2.
# Uncomment this if you are not using LiveBindings Designer. # Uncomment this if you are not using LiveBindings Designer.
#*.vlb #*.vlb
# #
# Deployment Manager configuration file for your project. Added in Delphi XE2. # Deployment Manager configuration file for your project. Added in Delphi XE2.
# Uncomment this if it is not mobile development and you do not use remote debug feature. # Uncomment this if it is not mobile development and you do not use remote debug feature.
#*.deployproj #*.deployproj
# #
# Delphi compiler-generated binaries (safe to delete) # Delphi compiler-generated binaries (safe to delete)
#*.exe #*.exe
*.dll *.dll
*.bpl *.bpl
*.bpi *.bpi
*.dcp *.dcp
*.so *.so
*.apk *.apk
*.drc *.drc
*.map *.map
*.dres *.dres
*.rsm *.rsm
*.tds *.tds
*.dcu *.dcu
*.lib *.lib
# Delphi autogenerated files (duplicated info) # Delphi autogenerated files (duplicated info)
*.cfg *.cfg
*Resource.rc *Resource.rc
# Delphi local files (user-specific info) # Delphi local files (user-specific info)
*.local *.local
*.identcache *.identcache
*.projdata *.projdata
*.tvsconfig *.tvsconfig
*.dsk *.dsk
# Delphi history and backups # Delphi history and backups
__history/ __history/
*.~* *.~*
# Castalia statistics file # Castalia statistics file
*.stat *.stat

View File

@ -1,35 +1,35 @@
rem ***************************************** rem *****************************************
rem * Delphi CleanUp Batch. * rem * Delphi CleanUp Batch. *
rem * * rem * *
rem * Clean identcache,local,dcu,exe, * rem * Clean identcache,local,dcu,exe, *
rem * map,drc files. * rem * map,drc files. *
rem * Clean hidden __history folder. * rem * Clean hidden __history folder. *
rem * * rem * *
rem * Author: Mahdi Safsafi * rem * Author: Mahdi Safsafi *
rem ***************************************** rem *****************************************
@echo off @echo off
Setlocal EnableDelayedExpansion Setlocal EnableDelayedExpansion
Del "*.identcache" /s/q Del "*.identcache" /s/q
Del "*.local" /s/q Del "*.local" /s/q
Del "*.dcu" /s/q Del "*.dcu" /s/q
Del "*.exe" /s/q Del "*.exe" /s/q
Del "*.drc" /s/q Del "*.drc" /s/q
Del "*.map" /s/q Del "*.map" /s/q
set mustdel=false set mustdel=false
For /r %%f in (.) do ( For /r %%f in (.) do (
set "mustdel=false" set "mustdel=false"
if %%~nf==Win32 ( if %%~nf==Win32 (
if exist "%%~ff\Debug\" set "mustdel=true" if exist "%%~ff\Debug\" set "mustdel=true"
if exist "%%~ff\Release\" set "mustdel=true" if exist "%%~ff\Release\" set "mustdel=true"
) else if %%~nf==Win64 ( ) else if %%~nf==Win64 (
if exist "%%~ff\Debug\" set "mustdel=true" if exist "%%~ff\Debug\" set "mustdel=true"
if exist "%%~ff\Release\" set "mustdel=true" if exist "%%~ff\Release\" set "mustdel=true"
) )
if %%~nf==__history set "mustdel=true" if %%~nf==__history set "mustdel=true"
if !mustdel!==true ( if !mustdel!==true (
if exist "%%~ff" rd /s/q "%%~ff" if exist "%%~ff" rd /s/q "%%~ff"
) )
) )

View File

@ -17,6 +17,7 @@ unit DDetours;
{define FIX_MADEXCEPT if you are using crash on buffer overrun/underrun feature from MadExcept } {define FIX_MADEXCEPT if you are using crash on buffer overrun/underrun feature from MadExcept }
{.$DEFINE FIX_MADEXCEPT} {.$DEFINE FIX_MADEXCEPT}
{.$define DEVMODE}
{$IFDEF FPC} {$IFDEF FPC}
{$MODE DELPHI} {$MODE DELPHI}
@ -591,7 +592,7 @@ begin
{$IFDEF CPUX64} {$IFDEF CPUX64}
IsNxtInstData := ((PInst^.Disp.Flags and (dfUsed or dfRip) = (dfUsed or dfRip)) and (PInst^.Disp.Value = 0)); IsNxtInstData := ((PInst^.Disp.Flags and (dfUsed or dfRip) = (dfUsed or dfRip)) and (PInst^.Disp.Value = 0));
{$ELSE !CPUX64} {$ELSE !CPUX64}
IsNxtInstData := (PInst^.Disp.Value = UInt64(PInst^.NextInst)); IsNxtInstData := (PInst^.Disp.Value = Int64(PInst^.NextInst));
{$ENDIF CPUX64} {$ENDIF CPUX64}
if IsNxtInstData then if IsNxtInstData then
begin begin
@ -1037,7 +1038,7 @@ begin
GetMem(POpc, MAX_INST_LENGTH_N + 1); GetMem(POpc, MAX_INST_LENGTH_N + 1);
try try
// Opcsz := GetInstOpCodes(PInst, POpc); // Opcsz := GetInstOpCodes(PInst, POpc);
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 6); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 6);
Relsz := GetInt64Size(Offset); Relsz := GetInt64Size(Offset);
{$IFDEF CPUX64} {$IFDEF CPUX64}
if Relsz = ops16bits then if Relsz = ops16bits then
@ -1110,7 +1111,7 @@ begin
case Relsz of case Relsz of
ops16bits: ops16bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 5); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 5);
PQ^ := opPrfOpSize; PQ^ := opPrfOpSize;
Inc(PQ); Inc(PQ);
PWord(PQ)^ := LOOP_To_JccZ[PInst^.OpCode and 3]; PWord(PQ)^ := LOOP_To_JccZ[PInst^.OpCode and 3];
@ -1120,7 +1121,7 @@ begin
end; end;
ops32bits: ops32bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 6); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 6);
PWord(PQ)^ := LOOP_To_JccZ[PInst^.OpCode and 3]; PWord(PQ)^ := LOOP_To_JccZ[PInst^.OpCode and 3];
Inc(PQ, 2); Inc(PQ, 2);
PInt32(PQ)^ := Int32(Offset); PInt32(PQ)^ := Int32(Offset);
@ -1204,7 +1205,7 @@ begin
TEST CX,CX TEST CX,CX
JZ @Dst JZ @Dst
} }
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 5); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 5);
PQ^ := opPrfOpSize; PQ^ := opPrfOpSize;
Inc(PQ); Inc(PQ);
PQ^ := $0F; PQ^ := $0F;
@ -1220,7 +1221,7 @@ begin
TEST ECX,ECX TEST ECX,ECX
JZ @Dst JZ @Dst
} }
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 6); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 6);
PQ^ := $0F; PQ^ := $0F;
Inc(PQ); Inc(PQ);
PQ^ := $84; // JZ ! PQ^ := $84; // JZ !
@ -1261,7 +1262,7 @@ begin
case Relsz of case Relsz of
ops8bits: ops8bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 2); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 2);
PInt8(PQ)^ := UInt8(NOpc); PInt8(PQ)^ := UInt8(NOpc);
Inc(PQ); Inc(PQ);
PInt8(PQ)^ := Int8(Offset); PInt8(PQ)^ := Int8(Offset);
@ -1269,7 +1270,7 @@ begin
end; end;
ops16bits: ops16bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 5); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 5);
PUInt32(PQ)^ := UInt32(NOpc); PUInt32(PQ)^ := UInt32(NOpc);
Inc(PQ, 3); Inc(PQ, 3);
PInt16(PQ)^ := Int16(Offset); PInt16(PQ)^ := Int16(Offset);
@ -1277,7 +1278,7 @@ begin
end; end;
ops32bits: ops32bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(PQ) - 6); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(PQ) - 6);
PUInt16(PQ)^ := UInt16(NOpc); PUInt16(PQ)^ := UInt16(NOpc);
Inc(PQ, 2); Inc(PQ, 2);
PInt32(PQ)^ := Int32(Offset); PInt32(PQ)^ := Int32(Offset);
@ -1435,7 +1436,7 @@ var
P: PByte; P: PByte;
begin begin
P := NewAddr; P := NewAddr;
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(P) - 6); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(P) - 6);
Relsz := GetInt64Size(Offset); Relsz := GetInt64Size(Offset);
{$IFDEF CPUX64} {$IFDEF CPUX64}
{ Only 32-bits relative offset is supported on x64! } { Only 32-bits relative offset is supported on x64! }
@ -1449,7 +1450,7 @@ begin
case Relsz of case Relsz of
ops16bits: ops16bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(P) - 4); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(P) - 4);
P^ := opPrfOpSize; P^ := opPrfOpSize;
Inc(P); Inc(P);
P^ := $E8; P^ := $E8;
@ -1459,7 +1460,7 @@ begin
end; end;
ops32bits: ops32bits:
begin begin
Offset := Int64(UInt64(PInst^.Branch.Target) - UInt64(P) - 5); Offset := Int64(Int64(PInst^.Branch.Target) - Int64(P) - 5);
P^ := $E8; P^ := $E8;
Inc(P); Inc(P);
PInt32(P)^ := Int32(Offset); PInt32(P)^ := Int32(Offset);