Process Hacker
main.c
Go to the documentation of this file.
1 /*
2  * Process Hacker -
3  * PE viewer
4  *
5  * Copyright (C) 2010 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 #define MAIN_PRIVATE
24 #include <peview.h>
25 
27 
28 static BOOLEAN NTAPI PvCommandLineCallback(
29  _In_opt_ PPH_COMMAND_LINE_OPTION Option,
30  _In_opt_ PPH_STRING Value,
31  _In_opt_ PVOID Context
32  )
33 {
34  if (!Option)
35  PhSwapReference(&PvFileName, Value);
36 
37  return TRUE;
38 }
39 
40 INT WINAPI wWinMain(
41  _In_ HINSTANCE hInstance,
42  _In_opt_ HINSTANCE hPrevInstance,
43  _In_ PWSTR lpCmdLine,
44  _In_ INT nCmdShow
45  )
46 {
47  static PH_COMMAND_LINE_OPTION options[] =
48  {
49  { 0, L"h", NoArgumentType }
50  };
51  PH_STRINGREF commandLine;
52 
54  return 1;
55 
57 
58  PhApplicationName = L"PE Viewer";
59 
60  PhUnicodeStringToStringRef(&NtCurrentPeb()->ProcessParameters->CommandLine, &commandLine);
61 
63  &commandLine,
64  options,
65  sizeof(options) / sizeof(PH_COMMAND_LINE_OPTION),
67  PvCommandLineCallback,
68  NULL
69  );
70 
71  if (!PvFileName)
72  {
73  static PH_FILETYPE_FILTER filters[] =
74  {
75  { L"Supported files (*.exe;*.dll;*.ocx;*.sys;*.scr;*.cpl;*.ax;*.acm;*.lib;*.winmd)", L"*.exe;*.dll;*.ocx;*.sys;*.scr;*.cpl;*.ax;*.acm;*.lib;*.winmd" },
76  { L"All files (*.*)", L"*.*" }
77  };
78  PVOID fileDialog;
79 
80  CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
81 
82  fileDialog = PhCreateOpenFileDialog();
83  PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));
84 
85  if (PhShowFileDialog(NULL, fileDialog))
86  {
87  PvFileName = PhGetFileDialogFileName(fileDialog);
88  }
89 
90  PhFreeFileDialog(fileDialog);
91  }
92 
93  if (!PvFileName)
94  return 1;
95 
96  if (PhEndsWithString2(PvFileName, L".lnk", TRUE))
97  {
98  PPH_STRING targetFileName;
99 
100  CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
101  targetFileName = PvResolveShortcutTarget(PvFileName);
102 
103  if (targetFileName)
104  PhMoveReference(&PvFileName, targetFileName);
105  }
106 
107  if (!PhEndsWithString2(PvFileName, L".lib", TRUE))
108  PvPeProperties();
109  else
110  PvLibProperties();
111 
112  return 0;
113 }