Implement Windows8+ Applicability PAL

This commit is contained in:
Ruben Guerrero Samaniego 2018-04-10 16:40:50 -07:00 коммит произвёл msftrubengu
Родитель cf39a03965
Коммит ca1a5ca3fb
8 изменённых файлов: 173 добавлений и 7 удалений

23
manifest.cmakein Normal file
Просмотреть файл

@ -0,0 +1,23 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<description>${DESCRIPTION}</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 7 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 8 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

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

@ -7,6 +7,13 @@ project (makemsix)
# Define two variables in order not to repeat ourselves.
set(BINARY_NAME ExtractContentsSample)
if(WIN32)
set(DESCRIPTION "makemsix manifest")
configure_file(../../manifest.cmakein ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.exe.manifest CRLF)
set(MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.exe.manifest)
endif()
include_directories(
${include_directories}
${CMAKE_PROJECT_ROOT}/src/inc
@ -14,6 +21,7 @@ include_directories(
add_executable(${BINARY_NAME}
ExtractContentsSample.cpp
${MANIFEST}
)
# specify that this binary is to be built with C++14

18
src/inc/Applicability.hpp Normal file
Просмотреть файл

@ -0,0 +1,18 @@
//
// Copyright (C) 2017 Microsoft. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#pragma once
#include <set>
#include <string>
namespace MSIX {
class Applicability
{
public:
static MSIX_PLATFORM GetPlatform();
static std::set<std::string> GetLanguages();
};
}

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

@ -2010,6 +2010,20 @@ enum MSIX_PACKUNPACK_OPTION
MSIX_PACKUNPACK_OPTION_CREATEPACKAGESUBFOLDER = 0x1
} MSIX_PACKUNPACK_OPTION;
typedef /* [v1_enum] */
enum MSIX_PLATFORM
{
MSIX_PLATFORM_ALL = 0x0,
MSIX_PLATFORM_WINDOWS10 = 0x1,
MSIX_PLATFORM_WINDOWS8POINT1 = 0x2,
MSIX_PLATFORM_WINDOWS8 = 0x4,
MSIX_PLATFORM_WINDOWS7 = 0x8,
MSIX_PLATFORM_MACOS = 0x10,
MSIX_PLATFORM_IOS = 0x20,
MSIX_PLATFORM_AOSP = 0x40,
MSIX_PLATFORM_LINUX = 0x80,
} MSIX_PLATFORM;
MSIX_API HRESULT STDMETHODCALLTYPE UnpackPackage(
MSIX_PACKUNPACK_OPTION packUnpackOptions,
MSIX_VALIDATION_OPTION validationOption,

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

@ -8,6 +8,12 @@ project (makemsix)
# Define two variables in order not to repeat ourselves.
set(BINARY_NAME makemsix)
if(WIN32)
set(DESCRIPTION "makemsix manifest")
configure_file(../../manifest.cmakein ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.exe.manifest CRLF)
set(MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.exe.manifest)
endif()
include_directories(
${include_directories}
${CMAKE_PROJECT_ROOT}/src/inc
@ -15,6 +21,7 @@ include_directories(
add_executable(${BINARY_NAME}
main.cpp
${MANIFEST}
)
# specify that this binary is to be built with C++14

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

@ -23,9 +23,10 @@ IF (XML_PARSER MATCHES msxml6)
ENDIF()
IF(WIN32)
SET (DirectoryObject PAL/FileSystem/Win32/DirectoryObject.CPP)
SET (SHA256 PAL/SHA256/Win32/SHA256.CPP)
SET (DirectoryObject PAL/FileSystem/Win32/DirectoryObject.cpp)
SET (SHA256 PAL/SHA256/Win32/SHA256.cpp)
SET (Signature PAL/Signature/Win32/SignatureValidator.cpp)
SET (Applicability PAL/Applicability/Win32/Applicability.cpp)
ELSE()
# Visibility variables for non-win32 platforms
IF((IOS) OR (MACOS))
@ -71,6 +72,7 @@ MESSAGE (STATUS "PAL: XML = ${XmlParser}")
MESSAGE (STATUS "PAL: DirectoryObject = ${DirectoryObject}")
MESSAGE (STATUS "PAL: SHA256 = ${SHA256}")
MESSAGE (STATUS "PAL: Signature = ${Signature}")
MESSAGE (STATUS "PAL: Applicability = ${Applicability}")
include(msix_resources)
@ -80,6 +82,7 @@ SET(LIB_PUBLIC_HEADERS
)
SET(LIB_PRIVATE_HEADERS
../inc/Applicability.hpp
../inc/AppxBlockMapObject.hpp
../inc/AppxFactory.hpp
../inc/AppxPackageInfo.hpp
@ -122,6 +125,7 @@ SET(LIB_SOURCES
${SHA256}
${Signature}
${XmlParser}
${Applicability}
)
# Copy out public headers
@ -175,5 +179,6 @@ IF(OpenSSL_FOUND)
ENDIF()
if(WIN32)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE bcrypt crypt32 wintrust)
SET_PROPERTY(TARGET ${BINARY_NAME} PROPERTY VS_WINRT_COMPONENT TRUE)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE bcrypt crypt32 wintrust runtimeobject.lib)
endif()

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

@ -0,0 +1,91 @@
//
// Copyright (C) 2017 Microsoft. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#include <windows.h>
#include <VersionHelpers.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include <windows.system.userprofile.h>
#include "AppxPackaging.hpp"
#include "Exceptions.hpp"
#include "Applicability.hpp"
#include "ComHelper.hpp"
#include "UnicodeConversion.hpp"
#include <set>
#include <iostream>
using namespace ABI::Windows::Foundation::Collections;
using namespace ABI::Windows::System::UserProfile;
using namespace Microsoft::WRL::Wrappers;
using namespace Windows::Foundation;
namespace MSIX {
#define ThrowHrIfFalse(a, m) \
{ BOOL _result = a; \
if (!_result) \
{ MSIX::RaiseException<MSIX::Exception> (__LINE__, __FILE__, m, HRESULT_FROM_WIN32(GetLastError())); \
} \
}
MSIX_PLATFORM Applicability::GetPlatform()
{
if (IsWindows10OrGreater())
{
return MSIX_PLATFORM_WINDOWS10;
}
else if (IsWindows8Point1OrGreater())
{
return MSIX_PLATFORM_WINDOWS8POINT1;
}
else if (IsWindows8OrGreater())
{
return MSIX_PLATFORM_WINDOWS8;
}
else if (IsWindows7SP1OrGreater() || IsWindows7OrGreater())
{
return MSIX_PLATFORM_WINDOWS7;
}
UNEXPECTED;
}
std::set<std::string> Applicability::GetLanguages()
{
std::set<std::string> result;
if (MSIX_PLATFORM_WINDOWS7 == GetPlatform())
{
ULONG numOfLangs = 0;
DWORD size = 0;
std::wstring languagesWin7;
ThrowHrIfFalse(GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numOfLangs, nullptr, &size),
"Failed GetUserPreferredUILanguages");
languagesWin7.resize(size);
ThrowHrIfFalse(GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numOfLangs, &languagesWin7.front(), &size),
"Failed GetUserPreferredUILanguages");
// TODO: split languagesWin7 by /0 and add the table with MUI to BCP47 conversion
}
else
{
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
ThrowHrIfFailed(initialize);
ComPtr<IGlobalizationPreferencesStatics> globalizationPreferences;
ComPtr<IVectorView<HSTRING>> languages;
ThrowHrIfFailed(GetActivationFactory(HStringReference(
RuntimeClass_Windows_System_UserProfile_GlobalizationPreferences).Get(),&globalizationPreferences));
ThrowHrIfFailed(globalizationPreferences->get_Languages(&languages));
UINT numOfLanguages = 0;
ThrowHrIfFailed(languages->get_Size(&numOfLanguages));
for (UINT i = 0; i < numOfLanguages; i++)
{
HString hstring;
ThrowHrIfFailed(languages->GetAt(i, hstring.GetAddressOf()));
result.insert(utf16_to_utf8(hstring.GetRawBuffer(nullptr)));
}
}
return result;
}
}

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

@ -35,14 +35,14 @@ namespace MSIX {
{
public:
NtStatusException(std::string& message, NTSTATUS error) : Exception(message, static_cast<std::uint32_t>(error)) {}
};
};
#define ThrowStatusIfFailed(a, m) \
{ NTSTATUS _status = a; \
if (!NT_SUCCESS(_status)) \
{ MSIX::RaiseException<MSIX::NtStatusException>(__LINE__, __FILE__, m, _status); \
} \
}
}
bool SHA256::ComputeHash(std::uint8_t* buffer, std::uint32_t cbBuffer, std::vector<uint8_t>& hash)
{
@ -61,7 +61,7 @@ namespace MSIX {
"failed computing SHA256 hash");
// Obtain the length of the hash
unique_alg_handle algHandle(algHandleT);
unique_alg_handle algHandle(algHandleT);
ThrowStatusIfFailed(BCryptGetProperty(
algHandle.get(), // Handle to a CNG object
BCRYPT_HASH_LENGTH, // Property name (null terminated unicode string)
@ -87,7 +87,7 @@ namespace MSIX {
"failed computing SHA256 hash");
// Hash the message(s)
unique_hash_handle hashHandle(hashHandleT);
unique_hash_handle hashHandle(hashHandleT);
ThrowStatusIfFailed(BCryptHashData(
hashHandle.get(), // Handle to the hash or MAC object
(PBYTE)buffer, // A pointer to a buffer that contains the data to hash