Process Hacker
main.c
Go to the documentation of this file.
1 /*
2  * Process Hacker Online Checks -
3  * Main Program
4  *
5  * Copyright (C) 2010-2013 wj32
6  * Copyright (C) 2012-2014 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 "onlnchk.h"
25 
32 
33 static VOID NTAPI LoadCallback(
34  _In_opt_ PVOID Parameter,
35  _In_opt_ PVOID Context
36  )
37 {
38  // Nothing
39 }
40 
41 static VOID NTAPI ShowOptionsCallback(
42  _In_opt_ PVOID Parameter,
43  _In_opt_ PVOID Context
44  )
45 {
46  // Nothing
47 }
48 
49 static VOID NTAPI MenuItemCallback(
50  _In_opt_ PVOID Parameter,
51  _In_opt_ PVOID Context
52  )
53 {
54  PPH_PLUGIN_MENU_ITEM menuItem = Parameter;
55  PPH_STRING fileName;
56 
57  switch (menuItem->Id)
58  {
59  case ID_SENDTO_SERVICE1:
60  fileName = menuItem->Context;
62  break;
63  case ID_SENDTO_SERVICE2:
64  fileName = menuItem->Context;
66  break;
67  case ID_SENDTO_SERVICE3:
68  fileName = menuItem->Context;
70  break;
71  }
72 }
73 
74 static PPH_EMENU_ITEM CreateSendToMenu(
75  _In_ PPH_EMENU_ITEM Parent,
76  _In_ PWSTR InsertAfter,
77  _In_ PPH_STRING FileName
78  )
79 {
80  PPH_EMENU_ITEM sendToMenu;
81  PPH_EMENU_ITEM menuItem;
82  ULONG insertIndex;
83 
84  // Create the Send To menu.
85  sendToMenu = PhPluginCreateEMenuItem(PluginInstance, 0, 0, L"Send To", NULL);
86  PhInsertEMenuItem(sendToMenu, PhPluginCreateEMenuItem(PluginInstance, 0, ID_SENDTO_SERVICE1, L"virustotal.com", FileName), -1);
87  PhInsertEMenuItem(sendToMenu, PhPluginCreateEMenuItem(PluginInstance, 0, ID_SENDTO_SERVICE2, L"virusscan.jotti.org", FileName), -1);
88  PhInsertEMenuItem(sendToMenu, PhPluginCreateEMenuItem(PluginInstance, 0, ID_SENDTO_SERVICE3, L"camas.comodo.com", FileName), -1);
89 
90  menuItem = PhFindEMenuItem(Parent, PH_EMENU_FIND_STARTSWITH, InsertAfter, 0);
91 
92  if (menuItem)
93  insertIndex = PhIndexOfEMenuItem(Parent, menuItem);
94  else
95  insertIndex = -1;
96 
97  PhInsertEMenuItem(Parent, sendToMenu, insertIndex + 1);
98 
99  return sendToMenu;
100 }
101 
103  _In_opt_ PVOID Parameter,
104  _In_opt_ PVOID Context
105  )
106 {
107  PPH_PLUGIN_MENU_INFORMATION menuInfo = Parameter;
108  PPH_PROCESS_ITEM processItem;
109  PPH_EMENU_ITEM sendToMenu;
110 
111  if (menuInfo->u.Process.NumberOfProcesses == 1)
112  processItem = menuInfo->u.Process.Processes[0];
113  else
114  processItem = NULL;
115 
116  sendToMenu = CreateSendToMenu(menuInfo->Menu, L"Search Online", processItem ? processItem->FileName : NULL);
117 
118  // Only enable the Send To menu if there is exactly one process selected and it has a file name.
119 
120  if (!processItem || !processItem->FileName)
121  {
122  sendToMenu->Flags |= PH_EMENU_DISABLED;
123  }
124 }
125 
127  _In_opt_ PVOID Parameter,
128  _In_opt_ PVOID Context
129  )
130 {
131  PPH_PLUGIN_MENU_INFORMATION menuInfo = Parameter;
132  PPH_MODULE_ITEM moduleItem;
133  PPH_EMENU_ITEM sendToMenu;
134 
135  if (menuInfo->u.Module.NumberOfModules == 1)
136  moduleItem = menuInfo->u.Module.Modules[0];
137  else
138  moduleItem = NULL;
139 
140  sendToMenu = CreateSendToMenu(menuInfo->Menu, L"Search Online", moduleItem ? moduleItem->FileName : NULL);
141 
142  if (!moduleItem)
143  {
144  sendToMenu->Flags |= PH_EMENU_DISABLED;
145  }
146 }
147 
149  _In_ HINSTANCE Instance,
150  _In_ ULONG Reason,
151  _Reserved_ PVOID Reserved
152  )
153 {
154  switch (Reason)
155  {
156  case DLL_PROCESS_ATTACH:
157  {
159 
160  PluginInstance = PhRegisterPlugin(PLUGIN_NAME, Instance, &info);
161 
162  if (!PluginInstance)
163  return FALSE;
164 
165  info->DisplayName = L"Online Checks";
166  info->Author = L"dmex, wj32";
167  info->Description = L"Allows files to be checked with online services.";
168  info->Url = L"http://processhacker.sf.net/forums/viewtopic.php?t=1118";
169  info->HasOptions = FALSE;
170 
172  PhGetPluginCallback(PluginInstance, PluginCallbackLoad),
173  LoadCallback,
174  NULL,
175  &PluginLoadCallbackRegistration
176  );
180  NULL,
181  &PluginShowOptionsCallbackRegistration
182  );
186  NULL,
187  &PluginMenuItemCallbackRegistration
188  );
192  NULL,
193  &ProcessMenuInitializingCallbackRegistration
194  );
198  NULL,
199  &ModuleMenuInitializingCallbackRegistration
200  );
201  }
202  break;
203  }
204 
205  return TRUE;
206 }