* Parse manifest

* Write reg keys

* launching alias from win+r works

* Still testing, does not work from cmd prompt

* Implement remove

* Updated notepad package with test extension

* Updated correct namespace for appexecution alias
This commit is contained in:
jyvenugo 2019-08-22 14:40:45 -07:00 коммит произвёл GitHub
Родитель 3c48599fc2
Коммит b204d4b08a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 191 добавлений и 11 удалений

Просмотреть файл

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c93e7769fd5d028ff40bd7d14fbaebf92d30003eca0f8ea9b267aec9d1851d5f
size 3112177
oid sha256:f259c4acdb356446b182996c051fe986b809240d57a7722fc9e6627f4d171d43
size 3112192

Просмотреть файл

@ -0,0 +1,143 @@
#include <windows.h>
#include "GeneralUtil.hpp"
#include "RegistryKey.hpp"
#include <TraceLoggingProvider.h>
#include "MsixTraceLoggingProvider.hpp"
#include "Constants.hpp"
#include "AppExecutionAlias.hpp"
using namespace MsixCoreLib;
const PCWSTR AppExecutionAlias::HandlerName = L"AppExecutionAlias";
HRESULT AppExecutionAlias::ExecuteForAddRequest()
{
for (auto executionAlias = m_appExecutionAliases.begin(); executionAlias != m_appExecutionAliases.end(); ++executionAlias)
{
RETURN_IF_FAILED(ProcessAliasForAdd(*executionAlias));
}
return S_OK;
}
HRESULT AppExecutionAlias::ExecuteForRemoveRequest()
{
for (auto executionAlias = m_appExecutionAliases.begin(); executionAlias != m_appExecutionAliases.end(); ++executionAlias)
{
RETURN_IF_FAILED(ProcessAliasForRemove(*executionAlias));
}
return S_OK;
}
HRESULT MsixCoreLib::AppExecutionAlias::ParseManifest()
{
ComPtr<IMsixDocumentElement> domElement;
RETURN_IF_FAILED(m_msixRequest->GetPackageInfo()->GetManifestReader()->QueryInterface(UuidOfImpl<IMsixDocumentElement>::iid, reinterpret_cast<void**>(&domElement)));
ComPtr<IMsixElement> element;
RETURN_IF_FAILED(domElement->GetDocumentElement(&element));
ComPtr<IMsixElementEnumerator> extensionEnum;
RETURN_IF_FAILED(element->GetElements(extensionQuery.c_str(), &extensionEnum));
BOOL hasCurrent = FALSE;
RETURN_IF_FAILED(extensionEnum->GetHasCurrent(&hasCurrent));
while (hasCurrent)
{
ComPtr<IMsixElement> extensionElement;
RETURN_IF_FAILED(extensionEnum->GetCurrent(&extensionElement));
Text<wchar_t> extensionCategory;
RETURN_IF_FAILED(extensionElement->GetAttributeValue(categoryAttribute.c_str(), &extensionCategory));
if (wcscmp(extensionCategory.Get(), appExecutionAliasCategory.c_str()) == 0)
{
BOOL hc_executionAlias = FALSE;
ComPtr<IMsixElementEnumerator> executionAliasEnum;
RETURN_IF_FAILED(extensionElement->GetElements(executionAliasQuery.c_str(), &executionAliasEnum));
RETURN_IF_FAILED(executionAliasEnum->GetHasCurrent(&hc_executionAlias));
while (hc_executionAlias)
{
ComPtr<IMsixElement> executionAliasElement;
RETURN_IF_FAILED(executionAliasEnum->GetCurrent(&executionAliasElement));
//alias
Text<wchar_t> alias;
RETURN_IF_FAILED(executionAliasElement->GetAttributeValue(executionAliasName.c_str(), &alias));
m_appExecutionAliases.push_back(alias.Get());
RETURN_IF_FAILED(executionAliasEnum->MoveNext(&hc_executionAlias));
}
}
RETURN_IF_FAILED(extensionEnum->MoveNext(&hasCurrent));
}
return S_OK;
}
HRESULT AppExecutionAlias::ProcessAliasForAdd(std::wstring & aliasName)
{
RegistryKey appPathsKey;
RETURN_IF_FAILED(appPathsKey.Open(HKEY_LOCAL_MACHINE, appPathsRegKeyName.c_str(), KEY_READ | KEY_WRITE));
RegistryKey aliasKey;
RETURN_IF_FAILED(appPathsKey.CreateSubKey(aliasName.c_str(), KEY_READ | KEY_WRITE, &aliasKey));
RETURN_IF_FAILED(aliasKey.SetStringValue(L"", m_msixRequest->GetPackageInfo()->GetResolvedExecutableFilePath()));
std::wstring executableDirectoryPath;
std::wstring executableFilePath = m_msixRequest->GetPackageInfo()->GetResolvedExecutableFilePath();
size_t lastSlashPostion = executableFilePath.rfind('\\');
if (std::wstring::npos != lastSlashPostion)
{
executableDirectoryPath = executableFilePath.substr(0, lastSlashPostion);
}
RETURN_IF_FAILED(aliasKey.SetStringValue(L"Path", executableDirectoryPath));
return S_OK;
}
HRESULT AppExecutionAlias::ProcessAliasForRemove(std::wstring & aliasName)
{
RegistryKey appPathsKey;
RETURN_IF_FAILED(appPathsKey.Open(HKEY_LOCAL_MACHINE, appPathsRegKeyName.c_str(), KEY_READ | KEY_WRITE));
RegistryKey aliasKey;
HRESULT hrCreateSubKey = appPathsKey.CreateSubKey(aliasName.c_str(), KEY_READ | KEY_WRITE, &aliasKey);
if (SUCCEEDED(hrCreateSubKey))
{
std::wstring aliasExecutablePath;
if (SUCCEEDED(aliasKey.GetStringValue(L"", aliasExecutablePath)))
{
if (CaseInsensitiveEquals(aliasExecutablePath, m_msixRequest->GetPackageInfo()->GetResolvedExecutableFilePath()))
{
HRESULT hrDeleteKey = appPathsKey.DeleteTree(aliasName.c_str());
if (FAILED(hrDeleteKey))
{
TraceLoggingWrite(g_MsixTraceLoggingProvider,
"Unable to delete app execution aliasname key",
TraceLoggingLevel(WINEVENT_LEVEL_WARNING),
TraceLoggingValue(hrDeleteKey, "HR"),
TraceLoggingValue(aliasName.c_str(), "aliasName"));
}
}
}
}
return S_OK;
}
HRESULT AppExecutionAlias::CreateHandler(MsixRequest * msixRequest, IPackageHandler ** instance)
{
std::unique_ptr<AppExecutionAlias > localInstance(new AppExecutionAlias(msixRequest));
if (localInstance == nullptr)
{
return E_OUTOFMEMORY;
}
RETURN_IF_FAILED(localInstance->ParseManifest());
*instance = localInstance.release();
return S_OK;
}

Просмотреть файл

@ -0,0 +1,33 @@
#pragma once
#include "GeneralUtil.hpp"
#include "IPackageHandler.hpp"
#include "MsixRequest.hpp"
namespace MsixCoreLib
{
class AppExecutionAlias : IPackageHandler
{
public:
HRESULT ExecuteForAddRequest();
HRESULT ExecuteForRemoveRequest();
static const PCWSTR HandlerName;
static HRESULT CreateHandler(_In_ MsixRequest* msixRequest, _Out_ IPackageHandler** instance);
~AppExecutionAlias() {}
private:
MsixRequest * m_msixRequest = nullptr;
std::vector<std::wstring> m_appExecutionAliases;
AppExecutionAlias() {}
AppExecutionAlias(_In_ MsixRequest* msixRequest) : m_msixRequest(msixRequest) {}
HRESULT ParseManifest();
HRESULT ProcessAliasForAdd(std::wstring & aliasName);
HRESULT ProcessAliasForRemove(std::wstring & aliasName);
};
}

Просмотреть файл

@ -1,7 +1,4 @@
#include <windows.h>
#include <shlobj_core.h>
#include <CommCtrl.h>
#include <iostream>
#include <algorithm>

Просмотреть файл

@ -110,10 +110,6 @@ static const std::wstring directionOut = L"out";
/// Constants for AutoPlay DEH
static const std::wstring desktopAppXExtensionCategory = L"windows.autoPlayHandler";
static const std::wstring desktopAppXContentSubCategory = L"Windows.AutoPlayDesktopAppX.Content";
static const std::wstring desktopAppXDeviceSubCategory = L"Windows.AutoPlayDesktopAppX.Device";
static const std::wstring idAttributeName = L"Verb";
static const std::wstring actionAttributeName = L"ActionDisplayName";
static const std::wstring providerAttributeName = L"ProviderDisplayName";
@ -131,6 +127,12 @@ static const std::wstring explorerRegKeyName = L"Software\\Microsoft\\Windows\\C
static const std::wstring handlerKeyName = L"AutoPlayHandlers\\Handlers";
static const std::wstring eventHandlerRootRegKeyName = L"AutoPlayHandlers\\EventHandlers";
/// Constants for AppExecutionAlias DEH
static const std::wstring appExecutionAliasCategory = L"windows.appExecutionAlias";
static const std::wstring executionAliasQuery = L"*[local-name()='AppExecutionAlias']/*[local-name()='ExecutionAlias']";
static const std::wstring executionAliasName = L"Alias";
static const std::wstring appPathsRegKeyName = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths";
static const std::wstring clsidKeyName = L"CLSID";
static const std::wstring inprocHandlerKeyName = L"InprocHandler32";
static const std::wstring defaultInprocHandler = L"ole32.dll";

Просмотреть файл

@ -37,6 +37,7 @@
#include "FirewallRules.hpp"
#include "AutoPlay.hpp"
#include "VirtualFileHandler.hpp"
#include "AppExecutionAlias.hpp"
#include "Constants.hpp"
@ -83,7 +84,8 @@ std::map<PCWSTR, AddHandlerInfo> AddHandlers =
{StartupTask::HandlerName, {StartupTask::CreateHandler, FileTypeAssociation::HandlerName, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{FileTypeAssociation::HandlerName, {FileTypeAssociation::CreateHandler, FirewallRules::HandlerName, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{FirewallRules::HandlerName, {FirewallRules::CreateHandler, AutoPlay::HandlerName, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{AutoPlay::HandlerName, {AutoPlay::CreateHandler, InstallComplete::HandlerName, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{AutoPlay::HandlerName, {AutoPlay::CreateHandler, AppExecutionAlias::HandlerName, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{AppExecutionAlias::HandlerName, {AppExecutionAlias::CreateHandler, InstallComplete::HandlerName, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{InstallComplete::HandlerName, {InstallComplete::CreateHandler, nullptr, ExecuteErrorHandler, ErrorHandler::HandlerName}},
{ErrorHandler::HandlerName, {ErrorHandler::CreateHandler, nullptr, ReturnError, nullptr}},
};
@ -101,7 +103,8 @@ std::map<PCWSTR, RemoveHandlerInfo> RemoveHandlers =
{StartupTask::HandlerName, {StartupTask::CreateHandler, FileTypeAssociation::HandlerName, IgnoreAndProcessNextHandler}},
{FileTypeAssociation::HandlerName, {FileTypeAssociation::CreateHandler, FirewallRules::HandlerName, IgnoreAndProcessNextHandler}},
{FirewallRules::HandlerName, {FirewallRules::CreateHandler, AutoPlay::HandlerName, IgnoreAndProcessNextHandler}},
{AutoPlay::HandlerName, {AutoPlay::CreateHandler, VirtualFileHandler::HandlerName, IgnoreAndProcessNextHandler}},
{AutoPlay::HandlerName, {AutoPlay::CreateHandler, AppExecutionAlias::HandlerName, IgnoreAndProcessNextHandler}},
{AppExecutionAlias::HandlerName, {AppExecutionAlias::CreateHandler, VirtualFileHandler::HandlerName, IgnoreAndProcessNextHandler}},
{VirtualFileHandler::HandlerName, {VirtualFileHandler::CreateHandler, WriteDevirtualizedRegistry::HandlerName, IgnoreAndProcessNextHandler}},
{WriteDevirtualizedRegistry::HandlerName, {WriteDevirtualizedRegistry::CreateHandler, Extractor::HandlerName, IgnoreAndProcessNextHandler}},
{Extractor::HandlerName, {Extractor::CreateHandler, nullptr, IgnoreAndProcessNextHandler}},

Просмотреть файл

@ -192,6 +192,7 @@
<ClInclude Include="..\msixmgr\CryptoProvider.hpp" />
<ClInclude Include="..\msixmgr\Base32Encoding.hpp" />
<ClInclude Include="..\msixmgr\VirtualFileHandler.hpp" />
<ClInclude Include="..\msixmgr\AppExecutionAlias.hpp" />
<ClInclude Include="inc\IMsixResponse.hpp" />
<ClInclude Include="inc\DeploymentOptions.hpp" />
<ClInclude Include="..\msixmgr\Extractor.hpp" />
@ -236,6 +237,7 @@
<ClCompile Include="..\msixmgr\CryptoProvider.cpp" />
<ClCompile Include="..\msixmgr\Base32Encoding.cpp" />
<ClCompile Include="..\msixmgr\VirtualFileHandler.cpp" />
<ClCompile Include="..\msixmgr\AppExecutionAlias.cpp" />
<ClCompile Include="GeneralUtil.cpp" />
<ClCompile Include="..\msixmgr\MsixResponse.cpp" />
<ClCompile Include="MsixTraceLoggingProvider.cpp" />