-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathNtUtils.Lpc.pas
More file actions
121 lines (97 loc) · 2.99 KB
/
NtUtils.Lpc.pas
File metadata and controls
121 lines (97 loc) · 2.99 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
unit NtUtils.Lpc;
{
This module providers wrappers for using LPC/ALPC (local inter-process
communication).
}
interface
uses
Ntapi.WinNt, Ntapi.ntdef, Ntapi.ntlpcapi, NtUtils, DelphiApi.Reflection;
// Connect to an LPC port
function NtxConnectPort(
out hxPort: IHandle;
const PortName: String;
ImpersonationLevel: TSecurityImpersonationLevel = SecurityImpersonation;
ContextTrackingMode: Boolean = False;
EffectiveOnly: Boolean = False
): TNtxStatus;
// Send a message to an LPC port
function NtxRequestWaitReplyPort(
const hxPort: IHandle;
var Msg: TPortMessage
): TNtxStatus;
// Connect to an ALPC port
function NtxAlpcConnectPort(
out hxPort: IHandle;
const PortName: String;
Flags: TAlpcMessageFlags = ALPC_MSGFLG_SYNC_REQUEST;
[opt] const ObjectAttributes: IObjectAttributes = nil;
[opt] PortAttributes: PAlpcPortAttributes = nil;
Timeout: TLargeInteger = NT_INFINITE
): TNtxStatus;
// Send a message to an ALPC port and wait for a reply
function NtxAlpcSendWaitReceivePort(
const hxPort: IHandle;
SendMessage: PPortMessage;
ReceiveMessage: PPortMessage;
BufferLength: PNativeUInt = nil;
Flags: TAlpcMessageFlags = ALPC_MSGFLG_SYNC_REQUEST;
Timeout: TLargeInteger = NT_INFINITE
): TNtxStatus;
implementation
uses
NtUtils.Objects;
{$BOOLEVAL OFF}
{$IFOPT R+}{$DEFINE R+}{$ENDIF}
{$IFOPT Q+}{$DEFINE Q+}{$ENDIF}
function NtxConnectPort;
var
PortNameStr: TNtUnicodeString;
QoS: TSecurityQualityOfService;
hPort: THandle;
begin
Result := RtlxInitUnicodeString(PortNameStr, PortName);
if not Result.IsSuccess then
Exit;
QoS.Length := SizeOf(QoS);
QoS.ImpersonationLevel := ImpersonationLevel;
QoS.ContextTrackingMode := ContextTrackingMode;
QoS.EffectiveOnly := EffectiveOnly;
Result.Location := 'NtConnectPort';
Result.LastCall.Parameter := PortName;
Result.Status := NtConnectPort(hPort, PortNameStr, QoS, nil, nil, nil, nil,
nil);
if Result.IsSuccess then
hxPort := Auto.CaptureHandle(hPort);
end;
function NtxRequestWaitReplyPort;
begin
Result.Location := 'NtRequestWaitReplyPort';
Result.Status := NtRequestWaitReplyPort(HandleOrDefault(hxPort), Msg, Msg);
end;
function NtxAlpcConnectPort;
var
NameStr: TNtUnicodeString;
hPort: THandle;
ObjAttr: PObjectAttributes;
begin
Result := RtlxInitUnicodeString(NameStr, PortName);
if not Result.IsSuccess then
Exit;
Result := AttributesRefOrNil(ObjAttr, ObjectAttributes);
if not Result.IsSuccess then
Exit;
Result.Location := 'NtAlpcConnectPort';
Result.LastCall.Parameter := PortName;
Result.Status := NtAlpcConnectPort(hPort, NameStr, ObjAttr, PortAttributes,
Flags, nil, nil, nil, nil, nil, TimeoutToLargeInteger(Timeout));
if Result.IsSuccess then
hxPort := Auto.CaptureHandle(hPort);
end;
function NtxAlpcSendWaitReceivePort;
begin
Result.Location := 'NtAlpcSendWaitReceivePort';
Result.Status := NtAlpcSendWaitReceivePort(HandleOrDefault(hxPort), Flags,
SendMessage, nil, ReceiveMessage, BufferLength, nil,
TimeoutToLargeInteger(Timeout));
end;
end.