add plugins-extra
This commit is contained in:
2
plugins-extra/ServiceBackupRestorePlugin/CHANGELOG.txt
Normal file
2
plugins-extra/ServiceBackupRestorePlugin/CHANGELOG.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
1.0
|
||||
* Initial release
|
||||
@@ -0,0 +1,123 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (Australia) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENA)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_AUS
|
||||
#pragma code_page(1252)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,0
|
||||
PRODUCTVERSION 1,0,0,0
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "0c0904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "dmex"
|
||||
VALUE "FileDescription", "Service Backup and Restore Plugin for Process Hacker"
|
||||
VALUE "FileVersion", "1.0"
|
||||
VALUE "InternalName", "dmex.ServiceBackupRestorePlugin"
|
||||
VALUE "LegalCopyright", "Licensed under the GNU GPL, v3."
|
||||
VALUE "OriginalFilename", "ServiceBackupRestorePlugin.dll"
|
||||
VALUE "ProductName", "Service Backup and Restore Plugin for Process Hacker"
|
||||
VALUE "ProductVersion", "1.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0xc09, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_OPTIONS DIALOGEX 0, 0, 187, 56
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_APPWINDOW
|
||||
CAPTION "Options"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
PUSHBUTTON "Cancel",IDCANCEL,131,35,50,14
|
||||
COMBOBOX IDC_GRAPH_TYPE,7,17,173,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Select Graph to show on the Taskbar:",IDC_STATIC,7,5,122,8
|
||||
DEFPUSHBUTTON "Ok",IDOK,79,35,50,14
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO
|
||||
BEGIN
|
||||
IDD_OPTIONS, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 180
|
||||
TOPMARGIN, 5
|
||||
BOTTOMMARGIN, 49
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (Australia) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{D08A2B6C-822F-46C8-A7AC-A2EE609237D6}</ProjectGuid>
|
||||
<RootNamespace>ServiceBackupRestorePlugin</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectName>ServiceBackupRestorePlugin</ProjectName>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;C:\Users\AirDog46\Downloads\processhacker-2.39-src\bin\Debug32</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\Users\AirDog46\Downloads\processhacker-2.39-src\bin\Release64</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;C:\Users\AirDog46\Downloads\processhacker-2.39-src\bin\Release32</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="backup.c" />
|
||||
<ClCompile Include="main.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="ServiceBackupRestorePlugin.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CHANGELOG.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="main.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CHANGELOG.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{425a0fc8-1446-4937-8041-dbe97bcbebc4}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{cb9a1b81-72f0-4b16-974c-dda6e1ab96ab}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{2a3c08d8-713f-4933-93e3-9a8ce42807ca}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="ServiceBackupRestorePlugin.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="backup.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
252
plugins-extra/ServiceBackupRestorePlugin/backup.c
Normal file
252
plugins-extra/ServiceBackupRestorePlugin/backup.c
Normal file
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Process Hacker Extra Plugins -
|
||||
* Service Backup and Restore Plugin
|
||||
*
|
||||
* Copyright (C) 2015 dmex
|
||||
*
|
||||
* This file is part of Process Hacker.
|
||||
*
|
||||
* Process Hacker is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Process Hacker is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
static PH_STRINGREF servicesKeyName = PH_STRINGREF_INIT(L"System\\CurrentControlSet\\Services\\");
|
||||
static PH_STRINGREF fileExtName = PH_STRINGREF_INIT(L".phservicebackup");
|
||||
|
||||
static PH_FILETYPE_FILTER filters[] =
|
||||
{
|
||||
{ L"Service Backup File (*.phservicebackup)", L"*.phservicebackup" },
|
||||
};
|
||||
|
||||
VOID PhBackupService(
|
||||
_In_ HWND OwnerWindow,
|
||||
_In_ PPH_SERVICE_ITEM ServiceItem
|
||||
)
|
||||
{
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
HANDLE keyHandle = NULL;
|
||||
HANDLE fileHandle = NULL;
|
||||
PVOID fileDialog = NULL;
|
||||
PPH_STRING ofdFileName = NULL;
|
||||
PPH_STRING backupFileName = NULL;
|
||||
PPH_STRING serviceKeyName = NULL;
|
||||
|
||||
backupFileName = PhConcatStringRef2(&ServiceItem->Name->sr, &fileExtName);
|
||||
serviceKeyName = PhConcatStringRef2(&servicesKeyName, &ServiceItem->Name->sr);
|
||||
|
||||
__try
|
||||
{
|
||||
if (!NT_SUCCESS(status = PhOpenKey(
|
||||
&keyHandle,
|
||||
KEY_ALL_ACCESS, // KEY_READ,
|
||||
PH_KEY_LOCAL_MACHINE,
|
||||
&serviceKeyName->sr,
|
||||
0
|
||||
)))
|
||||
{
|
||||
__leave;
|
||||
}
|
||||
|
||||
fileDialog = PhCreateSaveFileDialog();
|
||||
PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));
|
||||
PhSetFileDialogFileName(fileDialog, backupFileName->Buffer);
|
||||
|
||||
if (!PhShowFileDialog(OwnerWindow, fileDialog))
|
||||
__leave;
|
||||
|
||||
ofdFileName = PhGetFileDialogFileName(fileDialog);
|
||||
|
||||
if (!NT_SUCCESS(status = PhCreateFileWin32(
|
||||
&fileHandle,
|
||||
ofdFileName->Buffer,
|
||||
FILE_GENERIC_WRITE | DELETE,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
FILE_SHARE_READ,
|
||||
FILE_OVERWRITE_IF,
|
||||
FILE_NON_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT
|
||||
)))
|
||||
{
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status = NtSaveKeyEx(
|
||||
keyHandle,
|
||||
fileHandle,
|
||||
PhGetIntegerSetting(SETTING_NAME_REG_FORMAT)
|
||||
)))
|
||||
{
|
||||
__leave;
|
||||
}
|
||||
}
|
||||
__finally
|
||||
{
|
||||
if (fileHandle)
|
||||
{
|
||||
NtClose(fileHandle);
|
||||
}
|
||||
|
||||
if (keyHandle)
|
||||
{
|
||||
NtClose(keyHandle);
|
||||
}
|
||||
|
||||
if (ofdFileName)
|
||||
{
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhDeleteFileWin32(ofdFileName->Buffer);
|
||||
}
|
||||
|
||||
PhDereferenceObject(ofdFileName);
|
||||
}
|
||||
|
||||
if (fileDialog)
|
||||
{
|
||||
PhFreeFileDialog(fileDialog);
|
||||
}
|
||||
|
||||
PhDereferenceObject(backupFileName);
|
||||
PhDereferenceObject(serviceKeyName);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhShowStatus(OwnerWindow, L"Unable to backup the service", status, 0);
|
||||
}
|
||||
}
|
||||
|
||||
VOID PhRestoreService(
|
||||
_In_ HWND OwnerWindow,
|
||||
_In_ PPH_SERVICE_ITEM ServiceItem
|
||||
)
|
||||
{
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
HANDLE keyHandle = NULL;
|
||||
HANDLE fileHandle = NULL;
|
||||
PVOID fileDialog = NULL;
|
||||
PPH_STRING ofdFileName = NULL;
|
||||
PPH_STRING backupFileName = NULL;
|
||||
PPH_STRING serviceKeyName = NULL;
|
||||
|
||||
backupFileName = PhConcatStringRef2(&ServiceItem->Name->sr, &fileExtName);
|
||||
serviceKeyName = PhConcatStringRef2(&servicesKeyName, &ServiceItem->Name->sr);
|
||||
|
||||
__try
|
||||
{
|
||||
if (!NT_SUCCESS(status = PhOpenKey(
|
||||
&keyHandle,
|
||||
KEY_ALL_ACCESS,// KEY_WRITE
|
||||
PH_KEY_LOCAL_MACHINE,
|
||||
&serviceKeyName->sr,
|
||||
0
|
||||
)))
|
||||
{
|
||||
__leave;
|
||||
}
|
||||
|
||||
fileDialog = PhCreateOpenFileDialog();
|
||||
PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));
|
||||
|
||||
if (!PhShowFileDialog(OwnerWindow, fileDialog))
|
||||
__leave;
|
||||
|
||||
ofdFileName = PhGetFileDialogFileName(fileDialog);
|
||||
|
||||
HKEY appKeyHandle;
|
||||
|
||||
if (RegLoadAppKey(
|
||||
ofdFileName->Buffer,
|
||||
&appKeyHandle,
|
||||
KEY_ALL_ACCESS,
|
||||
REG_PROCESS_APPKEY, // REG_APP_HIVE
|
||||
0
|
||||
) == ERROR_SUCCESS)
|
||||
{
|
||||
PPH_STRING displayName = PhQueryRegistryString(appKeyHandle, L"DisplayName");
|
||||
PPH_STRING currentDisplayName = PhQueryRegistryString(keyHandle, L"DisplayName");
|
||||
|
||||
if (!PhEqualString(displayName, currentDisplayName, TRUE))
|
||||
{
|
||||
PhDereferenceObject(currentDisplayName);
|
||||
PhDereferenceObject(displayName);
|
||||
NtClose(appKeyHandle);
|
||||
PhShowError(OwnerWindow, L"The display name does not match the backup of this service.");
|
||||
__leave;
|
||||
}
|
||||
|
||||
PhDereferenceObject(currentDisplayName);
|
||||
PhDereferenceObject(displayName);
|
||||
NtClose(appKeyHandle);
|
||||
}
|
||||
|
||||
if (PhFindStringInString(ofdFileName, 0, ServiceItem->Name->Buffer) == -1)
|
||||
{
|
||||
PhShowError(OwnerWindow, L"The file name does not match the name of this service.");
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status = PhCreateFileWin32(
|
||||
&fileHandle,
|
||||
ofdFileName->Buffer,
|
||||
FILE_GENERIC_READ,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
FILE_SHARE_READ,
|
||||
FILE_OPEN,
|
||||
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
|
||||
)))
|
||||
{
|
||||
__leave;
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status = NtRestoreKey(
|
||||
keyHandle,
|
||||
fileHandle,
|
||||
0 // REG_FORCE_RESTORE
|
||||
)))
|
||||
{
|
||||
__leave;
|
||||
}
|
||||
}
|
||||
__finally
|
||||
{
|
||||
if (fileHandle)
|
||||
{
|
||||
NtClose(fileHandle);
|
||||
}
|
||||
|
||||
if (keyHandle)
|
||||
{
|
||||
NtClose(keyHandle);
|
||||
}
|
||||
|
||||
if (ofdFileName)
|
||||
{
|
||||
PhDereferenceObject(ofdFileName);
|
||||
}
|
||||
|
||||
if (fileDialog)
|
||||
{
|
||||
PhFreeFileDialog(fileDialog);
|
||||
}
|
||||
|
||||
PhDereferenceObject(backupFileName);
|
||||
PhDereferenceObject(serviceKeyName);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhShowStatus(OwnerWindow, L"Unable to restore the service", status, 0);
|
||||
}
|
||||
}
|
||||
193
plugins-extra/ServiceBackupRestorePlugin/main.c
Normal file
193
plugins-extra/ServiceBackupRestorePlugin/main.c
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Process Hacker Extra Plugins -
|
||||
* Service Backup and Restore Plugin
|
||||
*
|
||||
* Copyright (C) 2015 dmex
|
||||
*
|
||||
* This file is part of Process Hacker.
|
||||
*
|
||||
* Process Hacker is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Process Hacker is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
PPH_PLUGIN PluginInstance;
|
||||
static PH_CALLBACK_REGISTRATION PluginLoadCallbackRegistration;
|
||||
static PH_CALLBACK_REGISTRATION PluginUnloadCallbackRegistration;
|
||||
static PH_CALLBACK_REGISTRATION PluginShowOptionsCallbackRegistration;
|
||||
static PH_CALLBACK_REGISTRATION PluginMenuItemCallbackRegistration;
|
||||
static PH_CALLBACK_REGISTRATION ServiceMenuInitializingCallbackRegistration;
|
||||
|
||||
VOID NTAPI LoadCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
HANDLE tokenHandle;
|
||||
|
||||
if (NT_SUCCESS(NtOpenProcessToken(
|
||||
NtCurrentProcess(),
|
||||
TOKEN_ADJUST_PRIVILEGES,
|
||||
&tokenHandle
|
||||
)))
|
||||
{
|
||||
// Enable the backup and restore privileges
|
||||
PhSetTokenPrivilege(tokenHandle, SE_BACKUP_NAME, NULL, SE_PRIVILEGE_ENABLED);
|
||||
PhSetTokenPrivilege(tokenHandle, SE_RESTORE_NAME, NULL, SE_PRIVILEGE_ENABLED);
|
||||
NtClose(tokenHandle);
|
||||
}
|
||||
}
|
||||
|
||||
VOID NTAPI UnloadCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
NOTHING;
|
||||
}
|
||||
|
||||
VOID NTAPI ShowOptionsCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
NOTHING;
|
||||
}
|
||||
|
||||
VOID NTAPI MenuItemCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PLUGIN_MENU_ITEM menuItem = Parameter;
|
||||
|
||||
switch (menuItem->Id)
|
||||
{
|
||||
case 1001:
|
||||
PhBackupService(menuItem->OwnerWindow, menuItem->Context);
|
||||
break;
|
||||
case 1002:
|
||||
{
|
||||
if (PhGetIntegerSetting(L"EnableWarnings"))
|
||||
{
|
||||
if (MessageBox(
|
||||
menuItem->OwnerWindow,
|
||||
L"Restoring the incorrect file will permanently destroy this service.\r\n\r\nAre you sure you want to continue?",
|
||||
L"WARNING",
|
||||
MB_ICONEXCLAMATION | MB_YESNO
|
||||
) != IDYES)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PhRestoreService(menuItem->OwnerWindow, menuItem->Context);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VOID NTAPI ServiceMenuInitializingCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PLUGIN_MENU_INFORMATION menuInfo = Parameter;
|
||||
PPH_EMENU_ITEM menuItemBackup;
|
||||
PPH_EMENU_ITEM menuItemRestore;
|
||||
ULONG indexOfMenuItem;
|
||||
|
||||
if (menuInfo->u.Service.NumberOfServices != 1)
|
||||
return;
|
||||
|
||||
menuItemBackup = PhFindEMenuItem(menuInfo->Menu, PH_EMENU_FIND_STARTSWITH, L"Open Key", 0);
|
||||
|
||||
if (menuItemBackup)
|
||||
indexOfMenuItem = PhIndexOfEMenuItem(menuInfo->Menu, menuItemBackup);
|
||||
else
|
||||
indexOfMenuItem = -1;
|
||||
|
||||
menuItemBackup = PhPluginCreateEMenuItem(PluginInstance, 0, 1001, L"Backup...", menuInfo->u.Service.Services[0]);
|
||||
menuItemRestore = PhPluginCreateEMenuItem(PluginInstance, 0, 1002, L"Restore...", menuInfo->u.Service.Services[0]);
|
||||
PhInsertEMenuItem(menuInfo->Menu, menuItemBackup, indexOfMenuItem);
|
||||
PhInsertEMenuItem(menuInfo->Menu, menuItemRestore, indexOfMenuItem + 1);
|
||||
PhInsertEMenuItem(menuInfo->Menu, PhCreateEMenuItem(PH_EMENU_SEPARATOR, 0, L"", NULL, NULL), indexOfMenuItem + 2);
|
||||
}
|
||||
|
||||
LOGICAL DllMain(
|
||||
_In_ HINSTANCE Instance,
|
||||
_In_ ULONG Reason,
|
||||
_Reserved_ PVOID Reserved
|
||||
)
|
||||
{
|
||||
switch (Reason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
PPH_PLUGIN_INFORMATION info;
|
||||
PH_SETTING_CREATE settings[] =
|
||||
{
|
||||
{ IntegerSettingType, SETTING_NAME_REG_FORMAT, L"2" }
|
||||
};
|
||||
|
||||
PluginInstance = PhRegisterPlugin(PLUGIN_NAME, Instance, &info);
|
||||
|
||||
if (!PluginInstance)
|
||||
return FALSE;
|
||||
|
||||
info->DisplayName = L"Service Backup and Restore";
|
||||
info->Author = L"dmex";
|
||||
info->Description = L"Plugin for backing up and restoring individual services.";
|
||||
info->HasOptions = FALSE;
|
||||
|
||||
PhRegisterCallback(
|
||||
PhGetPluginCallback(PluginInstance, PluginCallbackLoad),
|
||||
LoadCallback,
|
||||
NULL,
|
||||
&PluginLoadCallbackRegistration
|
||||
);
|
||||
PhRegisterCallback(
|
||||
PhGetPluginCallback(PluginInstance, PluginCallbackUnload),
|
||||
UnloadCallback,
|
||||
NULL,
|
||||
&PluginUnloadCallbackRegistration
|
||||
);
|
||||
PhRegisterCallback(
|
||||
PhGetPluginCallback(PluginInstance, PluginCallbackShowOptions),
|
||||
ShowOptionsCallback,
|
||||
NULL,
|
||||
&PluginShowOptionsCallbackRegistration
|
||||
);
|
||||
|
||||
PhRegisterCallback(
|
||||
PhGetPluginCallback(PluginInstance, PluginCallbackMenuItem),
|
||||
MenuItemCallback,
|
||||
NULL,
|
||||
&PluginMenuItemCallbackRegistration
|
||||
);
|
||||
|
||||
PhRegisterCallback(
|
||||
PhGetGeneralCallback(GeneralCallbackServiceMenuInitializing),
|
||||
ServiceMenuInitializingCallback,
|
||||
NULL,
|
||||
&ServiceMenuInitializingCallbackRegistration
|
||||
);
|
||||
|
||||
PhAddSettings(settings, ARRAYSIZE(settings));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
47
plugins-extra/ServiceBackupRestorePlugin/main.h
Normal file
47
plugins-extra/ServiceBackupRestorePlugin/main.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Process Hacker Extra Plugins -
|
||||
* Service Backup and Restore Plugin
|
||||
*
|
||||
* Copyright (C) 2015 dmex
|
||||
*
|
||||
* This file is part of Process Hacker.
|
||||
*
|
||||
* Process Hacker is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Process Hacker is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SR_EXT_H_
|
||||
#define _SR_EXT_H_
|
||||
|
||||
#define PLUGIN_NAME L"dmex.ServiceBackupRestorePlugin"
|
||||
#define SETTING_NAME_REG_FORMAT (PLUGIN_NAME L".RegFileFormat")
|
||||
|
||||
#define CINTERFACE
|
||||
#define COBJMACROS
|
||||
#include <phdk.h>
|
||||
#include <phappresource.h>
|
||||
#include "resource.h"
|
||||
|
||||
extern PPH_PLUGIN PluginInstance;
|
||||
|
||||
VOID PhBackupService(
|
||||
_In_ HWND OwnerWindow,
|
||||
_In_ PPH_SERVICE_ITEM ServiceItem
|
||||
);
|
||||
|
||||
VOID PhRestoreService(
|
||||
_In_ HWND OwnerWindow,
|
||||
_In_ PPH_SERVICE_ITEM ServiceItem
|
||||
);
|
||||
|
||||
#endif _SR_EXT_H_
|
||||
17
plugins-extra/ServiceBackupRestorePlugin/resource.h
Normal file
17
plugins-extra/ServiceBackupRestorePlugin/resource.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by ServiceBackupRestorePlugin.rc
|
||||
//
|
||||
#define IDD_OPTIONS 101
|
||||
#define IDC_GRAPH_TYPE 1001
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 106
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1002
|
||||
#define _APS_NEXT_SYMED_VALUE 106
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user