Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Migration of some methods to new Delphi Tokio 10.2.3 #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ obj/
*.lib
*.identcache
*.local
libs/*
bin/*
*.ico
*.stat
*.map
*.otares
*.res
*.dproj
21 changes: 11 additions & 10 deletions libs/common/uDebugUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
PsApi,
SysUtils,
TlHelp32,
Windows;
Winapi.Windows;

function GetModuleCodeBase(AProcess: THandle; AModuleAsPtr: Pointer; out ACodeBase: DWORD): Boolean;
function GetModuleHeader(AProcess: THandle; AModuleAsPtr: Pointer; AImageNTHeaders: PImageNtHeaders): Boolean;
Expand All @@ -17,17 +17,18 @@ function GetProcessModuleFileName(AProcess: THandle; AFile: THandle): String;
function GetProcessModuleFileNameEx(APID: DWORD; const AModuleName: String): String;
function GetProcessModuleName(AProcess: THandle; AModuleAsPtr: Pointer): String;
function GetThreadHandleByID(AThreadId: DWORD): THandle;
function ReadProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: DWORD): Boolean;
function ReadProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: SIZE_T): BOOL;
function SearchModulePath(const AModuleName: String): String;
function WriteProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: DWORD): Boolean;
function WriteProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: SIZE_T): Boolean;

implementation

function ReadProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: DWORD): Boolean;
function ReadProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: SIZE_T): BOOL;

var
dwRead : DWORD;
dwRead : SIZE_T;
begin
Result := ReadProcessMemory(
Result := Winapi.Windows.ReadProcessMemory(
AProcess,
AProcMem,
ALocalMem,
Expand Down Expand Up @@ -67,7 +68,7 @@ function GetProcessModuleName(AProcess: THandle; AModuleAsPtr: Pointer): String;
then begin
SetLength(Str, 64);
if ReadProcMem(AProcess, Pointer(DWORD(AModuleAsPtr) + IED.Name), @Str[1], 64) then
Result := StrPas(PChar(Str));
Result := StrPas(PAnsiChar(Str));
end;
end;
end;
Expand Down Expand Up @@ -170,7 +171,7 @@ function GetProcessModuleFileName(AProcess: THandle; AFile: THandle): String;
repeat
{ Copy the drive letter to the template string }

Byte(szDrive[0]) := lpTemp^;
szDrive[0] := Char(lpTemp^);

{ Look up each device name }

Expand Down Expand Up @@ -269,9 +270,9 @@ function GetProcessModuleFileNameEx(APID: DWORD; const AModuleName: String): Str
CloseHandle(hSnap);
end;

function WriteProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: DWORD): Boolean;
function WriteProcMem(AProcess: THandle; AProcMem, ALocalMem: Pointer; ASize: SIZE_T): Boolean;
var
dwWrote : DWORD;
dwWrote : SIZE_T;
begin
Result := WriteProcessMemory(
AProcess,
Expand Down
2 changes: 1 addition & 1 deletion libs/common/uLog.pas
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ procedure TLogFile.DestroyMutex;

class function TLogFile.GetLogDateTime: String;
begin
Result := FormatDateTime('DD/MM/YYYY HH:NN:SS', Now);
Result := FormatDateTime('DD/MM/YYYY HH:NN:SS:zzz', Now);
end;

class function TLogFile.GetModuleFileName: String;
Expand Down
7 changes: 5 additions & 2 deletions libs/common/uUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
Controls,
Dialogs,
hUtils,
SysUtils,
System.SysUtils,
Windows;

function AreYouSure: Boolean;
Expand All @@ -19,6 +19,9 @@ function IsOsWin32: Boolean;

implementation

uses
AnsiStrings, System.UITypes;

function GetAppVersionInfo(var AFileVErsionInfo: TFileVersionInfo; AAppNamePath: String): Boolean;
var
VerBuf : PChar;
Expand All @@ -38,7 +41,7 @@ function GetAppVersionInfo(var AFileVErsionInfo: TFileVersionInfo; AAppNamePath:
;

if VerQueryValue(VerBuf, PChar(VerKey), VerBufValue, VerBufLen) then
Result := StrPas(VerBufValue);
Result := AnsiStrings.StrPas(PAnsiChar(VerBufValue));
end;

function QueryValue(const AValue: String): String;
Expand Down
2 changes: 2 additions & 0 deletions src/BfCfgWiz/BfCfgWiz.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<DCC_DcuOutput>..\..\dcu</DCC_DcuOutput>
<DCC_ObjOutput>..\..\dcu</DCC_ObjOutput>
<DCC_HppOutput>..\..\dcu</DCC_HppOutput>
<DCC_UnitSearchPath>..\..\dcu;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Define>RELEASE</DCC_Define>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -33,6 +34,7 @@
<DCC_DcuOutput>..\..\dcu</DCC_DcuOutput>
<DCC_ObjOutput>..\..\dcu</DCC_ObjOutput>
<DCC_HppOutput>..\..\dcu</DCC_HppOutput>
<DCC_UnitSearchPath>..\..\dcu;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Define>DEBUG</DCC_Define>
</PropertyGroup>
<ProjectExtensions>
Expand Down
1 change: 1 addition & 0 deletions src/BfCfgWiz/ufmBfCfgWiz.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface
Mask,
Messages,
StdCtrls,
System.Actions,
SysUtils,
uLog,
uLogRotator,
Expand Down
2 changes: 1 addition & 1 deletion src/BfConfig/BfConfig.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ uses

begin
Application.Initialize;
Configure(0, 0, PChar(ParamStr(1)), 0);
Configure(0, 0, PAnsiChar(ParamStr(1)), 0);
end.
3 changes: 2 additions & 1 deletion src/BugFinder/BugFinder.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ uses
hBfCfgWiz in '..\intf\hBfCfgWiz.pas',
hStackWalk in 'hStackWalk.pas',
hDebugUtils in '..\..\libs\common\hDebugUtils.pas',
uDebugUtils in '..\..\libs\common\uDebugUtils.pas';
uDebugUtils in '..\..\libs\common\uDebugUtils.pas',
uDebugThread in 'uDebugThread.pas';

begin
Application.Initialize;
Expand Down
10 changes: 3 additions & 7 deletions src/BugFinder/BugFinder.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<DCC_DcuOutput>..\..\dcu</DCC_DcuOutput>
<DCC_ObjOutput>..\..\dcu</DCC_ObjOutput>
<DCC_HppOutput>..\..\dcu</DCC_HppOutput>
<DCC_UnitSearchPath>..\..\dcu;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Define>RELEASE</DCC_Define>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -33,20 +34,15 @@
<DCC_DcuOutput>..\..\dcu</DCC_DcuOutput>
<DCC_ObjOutput>..\..\dcu</DCC_ObjOutput>
<DCC_HppOutput>..\..\dcu</DCC_HppOutput>
<DCC_UnitSearchPath>..\..\dcu;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_Define>DEBUG</DCC_Define>
<DCC_Optimize>False</DCC_Optimize>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality</Borland.Personality>
<Borland.ProjectType>VCLApplication</Borland.ProjectType>
<BorlandProject>
<BorlandProject><Delphi.Personality><Parameters><Parameters Name="UseLauncher">False</Parameters><Parameters Name="LoadAllSymbols">True</Parameters><Parameters Name="LoadUnspecifiedSymbols">False</Parameters><Parameters Name="RunParams">BugFinder.ini</Parameters></Parameters><VersionInfo><VersionInfo Name="IncludeVerInfo">True</VersionInfo><VersionInfo Name="AutoIncBuild">True</VersionInfo><VersionInfo Name="MajorVer">1</VersionInfo><VersionInfo Name="MinorVer">2</VersionInfo><VersionInfo Name="Release">0</VersionInfo><VersionInfo Name="Build">49</VersionInfo><VersionInfo Name="Debug">False</VersionInfo><VersionInfo Name="PreRelease">False</VersionInfo><VersionInfo Name="Special">False</VersionInfo><VersionInfo Name="Private">False</VersionInfo><VersionInfo Name="DLL">False</VersionInfo><VersionInfo Name="Locale">1040</VersionInfo><VersionInfo Name="CodePage">1252</VersionInfo></VersionInfo><VersionInfoKeys><VersionInfoKeys Name="CompanyName">Antonio Petricca</VersionInfoKeys><VersionInfoKeys Name="FileDescription">[email protected]</VersionInfoKeys><VersionInfoKeys Name="FileVersion">1.2.0.49</VersionInfoKeys><VersionInfoKeys Name="InternalName"></VersionInfoKeys><VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys><VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys><VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys><VersionInfoKeys Name="ProductName">Bug Finder</VersionInfoKeys><VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys><VersionInfoKeys Name="Comments"></VersionInfoKeys></VersionInfoKeys><Source><Source Name="MainSource">BugFinder.dpr</Source></Source><Excluded_Packages>






<BorlandProject><Delphi.Personality><Parameters><Parameters Name="UseLauncher">False</Parameters><Parameters Name="LoadAllSymbols">True</Parameters><Parameters Name="LoadUnspecifiedSymbols">False</Parameters><Parameters Name="RunParams">BugFinder.ini</Parameters></Parameters><VersionInfo><VersionInfo Name="IncludeVerInfo">True</VersionInfo><VersionInfo Name="AutoIncBuild">True</VersionInfo><VersionInfo Name="MajorVer">1</VersionInfo><VersionInfo Name="MinorVer">2</VersionInfo><VersionInfo Name="Release">0</VersionInfo><VersionInfo Name="Build">49</VersionInfo><VersionInfo Name="Debug">False</VersionInfo><VersionInfo Name="PreRelease">False</VersionInfo><VersionInfo Name="Special">False</VersionInfo><VersionInfo Name="Private">False</VersionInfo><VersionInfo Name="DLL">False</VersionInfo><VersionInfo Name="Locale">1040</VersionInfo><VersionInfo Name="CodePage">1252</VersionInfo></VersionInfo><VersionInfoKeys><VersionInfoKeys Name="CompanyName">Antonio Petricca</VersionInfoKeys><VersionInfoKeys Name="FileDescription">[email protected]</VersionInfoKeys><VersionInfoKeys Name="FileVersion">1.2.0.49</VersionInfoKeys><VersionInfoKeys Name="InternalName"></VersionInfoKeys><VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys><VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys><VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys><VersionInfoKeys Name="ProductName">Bug Finder</VersionInfoKeys><VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys><VersionInfoKeys Name="Comments"></VersionInfoKeys></VersionInfoKeys><Source><Source Name="MainSource">BugFinder.dpr</Source></Source><Excluded_Packages>
<Excluded_Packages Name="$(BDS)\bin\dcloffice2k100.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDS)\bin\dclofficexp100.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages></Delphi.Personality></BorlandProject></BorlandProject>
Expand Down
20 changes: 18 additions & 2 deletions src/BugFinder/uBreakpoints.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface
TBreakpoint = class(TObject)
private
FAddress : DWORD;
FDebugStart: DWORD;
FDebugEnd : DWORD;
FSize : DWORD;
FByteData : Byte;
FMethod : String;
FModule : String;
Expand All @@ -33,11 +36,14 @@ TBreakpoint = class(TObject)
function Activate(AProcess: THandle): Boolean;
function Resume(AThreadId: THandle): Boolean;

property Address : DWORD read FAddress;
property Address : DWORD read FAddress write FAddress;
property Method : String read FMethod;
property Module : String read FModule;
property Name : String read FName;
property UnitName : String read FUnitName;
property DebugStart: DWORD read FDebugStart write FDebugStart;
property DebugEnd : DWORD read FDebugEnd write FDebugEnd;
property Size : DWORD read FSize write FSize;

property ByteData : Byte read FByteData;
end;
Expand Down Expand Up @@ -164,16 +170,26 @@ function TBreakPoints.Find(AAddress: DWORD): TBreakpoint;
function TBreakPoints.ValidateBP(const ASymProvider: ISymbolProvider; const AName, AModule, AUnit, AMethod: String; AModuleCodeBase: DWORD): TBreakpoint;
var
Address : DWORD;
Size: DWORD;
DebugStart: DWORD;
DebugEnd: DWORD;
begin
if not Assigned(ASymProvider) then
Address := 0
else
ASymProvider.QueryAddress(PChar(AUnit), PChar(AMethod), AModuleCodeBase, Address);
begin
ASymProvider.QuerySymbolProps(PChar(AUnit), PChar(AMethod), AModuleCodeBase, Address, Size, DebugStart, DebugEnd);
end;

if (Address <= 0) then
Result := nil
else
begin
Result := TBreakpoint.Create(FThreads, AName, AModule, AUnit, AMethod, Address);
Result.Size := Size;
Result.DebugStart := DebugStart;
Result.DebugEnd := DebugEnd;
end;
end;


Expand Down
115 changes: 115 additions & 0 deletions src/BugFinder/uDebugThread.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
unit uDebugThread;

interface

uses
Classes,
SysUtils,
hCore,
uCore;

type
TDebugThread = class(TThread)
private
FCore : TBugFinderCore;
FErrorStatus : Boolean;
FIsError : Boolean;
FLogEvent : TLogEvent;
FMessage : String;

procedure DoInternalLog;
procedure DoSyncLog(ASender: TObject; const AMsg: String; AIsError: Boolean);
function GetIsRunning: Boolean;
protected
procedure Execute; override;
public
constructor Create(ALogEvent: TLogEvent; AOnTerminate: TNotifyEvent); reintroduce;
destructor Destroy; override;

procedure Start;
procedure Stop;

property Core : TBugFinderCore read FCore;

property ErrorStatus : Boolean read FErrorStatus;
property IsRunning : Boolean read GetIsRunning;
end;

implementation

uses
Forms;

{ TDebugThread }

constructor TDebugThread.Create(ALogEvent: TLogEvent; AOnTerminate: TNotifyEvent);
var
IniFileName : String;
IniFilePath : String;
begin
inherited Create(True);

IniFileName := Trim(ParamStr(1));
IniFilePath := ExtractFilePath(IniFileName);

if (IniFilePath = '') then
IniFileName := Format('.\%s', [IniFileName]);

FCore := TBugFinderCore.Create(IniFileName);
FCore.LogEvent := DoSyncLog;

FErrorStatus := False;
FLogEvent := ALogEvent;

OnTerminate := AOnTerminate;
end;

destructor TDebugThread.Destroy;
begin
FreeAndNil(FCore);

inherited Destroy;
end;

procedure TDebugThread.DoInternalLog;
begin
FLogEvent(Self, FMessage, FIsError);
end;

procedure TDebugThread.DoSyncLog(ASender: TObject; const AMsg: String; AIsError: Boolean);
begin
FIsError := AIsError;
FMessage := AMsg;

Synchronize(DoInternalLog);
end;

procedure TDebugThread.Execute;
begin
FErrorStatus := not FCore.Run;
end;

function TDebugThread.GetIsRunning: Boolean;
begin
Result := not FCore.Stopped;
end;

procedure TDebugThread.Start;
begin
Resume;
end;

procedure TDebugThread.Stop;
begin
with FCore do begin
Terminate;

while not Stopped do
Application.ProcessMessages;
end;

WaitFor;
end;


end.
3 changes: 3 additions & 0 deletions src/BugFinder/uExcProviders.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ TExceptionProviders = class(TObject)

implementation

uses
System.Classes;

{ TExceptionProviderItem }

constructor TExceptionProviderItem.Create(AHandle: THandle; const AName, AFileName: String; AFactory: TGetExceptionProviderFunc);
Expand Down
Loading