* added PhCreateProcessWin32

* added PE Viewer integration

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2993 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
wj32
2010-03-28 07:58:25 +00:00
parent 3d897686e5
commit 56f0fd30c0
11 changed files with 189 additions and 38 deletions
+1
View File
@@ -167,6 +167,7 @@ BEGIN
BEGIN
MENUITEM "Unload", ID_MODULE_UNLOAD
MENUITEM SEPARATOR
MENUITEM "Inspect", ID_MODULE_INSPECT
MENUITEM "Search Online", ID_MODULE_SEARCHONLINE
MENUITEM "Open Containing Folder", ID_MODULE_OPENCONTAININGFOLDER
MENUITEM "Properties", ID_MODULE_PROPERTIES
+7 -22
View File
@@ -380,14 +380,11 @@ BOOLEAN PhUiRestartProcess(
)
{
NTSTATUS status;
ULONG win32Result = 0;
BOOLEAN cont = FALSE;
HANDLE processHandle = NULL;
BOOLEAN isPosix;
PPH_STRING commandLine;
PPH_STRING currentDirectory;
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInformation;
if (PhGetIntegerSetting(L"EnableWarnings"))
{
@@ -467,36 +464,24 @@ BOOLEAN PhUiRestartProcess(
// Start the process.
memset(&startupInfo, 0, sizeof(STARTUPINFO));
startupInfo.cb = sizeof(STARTUPINFO);
if (!CreateProcess(
status = PhCreateProcessWin32(
PhGetString(Process->FileName), // we didn't wait for S1 processing
commandLine->Buffer, // string may be modified, but it's OK in this case
NULL,
NULL,
FALSE,
currentDirectory->Buffer,
0,
NULL,
currentDirectory->Buffer,
&startupInfo,
&processInformation
))
{
win32Result = GetLastError();
goto ErrorExit;
}
NtClose(processInformation.hProcess);
NtClose(processInformation.hThread);
NULL,
NULL
);
ErrorExit:
if (processHandle)
NtClose(processHandle);
if (!NT_SUCCESS(status) || win32Result)
if (!NT_SUCCESS(status))
{
PhpShowErrorProcess(hWnd, L"restart", Process, status, win32Result);
PhpShowErrorProcess(hWnd, L"restart", Process, status, 0);
return FALSE;
}
+7
View File
@@ -124,6 +124,13 @@ VOID PhSearchOnlineString(
__in PWSTR String
);
VOID PhShellExecuteUserString(
__in HWND hWnd,
__in PWSTR Setting,
__in PWSTR String,
__in BOOLEAN UseShellExecute
);
FORCEINLINE PVOID PhpGenericPropertyPageHeader(
__in HWND hwndDlg,
__in UINT uMsg,
+24
View File
@@ -1836,6 +1836,15 @@ VOID PhpInitializeModuleMenu(
__in ULONG NumberOfModules
)
{
PPH_STRING inspectExecutables;
inspectExecutables = PhGetStringSetting(L"ProgramInspectExecutables");
if (inspectExecutables->Length == 0)
DeleteMenu(Menu, ID_MODULE_INSPECT, 0);
PhDereferenceObject(inspectExecutables);
if (NumberOfModules == 0)
{
PhEnableAllMenuItems(Menu, FALSE);
@@ -2074,6 +2083,21 @@ INT_PTR CALLBACK PhpProcessModulesDlgProc(
}
}
break;
case ID_MODULE_INSPECT:
{
PPH_MODULE_ITEM moduleItem = PhGetSelectedListViewItemParam(lvHandle);
if (moduleItem)
{
PhShellExecuteUserString(
hwndDlg,
L"ProgramInspectExecutables",
moduleItem->FileName->Buffer,
FALSE
);
}
}
break;
case ID_MODULE_SEARCHONLINE:
{
PPH_MODULE_ITEM moduleItem = PhGetSelectedListViewItemParam(lvHandle);
+2 -1
View File
@@ -311,6 +311,7 @@
#define ID_USER_SENDMESSAGE 40129
#define ID_USER_PROPERTIES 40130
#define ID_USERS_DUMMY 40131
#define ID_MODULE_INSPECT 40132
#define IDDYNAMIC 50000
// Next default values for new objects
@@ -318,7 +319,7 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 154
#define _APS_NEXT_COMMAND_VALUE 40132
#define _APS_NEXT_COMMAND_VALUE 40133
#define _APS_NEXT_CONTROL_VALUE 1115
#define _APS_NEXT_SYMED_VALUE 111
#endif
+2 -1
View File
@@ -47,7 +47,8 @@ VOID PhSettingsInitialization()
PhpAddStringSetting(L"DbgHelpPath", L"dbghelp.dll");
PhpAddStringSetting(L"DbgHelpSearchPath", L"");
PhpAddIntegerSetting(L"DbgHelpUndecorate", L"1");
PhpAddStringSetting(L"SearchEngine", L"http://www.google.com/search?q=%s");
PhpAddStringSetting(L"SearchEngine", L"http://www.google.com/search?q=\"%s\"");
PhpAddStringSetting(L"ProgramInspectExecutables", L"peview.exe \"%s\"");
PhpAddIntegerPairSetting(L"ProcPropPosition", L"200,200");
PhpAddIntegerPairSetting(L"ProcPropSize", L"460,580");
PhpAddStringSetting(L"ProcPropPage", L"General");
+43 -11
View File
@@ -262,22 +262,41 @@ VOID PhSearchOnlineString(
__in PWSTR String
)
{
PPH_STRING searchEngine = PhGetStringSetting(L"SearchEngine");
ULONG indexOfReplacement = PhStringIndexOfString(searchEngine, 0, L"%s");
PhShellExecuteUserString(hWnd, L"SearchEngine", String, TRUE);
}
VOID PhShellExecuteUserString(
__in HWND hWnd,
__in PWSTR Setting,
__in PWSTR String,
__in BOOLEAN UseShellExecute
)
{
PPH_STRING executeString = PhGetStringSetting(Setting);
ULONG indexOfReplacement;
PPH_STRING stringBefore;
PPH_STRING stringAfter;
PPH_STRING newString;
// Make sure the user executable string is absolute.
if (PhStringIndexOfChar(executeString, 0, L':') == -1)
{
newString = PhConcatStrings2(PhApplicationDirectory->Buffer, executeString->Buffer);
PhDereferenceObject(executeString);
executeString = newString;
}
indexOfReplacement = PhStringIndexOfString(executeString, 0, L"%s");
if (indexOfReplacement != -1)
{
PPH_STRING stringBefore;
PPH_STRING stringAfter;
PPH_STRING newString;
// Replace "%s" with the string.
stringBefore = PhSubstring(searchEngine, 0, indexOfReplacement);
stringBefore = PhSubstring(executeString, 0, indexOfReplacement);
stringAfter = PhSubstring(
searchEngine,
executeString,
indexOfReplacement + 2,
searchEngine->Length / 2 - indexOfReplacement - 2
executeString->Length / 2 - indexOfReplacement - 2
);
newString = PhConcatStrings(
@@ -286,12 +305,25 @@ VOID PhSearchOnlineString(
String,
stringAfter->Buffer
);
PhShellExecute(hWnd, newString->Buffer, NULL);
if (UseShellExecute)
{
PhShellExecute(hWnd, newString->Buffer, NULL);
}
else
{
NTSTATUS status;
status = PhCreateProcessWin32(NULL, newString->Buffer, NULL, NULL, 0, NULL, NULL, NULL);
if (!NT_SUCCESS(status))
PhShowStatus(hWnd, L"Unable to execute the command", status, 0);
}
PhDereferenceObject(newString);
PhDereferenceObject(stringAfter);
PhDereferenceObject(stringBefore);
}
PhDereferenceObject(searchEngine);
PhDereferenceObject(executeString);
}
+15
View File
@@ -1674,6 +1674,21 @@ NTSTATUS PhWaitForMultipleObjectsAndPump(
__in ULONG Timeout
);
#define PH_CREATE_PROCESS_INHERIT_HANDLES 0x1
#define PH_CREATE_PROCESS_UNICODE_ENVIRONMENT 0x2
#define PH_CREATE_PROCESS_SUSPENDED 0x4
NTSTATUS PhCreateProcessWin32(
__in_opt PWSTR FileName,
__in_opt PWSTR CommandLine,
__in_opt PVOID Environment,
__in_opt PWSTR CurrentDirectory,
__in ULONG Flags,
__in_opt HANDLE TokenHandle,
__out_opt PHANDLE ProcessHandle,
__out_opt PHANDLE ThreadHandle
);
VOID PhShellExecute(
__in HWND hWnd,
__in PWSTR FileName,
+85
View File
@@ -1245,6 +1245,91 @@ NTSTATUS PhWaitForMultipleObjectsAndPump(
}
}
NTSTATUS PhCreateProcessWin32(
__in_opt PWSTR FileName,
__in_opt PWSTR CommandLine,
__in_opt PVOID Environment,
__in_opt PWSTR CurrentDirectory,
__in ULONG Flags,
__in_opt HANDLE TokenHandle,
__out_opt PHANDLE ProcessHandle,
__out_opt PHANDLE ThreadHandle
)
{
static PH_FLAG_MAPPING mappings[] =
{
{ PH_CREATE_PROCESS_UNICODE_ENVIRONMENT, CREATE_UNICODE_ENVIRONMENT },
{ PH_CREATE_PROCESS_SUSPENDED, CREATE_SUSPENDED }
};
NTSTATUS status;
PPH_STRING commandLine = NULL;
STARTUPINFO startupInfo = { sizeof(startupInfo) };
PROCESS_INFORMATION processInfo;
ULONG newFlags;
if (CommandLine)
commandLine = PhCreateString(CommandLine);
newFlags = 0;
PhMapFlags1(&newFlags, Flags, &mappings, sizeof(mappings) / sizeof(PH_FLAG_MAPPING));
if (!TokenHandle)
{
if (CreateProcess(
FileName,
PhGetString(commandLine),
NULL,
NULL,
!!(Flags & PH_CREATE_PROCESS_INHERIT_HANDLES),
newFlags,
Environment,
CurrentDirectory,
&startupInfo,
&processInfo
))
status = STATUS_SUCCESS;
else
status = NTSTATUS_FROM_WIN32(GetLastError());
}
else
{
if (CreateProcessAsUser(
TokenHandle,
FileName,
PhGetString(commandLine),
NULL,
NULL,
!!(Flags & PH_CREATE_PROCESS_INHERIT_HANDLES),
newFlags,
Environment,
CurrentDirectory,
&startupInfo,
&processInfo
))
status = STATUS_SUCCESS;
else
status = NTSTATUS_FROM_WIN32(GetLastError());
}
if (commandLine)
PhDereferenceObject(commandLine);
if (NT_SUCCESS(status))
{
if (ProcessHandle)
*ProcessHandle = processInfo.hProcess;
else
NtClose(processInfo.hProcess);
if (ThreadHandle)
*ThreadHandle = processInfo.hThread;
else
NtClose(processInfo.hThread);
}
return status;
}
VOID PhShellExecute(
__in HWND hWnd,
__in PWSTR FileName,
+2 -2
View File
@@ -55,8 +55,6 @@ INT WINAPI WinMain(
PhGuiSupportInitialization();
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
PhApplicationName = L"PE Viewer";
commandLine.us = NtCurrentPeb()->ProcessParameters->CommandLine;
@@ -79,6 +77,8 @@ INT WINAPI WinMain(
};
PVOID fileDialog;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
fileDialog = PhCreateOpenFileDialog();
PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));
+1 -1
View File
@@ -209,7 +209,7 @@ INT_PTR CALLBACK PvpPeGeneralDlgProc(
lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
PhSetListViewStyle(lvHandle, FALSE, TRUE);
PhSetControlTheme(lvHandle, L"explorer");
PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 60, L"Name");
PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 80, L"Name");
PhAddListViewColumn(lvHandle, 1, 1, 1, LVCFMT_LEFT, 80, L"VA");
PhAddListViewColumn(lvHandle, 2, 2, 2, LVCFMT_LEFT, 80, L"Size");