Process Hacker
main.c
Go to the documentation of this file.
1 /*
2  * Process Hacker Network Tools -
3  * main program
4  *
5  * Copyright (C) 2010-2011 wj32
6  * Copyright (C) 2013 dmex
7  *
8  * This file is part of Process Hacker.
9  *
10  * Process Hacker is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * Process Hacker is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "nettools.h"
25 
31 
33  _In_opt_ PVOID Parameter,
34  _In_opt_ PVOID Context
35  )
36 {
37  DialogBox(
38  PluginInstance->DllBase,
39  MAKEINTRESOURCE(IDD_OPTIONS),
40  (HWND)Parameter,
42  );
43 }
44 
46  _In_opt_ PVOID Parameter,
47  _In_opt_ PVOID Context
48  )
49 {
50  PPH_PLUGIN_MENU_ITEM menuItem = (PPH_PLUGIN_MENU_ITEM)Parameter;
51  PPH_NETWORK_ITEM networkItem = (PPH_NETWORK_ITEM)menuItem->Context;
52 
53  switch (menuItem->Id)
54  {
57  break;
60  break;
63  break;
64  }
65 }
66 
68  _In_opt_ PVOID Parameter,
69  _In_opt_ PVOID Context
70  )
71 {
73  PPH_NETWORK_ITEM networkItem;
74  PPH_EMENU_ITEM toolsMenu;
75  PPH_EMENU_ITEM closeMenuItem;
76 
77  if (menuInfo->u.Network.NumberOfNetworkItems == 1)
78  networkItem = menuInfo->u.Network.NetworkItems[0];
79  else
80  networkItem = NULL;
81 
82  // Create the Tools menu.
83  toolsMenu = PhPluginCreateEMenuItem(PluginInstance, 0, 0, L"Tools", NULL);
84  PhInsertEMenuItem(toolsMenu, PhPluginCreateEMenuItem(PluginInstance, 0, NETWORK_ACTION_PING, L"Ping", networkItem), -1);
85  PhInsertEMenuItem(toolsMenu, PhPluginCreateEMenuItem(PluginInstance, 0, NETWORK_ACTION_TRACEROUTE, L"Traceroute", networkItem), -1);
86  PhInsertEMenuItem(toolsMenu, PhPluginCreateEMenuItem(PluginInstance, 0, NETWORK_ACTION_WHOIS, L"Whois", networkItem), -1);
87 
88  // Insert the Tools menu into the network menu.
89  closeMenuItem = PhFindEMenuItem(menuInfo->Menu, 0, L"Close", 0);
90  PhInsertEMenuItem(menuInfo->Menu, toolsMenu, closeMenuItem ? PhIndexOfEMenuItem(menuInfo->Menu, closeMenuItem) : 1);
91 
92  toolsMenu->Flags |= PH_EMENU_DISABLED;
93 
94  if (networkItem)
95  {
96  if (!PhIsNullIpAddress(&networkItem->RemoteEndpoint.Address))
97  {
98  toolsMenu->Flags &= ~PH_EMENU_DISABLED;
99  }
100  }
101 }
102 
104  _In_ HINSTANCE Instance,
105  _In_ ULONG Reason,
106  _Reserved_ PVOID Reserved
107  )
108 {
109  switch (Reason)
110  {
111  case DLL_PROCESS_ATTACH:
112  {
114  PH_SETTING_CREATE settings[] =
115  {
120  { IntegerSettingType, SETTING_NAME_PING_TIMEOUT, L"3e8" } // 1000 timeout.
121  };
122 
123  PluginInstance = PhRegisterPlugin(PLUGIN_NAME, Instance, &info);
124 
125  if (!PluginInstance)
126  return FALSE;
127 
128  info->DisplayName = L"Network Tools";
129  info->Author = L"dmex, wj32";
130  info->Description = L"Provides ping, traceroute and whois for network connections.";
131  info->Url = L"http://processhacker.sf.net/forums/viewtopic.php?t=1117";
132  info->HasOptions = TRUE;
133 
137  NULL,
138  &PluginShowOptionsCallbackRegistration
139  );
143  NULL,
144  &PluginMenuItemCallbackRegistration
145  );
146 
150  NULL,
151  &NetworkMenuInitializingCallbackRegistration
152  );
153 
154  PhAddSettings(settings, _countof(settings));
155  }
156  break;
157  }
158 
159  return TRUE;
160 }