-
Notifications
You must be signed in to change notification settings - Fork 36
/
NtUtils.Lpc.pas
68 lines (53 loc) · 1.49 KB
/
NtUtils.Lpc.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
63
64
65
66
67
68
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;
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;
end.