-
Notifications
You must be signed in to change notification settings - Fork 51
/
DbgHookCS.pas
62 lines (46 loc) · 1.08 KB
/
DbgHookCS.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
unit DbgHookCS;
interface
uses Windows;
type
TDbgCriticalSection = class
private
FLock: TRTLCriticalSection;
public
constructor Create;
destructor Destroy; override;
procedure Enter;
procedure Leave;
function TryEnter: LongBool;
end;
implementation
uses DbgHookSyncObjs;
{ TDbgCriticalSection }
constructor TDbgCriticalSection.Create;
begin
inherited;
InitializeCriticalSection(FLock);
end;
destructor TDbgCriticalSection.Destroy;
begin
DeleteCriticalSection(FLock);
inherited;
end;
procedure TDbgCriticalSection.Enter;
begin
if SyncObjsHooked and Assigned(Kernel32_EnterCriticalSection) then
Kernel32_EnterCriticalSection(FLock)
else
EnterCriticalSection(FLock);
end;
procedure TDbgCriticalSection.Leave;
begin
if SyncObjsHooked and Assigned(Kernel32_LeaveCriticalSection) then
Kernel32_LeaveCriticalSection(FLock)
else
LeaveCriticalSection(FLock);
end;
function TDbgCriticalSection.TryEnter: LongBool;
begin
Result := TryEnterCriticalSection(FLock);
end;
end.