From 38eb0391b3c1a652f8f8cf91d24edd7cee41c41e Mon Sep 17 00:00:00 2001 From: jakcron Date: Wed, 4 Jul 2018 14:00:45 +0800 Subject: [PATCH] [es] Change handling of ticket property flags. --- lib/libes/include/es/TicketBody_V2.h | 15 ++------ lib/libes/source/TicketBody_V2.cpp | 55 ++++++++-------------------- 2 files changed, 20 insertions(+), 50 deletions(-) diff --git a/lib/libes/include/es/TicketBody_V2.h b/lib/libes/include/es/TicketBody_V2.h index 6b0be01..4741cac 100644 --- a/lib/libes/include/es/TicketBody_V2.h +++ b/lib/libes/include/es/TicketBody_V2.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include namespace es @@ -42,14 +43,8 @@ namespace es byte_t getCommonKeyId() const; void setCommonKeyId(byte_t id); - bool isPreInstall() const; - void setIsPreInstall(bool isPreInstall); - - bool isSharedTitle() const; - void setIsSharedTitle(bool isSharedTitle); - - bool allowAllContent() const; - void setAllowAllContent(bool allowAllContent); + const fnd::List& getPropertyFlags() const; + void setPropertyFlags(const fnd::List& flags); const byte_t* getReservedRegion() const; void setReservedRegion(const byte_t* data, size_t len); @@ -91,9 +86,7 @@ namespace es uint16_t mTicketVersion; ticket::LicenseType mLicenseType; byte_t mCommonKeyId; - bool mPreInstall; - bool mSharedTitle; - bool mAllowAllContent; + fnd::List mPropertyFlags; byte_t mReservedRegion[ticket::kReservedRegionSize]; // explicitly reserved uint64_t mTicketId; uint64_t mDeviceId; diff --git a/lib/libes/source/TicketBody_V2.cpp b/lib/libes/source/TicketBody_V2.cpp index 0ba5919..8e19726 100644 --- a/lib/libes/source/TicketBody_V2.cpp +++ b/lib/libes/source/TicketBody_V2.cpp @@ -27,9 +27,7 @@ void es::TicketBody_V2::operator=(const TicketBody_V2 & other) mTicketVersion = other.mTicketVersion; mLicenseType = other.mLicenseType; mCommonKeyId = other.mCommonKeyId; - mPreInstall = other.mPreInstall; - mSharedTitle = other.mSharedTitle; - mAllowAllContent = other.mAllowAllContent; + mPropertyFlags = other.mPropertyFlags; memcpy(mReservedRegion, other.mReservedRegion, ticket::kReservedRegionSize); mTicketId = other.mTicketId; mDeviceId = other.mDeviceId; @@ -49,9 +47,7 @@ bool es::TicketBody_V2::operator==(const TicketBody_V2 & other) const && (mEncType == other.mEncType) \ && (mTicketVersion == other.mTicketVersion) \ && (mLicenseType == other.mLicenseType) \ - && (mPreInstall == other.mPreInstall) \ - && (mSharedTitle == other.mSharedTitle) \ - && (mAllowAllContent == other.mAllowAllContent) \ + && (mPropertyFlags == other.mPropertyFlags) \ && (memcmp(mReservedRegion, other.mReservedRegion, ticket::kReservedRegionSize) == 0) \ && (mTicketId == other.mTicketId) \ && (mDeviceId == other.mDeviceId) \ @@ -82,9 +78,10 @@ void es::TicketBody_V2::toBytes() body->license_type = mLicenseType; body->common_key_id = mCommonKeyId; byte_t property_mask = 0; - property_mask |= mPreInstall ? _BIT(ticket::FLAG_PRE_INSTALL) : 0; - property_mask |= mSharedTitle ? _BIT(ticket::FLAG_SHARED_TITLE) : 0; - property_mask |= mAllowAllContent ? _BIT(ticket::FLAG_ALLOW_ALL_CONTENT) : 0; + for (size_t i = 0; i < mPropertyFlags.size(); i++) + { + property_mask |= _BIT(mPropertyFlags[i]); + } body->property_mask = (property_mask); memcpy(body->reserved_region, mReservedRegion, ticket::kReservedRegionSize); body->ticket_id = (mTicketId); @@ -121,9 +118,11 @@ void es::TicketBody_V2::fromBytes(const byte_t * bytes, size_t len) mTicketVersion = body->ticket_version.get(); mLicenseType = (ticket::LicenseType)body->license_type; mCommonKeyId = body->common_key_id; - mPreInstall = _HAS_BIT(body->property_mask, ticket::FLAG_PRE_INSTALL); - mSharedTitle = _HAS_BIT(body->property_mask, ticket::FLAG_SHARED_TITLE); - mAllowAllContent = _HAS_BIT(body->property_mask, ticket::FLAG_ALLOW_ALL_CONTENT); + for (size_t i = 0; i < mPropertyFlags.size(); i++) + { + if (_HAS_BIT(body->property_mask, i)) + mPropertyFlags.addElement((ticket::PropertyMaskFlags)i); + } memcpy(mReservedRegion, body->reserved_region, ticket::kReservedRegionSize); mTicketId = body->ticket_id.get(); mDeviceId = body->device_id.get(); @@ -149,9 +148,7 @@ void es::TicketBody_V2::clear() mTicketVersion = 0; mLicenseType = ticket::LICENSE_PERMANENT; mCommonKeyId = 0; - mPreInstall = false; - mSharedTitle = false; - mAllowAllContent = false; + mPropertyFlags.clear(); memset(mReservedRegion, 0, ticket::kReservedRegionSize); mTicketId = 0; mDeviceId = 0; @@ -229,34 +226,14 @@ void es::TicketBody_V2::setCommonKeyId(byte_t id) mCommonKeyId = id; } -bool es::TicketBody_V2::isPreInstall() const +const fnd::List& es::TicketBody_V2::getPropertyFlags() const { - return mPreInstall; + return mPropertyFlags; } -void es::TicketBody_V2::setIsPreInstall(bool isPreInstall) +void es::TicketBody_V2::setPropertyFlags(const fnd::List& flags) { - mPreInstall = isPreInstall; -} - -bool es::TicketBody_V2::isSharedTitle() const -{ - return mSharedTitle; -} - -void es::TicketBody_V2::setIsSharedTitle(bool isSharedTitle) -{ - mSharedTitle = isSharedTitle; -} - -bool es::TicketBody_V2::allowAllContent() const -{ - return mAllowAllContent; -} - -void es::TicketBody_V2::setAllowAllContent(bool allowAllContent) -{ - mAllowAllContent = allowAllContent; + mPropertyFlags = flags; } const byte_t * es::TicketBody_V2::getReservedRegion() const