Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detoured GetCurrentPackageInfo3() should route to the OS any PackageInfoType value it doesn't handle #2623

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions dev/DynamicDependency/API/MddDetourPackageGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,15 @@ LONG MddGetPackageInfo1Or2(
return ::GetPackageInfo(packageInfoReference, flags, bufferLength, buffer, count);
}
}

HRESULT MddTrueGetCurrentPackageInfo3(
UINT32 flags,
PackageInfoType packageInfoType,
UINT32* bufferLength,
void* buffer,
UINT32* count)
{
// Passthru to the original (not-Detoured) Windows API
RETURN_IF_FAILED(TrueGetCurrentPackageInfo3(flags, packageInfoType, bufferLength, buffer, count));
return S_OK;
}
11 changes: 10 additions & 1 deletion dev/DynamicDependency/API/MddDetourPackageGraph.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#if !defined(MDDDETOURPACKAGEGRAPH_H)
#define MDDDETOURPACKAGEGRAPH_H

#include "appmodel_msixdynamicdependency.h"

HRESULT WINAPI MddDetourPackageGraphInitialize() noexcept;

void WINAPI MddDetourPackageGraphShutdown() noexcept;
Expand All @@ -22,4 +24,11 @@ LONG MddGetPackageInfo1Or2(
BYTE* buffer,
UINT32* count);

HRESULT MddTrueGetCurrentPackageInfo3(
UINT32 flags,
PackageInfoType packageInfoType,
UINT32* bufferLength,
void* buffer,
UINT32* count);

#endif // MDDDETOURPACKAGEGRAPH_H
20 changes: 14 additions & 6 deletions dev/DynamicDependency/API/PackageGraphManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "PackageGraphManager.h"

#include "MddDetourPackageGraph.h"

std::recursive_mutex MddCore::PackageGraphManager::s_lock;
MddCore::PackageGraph MddCore::PackageGraphManager::s_packageGraph;
volatile ULONG MddCore::PackageGraphManager::s_generationId{};
Expand Down Expand Up @@ -133,12 +135,18 @@ HRESULT MddCore::PackageGraphManager::GetCurrentPackageInfo3(
*generationId = GetGenerationId();
return S_OK;
}
RETURN_HR_IF(E_INVALIDARG, (packageInfoType != PackageInfoType_PackageInfoInstallPath) &&
(packageInfoType != PackageInfoType_PackageInfoMutablePath) &&
(packageInfoType != PackageInfoType_PackageInfoEffectivePath) &&
(packageInfoType != PackageInfoType_PackageInfoMachineExternalPath) &&
(packageInfoType != PackageInfoType_PackageInfoUserExternalPath) &&
(packageInfoType != PackageInfoType_PackageInfoEffectiveExternalPath));
else if ((packageInfoType != PackageInfoType_PackageInfoInstallPath) &&
(packageInfoType != PackageInfoType_PackageInfoMutablePath) &&
(packageInfoType != PackageInfoType_PackageInfoEffectivePath) &&
(packageInfoType != PackageInfoType_PackageInfoMachineExternalPath) &&
(packageInfoType != PackageInfoType_PackageInfoUserExternalPath) &&
(packageInfoType != PackageInfoType_PackageInfoEffectiveExternalPath))
{
// packageInfoType isn't a value we recognize and/or handle
// Pass the call on down to Windows to handle the request
RETURN_IF_FAILED(MddTrueGetCurrentPackageInfo3(flags, packageInfoType, bufferLength, buffer, count));
return S_OK;
}

// We manage the package graph as a list of nodes, where each contain contains information about 1+ package.
//
Expand Down