Process Hacker
libprp.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 #include <peview.h>
24 
25 INT_PTR CALLBACK PvpLibExportsDlgProc(
26  _In_ HWND hwndDlg,
27  _In_ UINT uMsg,
28  _In_ WPARAM wParam,
29  _In_ LPARAM lParam
30  );
31 
33 
35  VOID
36  )
37 {
38  NTSTATUS status;
39  PROPSHEETHEADER propSheetHeader = { sizeof(propSheetHeader) };
40  PROPSHEETPAGE propSheetPage;
41  HPROPSHEETPAGE pages[1];
42 
43  status = PhLoadMappedArchive(PvFileName->Buffer, NULL, TRUE, &PvMappedArchive);
44 
45  if (!NT_SUCCESS(status))
46  {
47  PhShowStatus(NULL, L"Unable to load the archive file", status, 0);
48  return;
49  }
50 
51  propSheetHeader.dwFlags =
52  PSH_NOAPPLYNOW |
53  PSH_NOCONTEXTHELP |
54  PSH_PROPTITLE;
55  propSheetHeader.hwndParent = NULL;
56  propSheetHeader.pszCaption = PvFileName->Buffer;
57  propSheetHeader.nPages = 0;
58  propSheetHeader.nStartPage = 0;
59  propSheetHeader.phpage = pages;
60 
61  // Exports page
62  memset(&propSheetPage, 0, sizeof(PROPSHEETPAGE));
63  propSheetPage.dwSize = sizeof(PROPSHEETPAGE);
64  propSheetPage.pszTemplate = MAKEINTRESOURCE(IDD_LIBEXPORTS);
65  propSheetPage.pfnDlgProc = PvpLibExportsDlgProc;
66  pages[propSheetHeader.nPages++] = CreatePropertySheetPage(&propSheetPage);
67 
68  PropertySheet(&propSheetHeader);
69 
70  PhUnloadMappedArchive(&PvMappedArchive);
71 }
72 
73 INT_PTR CALLBACK PvpLibExportsDlgProc(
74  _In_ HWND hwndDlg,
75  _In_ UINT uMsg,
76  _In_ WPARAM wParam,
77  _In_ LPARAM lParam
78  )
79 {
80  switch (uMsg)
81  {
82  case WM_INITDIALOG:
83  {
84  ULONG fallbackColumns[] = { 0, 1, 2, 3 };
85  HWND lvHandle;
88 
89  PhCenterWindow(GetParent(hwndDlg), NULL);
90 
91  lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
92  PhSetListViewStyle(lvHandle, FALSE, TRUE);
93  PhSetControlTheme(lvHandle, L"explorer");
94  PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 60, L"DLL");
95  PhAddListViewColumn(lvHandle, 1, 1, 1, LVCFMT_LEFT, 200, L"Name");
96  PhAddListViewColumn(lvHandle, 2, 2, 2, LVCFMT_LEFT, 40, L"Ordinal/Hint");
97  PhAddListViewColumn(lvHandle, 3, 3, 3, LVCFMT_LEFT, 40, L"Type");
98  PhAddListViewColumn(lvHandle, 4, 4, 4, LVCFMT_LEFT, 60, L"Name Type");
99  PhSetExtendedListView(lvHandle);
100  ExtendedListView_AddFallbackColumns(lvHandle, 4, fallbackColumns);
101 
102  member = *PvMappedArchive.LastStandardMember;
103 
104  while (NT_SUCCESS(PhGetNextMappedArchiveMember(&member, &member)))
105  {
106  if (NT_SUCCESS(PhGetMappedArchiveImportEntry(&member, &importEntry)))
107  {
108  INT lvItemIndex;
109  PPH_STRING name;
110  WCHAR number[PH_INT32_STR_LEN_1];
111  PWSTR type;
112 
113  name = PhZeroExtendToUtf16(importEntry.DllName);
114  lvItemIndex = PhAddListViewItem(lvHandle, MAXINT, name->Buffer, NULL);
115  PhDereferenceObject(name);
116 
117  name = PhZeroExtendToUtf16(importEntry.Name);
118  PhSetListViewSubItem(lvHandle, lvItemIndex, 1, name->Buffer);
119  PhDereferenceObject(name);
120 
121  // Ordinal is unioned with NameHint, so this works both ways.
122  PhPrintUInt32(number, importEntry.Ordinal);
123  PhSetListViewSubItem(lvHandle, lvItemIndex, 2, number);
124 
125  switch (importEntry.Type)
126  {
127  case IMPORT_OBJECT_CODE:
128  type = L"Code";
129  break;
130  case IMPORT_OBJECT_DATA:
131  type = L"Data";
132  break;
133  case IMPORT_OBJECT_CONST:
134  type = L"Const";
135  break;
136  default:
137  type = L"Unknown";
138  break;
139  }
140 
141  PhSetListViewSubItem(lvHandle, lvItemIndex, 3, type);
142 
143  switch (importEntry.NameType)
144  {
145  case IMPORT_OBJECT_ORDINAL:
146  type = L"Ordinal";
147  break;
148  case IMPORT_OBJECT_NAME:
149  type = L"Name";
150  break;
151  case IMPORT_OBJECT_NAME_NO_PREFIX:
152  type = L"Name, No Prefix";
153  break;
154  case IMPORT_OBJECT_NAME_UNDECORATE:
155  type = L"Name, Undecorate";
156  break;
157  default:
158  type = L"Unknown";
159  break;
160  }
161 
162  PhSetListViewSubItem(lvHandle, lvItemIndex, 4, type);
163  }
164  }
165 
166  ExtendedListView_SortItems(lvHandle);
167  }
168  break;
169  case WM_NOTIFY:
170  {
171  PvHandleListViewNotifyForCopy(lParam, GetDlgItem(hwndDlg, IDC_LIST));
172  }
173  break;
174  }
175 
176  return FALSE;
177 }