Process Hacker
Main Page
Namespaces
Data Structures
Files
File List
Globals
svcclient.c
Go to the documentation of this file.
1
/*
2
* Process Hacker -
3
* server client
4
*
5
* Copyright (C) 2011-2015 wj32
6
*
7
* This file is part of Process Hacker.
8
*
9
* Process Hacker is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
13
*
14
* Process Hacker is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
23
#include <
phapp.h
>
24
#include <
phsvc.h
>
25
26
VOID
NTAPI
PhSvcpClientDeleteProcedure
(
27
_In_ PVOID Object,
28
_In_ ULONG Flags
29
);
30
31
PPH_OBJECT_TYPE
PhSvcClientType
;
32
LIST_ENTRY
PhSvcClientListHead
;
33
PH_QUEUED_LOCK
PhSvcClientListLock
=
PH_QUEUED_LOCK_INIT
;
34
35
NTSTATUS
PhSvcClientInitialization
(
36
VOID
37
)
38
{
39
PhSvcClientType =
PhCreateObjectType
(L
"Client"
, 0,
PhSvcpClientDeleteProcedure
);
40
InitializeListHead
(&
PhSvcClientListHead
);
41
42
return
STATUS_SUCCESS;
43
}
44
45
PPHSVC_CLIENT
PhSvcCreateClient
(
46
_In_opt_
PCLIENT_ID
ClientId
47
)
48
{
49
PPHSVC_CLIENT
client;
50
51
client =
PhCreateObject
(
sizeof
(
PHSVC_CLIENT
), PhSvcClientType);
52
memset(client, 0,
sizeof
(
PHSVC_CLIENT
));
53
PhInitializeEvent
(&client->
ReadyEvent
);
54
55
if
(ClientId)
56
client->
ClientId
= *ClientId;
57
58
PhAcquireQueuedLockExclusive
(&PhSvcClientListLock);
59
InsertTailList
(&
PhSvcClientListHead
, &client->
ListEntry
);
60
PhReleaseQueuedLockExclusive
(&PhSvcClientListLock);
61
62
return
client;
63
}
64
65
VOID
NTAPI
PhSvcpClientDeleteProcedure
(
66
_In_ PVOID Object,
67
_In_ ULONG Flags
68
)
69
{
70
PPHSVC_CLIENT
client = Object;
71
72
PhAcquireQueuedLockExclusive
(&PhSvcClientListLock);
73
RemoveEntryList
(&client->
ListEntry
);
74
PhReleaseQueuedLockExclusive
(&PhSvcClientListLock);
75
76
if
(client->
PortHandle
)
77
NtClose(client->
PortHandle
);
78
}
79
80
PPHSVC_CLIENT
PhSvcReferenceClientByClientId
(
81
_In_
PCLIENT_ID
ClientId
82
)
83
{
84
PLIST_ENTRY listEntry;
85
PPHSVC_CLIENT
client = NULL;
86
87
PhAcquireQueuedLockShared
(&PhSvcClientListLock);
88
89
listEntry =
PhSvcClientListHead
.Flink;
90
91
while
(listEntry != &
PhSvcClientListHead
)
92
{
93
client = CONTAINING_RECORD(listEntry,
PHSVC_CLIENT
, ListEntry);
94
95
if
(ClientId->UniqueThread)
96
{
97
if
(
98
client->
ClientId
.
UniqueProcess
== ClientId->UniqueProcess &&
99
client->
ClientId
.
UniqueThread
== ClientId->UniqueThread
100
)
101
{
102
break
;
103
}
104
}
105
else
106
{
107
if
(client->
ClientId
.
UniqueProcess
== ClientId->UniqueProcess)
108
break
;
109
}
110
111
client = NULL;
112
113
listEntry = listEntry->Flink;
114
}
115
116
if
(client)
117
{
118
if
(!
PhReferenceObjectSafe
(client))
119
client = NULL;
120
}
121
122
PhReleaseQueuedLockShared
(&PhSvcClientListLock);
123
124
return
client;
125
}
126
127
PPHSVC_CLIENT
PhSvcGetCurrentClient
(
128
VOID
129
)
130
{
131
return
PhSvcGetCurrentThreadContext
()->
CurrentClient
;
132
}
133
134
BOOLEAN
PhSvcAttachClient
(
135
_In_
PPHSVC_CLIENT
Client
136
)
137
{
138
PPHSVC_THREAD_CONTEXT
threadContext =
PhSvcGetCurrentThreadContext
();
139
140
if
(threadContext->
OldClient
)
141
return
FALSE
;
142
143
PhReferenceObject
(Client);
144
threadContext->
OldClient
= threadContext->
CurrentClient
;
145
threadContext->
CurrentClient
= Client;
146
147
return
TRUE
;
148
}
149
150
VOID
PhSvcDetachClient
(
151
_In_
PPHSVC_CLIENT
Client
152
)
153
{
154
PPHSVC_THREAD_CONTEXT
threadContext =
PhSvcGetCurrentThreadContext
();
155
156
PhDereferenceObject
(threadContext->
CurrentClient
);
157
threadContext->
CurrentClient
= threadContext->
OldClient
;
158
threadContext->
OldClient
= NULL;
159
}
ProcessHacker
phsvc
svcclient.c
Generated by
1.8.2