Process Hacker
main.c
Go to the documentation of this file.
1 /*
2  * Process Hacker .NET Tools -
3  * main program
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 "dn.h"
24 #include "resource.h"
25 
26 VOID NTAPI LoadCallback(
27  _In_opt_ PVOID Parameter,
28  _In_opt_ PVOID Context
29  );
30 
31 VOID NTAPI UnloadCallback(
32  _In_opt_ PVOID Parameter,
33  _In_opt_ PVOID Context
34  );
35 
37  _In_opt_ PVOID Parameter,
38  _In_opt_ PVOID Context
39  );
40 
42  _In_opt_ PVOID Parameter,
43  _In_opt_ PVOID Context
44  );
45 
47  _In_opt_ PVOID Parameter,
48  _In_opt_ PVOID Context
49  );
50 
52  _In_opt_ PVOID Parameter,
53  _In_opt_ PVOID Context
54  );
55 
57  _In_opt_ PVOID Parameter,
58  _In_opt_ PVOID Context
59  );
60 
62  _In_opt_ PVOID Parameter,
63  _In_opt_ PVOID Context
64  );
65 
67  _In_opt_ PVOID Parameter,
68  _In_opt_ PVOID Context
69  );
70 
72  _In_opt_ PVOID Parameter,
73  _In_opt_ PVOID Context
74  );
75 
77  _In_opt_ PVOID Parameter,
78  _In_opt_ PVOID Context
79  );
80 
82  _In_opt_ PVOID Parameter,
83  _In_opt_ PVOID Context
84  );
85 
87  _In_opt_ PVOID Parameter,
88  _In_opt_ PVOID Context
89  );
90 
92  _In_opt_ PVOID Parameter,
93  _In_opt_ PVOID Context
94  );
95 
97  _In_opt_ PVOID Parameter,
98  _In_opt_ PVOID Context
99  );
100 
102  _In_ PVOID Object,
103  _In_ PH_EM_OBJECT_TYPE ObjectType,
104  _In_ PVOID Extension
105  );
106 
108  _In_ PVOID Object,
109  _In_ PH_EM_OBJECT_TYPE ObjectType,
110  _In_ PVOID Extension
111  );
112 
129 
131  _In_ HINSTANCE Instance,
132  _In_ ULONG Reason,
133  _Reserved_ PVOID Reserved
134  )
135 {
136  switch (Reason)
137  {
138  case DLL_PROCESS_ATTACH:
139  {
141 
142  PluginInstance = PhRegisterPlugin(PLUGIN_NAME, Instance, &info);
143 
144  if (!PluginInstance)
145  return FALSE;
146 
147  info->DisplayName = L".NET Tools";
148  info->Author = L"wj32";
149  info->Description = L"Adds .NET performance counters, assembly information, thread stack support, and more.";
150  info->Url = L"http://processhacker.sf.net/forums/viewtopic.php?t=1111";
151  info->HasOptions = FALSE;
152 
154  PhGetPluginCallback(PluginInstance, PluginCallbackLoad),
155  LoadCallback,
156  NULL,
157  &PluginLoadCallbackRegistration
158  );
160  PhGetPluginCallback(PluginInstance, PluginCallbackUnload),
162  NULL,
163  &PluginUnloadCallbackRegistration
164  );
168  NULL,
169  &PluginShowOptionsCallbackRegistration
170  );
171  //PhRegisterCallback(
172  // PhGetPluginCallback(PluginInstance, PluginCallbackMenuItem),
173  // MenuItemCallback,
174  // NULL,
175  // &PluginMenuItemCallbackRegistration
176  // );
180  NULL,
181  &PluginTreeNewMessageCallbackRegistration
182  );
186  NULL,
187  &PluginPhSvcRequestCallbackRegistration
188  );
189 
190  //PhRegisterCallback(
191  // PhGetGeneralCallback(GeneralCallbackMainWindowShowing),
192  // MainWindowShowingCallback,
193  // NULL,
194  // &MainWindowShowingCallbackRegistration
195  // );
199  NULL,
200  &ProcessPropertiesInitializingCallbackRegistration
201  );
202  //PhRegisterCallback(
203  // PhGetGeneralCallback(GeneralCallbackProcessMenuInitializing),
204  // ProcessMenuInitializingCallback,
205  // NULL,
206  // &ProcessMenuInitializingCallbackRegistration
207  // );
208  //PhRegisterCallback(
209  // PhGetGeneralCallback(GeneralCallbackThreadMenuInitializing),
210  // ThreadMenuInitializingCallback,
211  // NULL,
212  // &ThreadMenuInitializingCallbackRegistration
213  // );
214  //PhRegisterCallback(
215  // PhGetGeneralCallback(GeneralCallbackModuleMenuInitializing),
216  // ModuleMenuInitializingCallback,
217  // NULL,
218  // &ModuleMenuInitializingCallbackRegistration
219  // );
220  //PhRegisterCallback(
221  // PhGetGeneralCallback(GeneralCallbackProcessTreeNewInitializing),
222  // ProcessTreeNewInitializingCallback,
223  // NULL,
224  // &ProcessTreeNewInitializingCallbackRegistration
225  // );
229  NULL,
230  &ThreadTreeNewInitializingCallbackRegistration
231  );
235  NULL,
236  &ThreadTreeNewUninitializingCallbackRegistration
237  );
241  NULL,
242  &ThreadStackControlCallbackRegistration
243  );
244 
246  PluginInstance,
248  sizeof(DN_THREAD_ITEM),
251  );
253 
254  {
255  static PH_SETTING_CREATE settings[] =
256  {
258  };
259 
260  PhAddSettings(settings, sizeof(settings) / sizeof(PH_SETTING_CREATE));
261  }
262  }
263  break;
264  }
265 
266  return TRUE;
267 }
268 
270  _In_opt_ PVOID Parameter,
271  _In_opt_ PVOID Context
272  )
273 {
274  NOTHING;
275 }
276 
278  _In_opt_ PVOID Parameter,
279  _In_opt_ PVOID Context
280  )
281 {
282  NOTHING;
283 }
284 
286  _In_opt_ PVOID Parameter,
287  _In_opt_ PVOID Context
288  )
289 {
290  NOTHING;
291 }
292 
294  _In_opt_ PVOID Parameter,
295  _In_opt_ PVOID Context
296  )
297 {
298  PPH_PLUGIN_MENU_ITEM menuItem = Parameter;
299 
300  switch (menuItem->Id)
301  {
302  default:
303  NOTHING;
304  break;
305  }
306 }
307 
309  _In_opt_ PVOID Parameter,
310  _In_opt_ PVOID Context
311  )
312 {
313  DispatchTreeNewMessage(Parameter);
314 }
315 
317  _In_opt_ PVOID Parameter,
318  _In_opt_ PVOID Context
319  )
320 {
321  DispatchPhSvcRequest(Parameter);
322 }
323 
325  _In_opt_ PVOID Parameter,
326  _In_opt_ PVOID Context
327  )
328 {
329  ThreadTreeNewInitializing(Parameter);
330 }
331 
333  _In_opt_ PVOID Parameter,
334  _In_opt_ PVOID Context
335  )
336 {
337  ThreadTreeNewUninitializing(Parameter);
338 }
339 
341  _In_opt_ PVOID Parameter,
342  _In_opt_ PVOID Context
343  )
344 {
345  PPH_PLUGIN_PROCESS_PROPCONTEXT propContext = Parameter;
346  BOOLEAN isDotNet;
347 
348  if (NT_SUCCESS(PhGetProcessIsDotNet(propContext->ProcessItem->ProcessId, &isDotNet)))
349  {
350  if (isDotNet)
351  {
353  AddAsmPageToPropContext(propContext);
354  AddPerfPageToPropContext(propContext);
355  }
356 
357  if (propContext->ProcessItem->IsDotNet != isDotNet)
358  propContext->ProcessItem->UpdateIsDotNet = TRUE; // force a refresh
359  }
360 }
361 
363  _In_opt_ PVOID Parameter,
364  _In_opt_ PVOID Context
365  )
366 {
367  NOTHING;
368 }
369 
371  _In_opt_ PVOID Parameter,
372  _In_opt_ PVOID Context
373  )
374 {
375  NOTHING;
376 }
377 
379  _In_opt_ PVOID Parameter,
380  _In_opt_ PVOID Context
381  )
382 {
383  NOTHING;
384 }
385 
387  _In_opt_ PVOID Parameter,
388  _In_opt_ PVOID Context
389  )
390 {
391  NOTHING;
392 }
393 
395  _In_opt_ PVOID Parameter,
396  _In_opt_ PVOID Context
397  )
398 {
399  ProcessThreadStackControl(Parameter);
400 }
401 
403  _In_ PVOID Object,
404  _In_ PH_EM_OBJECT_TYPE ObjectType,
405  _In_ PVOID Extension
406  )
407 {
408  PDN_THREAD_ITEM dnThread = Extension;
409 
410  memset(dnThread, 0, sizeof(DN_THREAD_ITEM));
411  dnThread->ThreadItem = Object;
412 }
413 
415  _In_ PVOID Object,
416  _In_ PH_EM_OBJECT_TYPE ObjectType,
417  _In_ PVOID Extension
418  )
419 {
420  PDN_THREAD_ITEM dnThread = Extension;
421 
422  PhClearReference(&dnThread->AppDomainText);
423 }