mirror of
https://github.com/jakcron/nstool
synced 2024-11-14 17:56:39 +00:00
[es] Converted endian sensitive primatives to wrapped types.
This commit is contained in:
parent
1dbef17165
commit
5f91ea9c8b
5 changed files with 74 additions and 141 deletions
|
@ -117,76 +117,25 @@ namespace es
|
|||
#pragma pack (push, 1)
|
||||
struct sTicketBody_v2
|
||||
{
|
||||
private:
|
||||
char issuer_[kIssuerLen];
|
||||
byte_t enc_title_key_[kEncTitleKeyLen];
|
||||
byte_t format_version_;
|
||||
byte_t title_key_enc_type_;
|
||||
uint16_t ticket_version_;
|
||||
byte_t license_type_;
|
||||
byte_t common_key_id_;
|
||||
byte_t property_mask_;
|
||||
byte_t reserved_0_;
|
||||
byte_t reserved_region_[kReservedRegionLen]; // explicitly reserved
|
||||
uint64_t ticket_id_;
|
||||
uint64_t device_id_;
|
||||
byte_t rights_id_[kRightsIdLen];
|
||||
uint32_t account_id_;
|
||||
uint32_t sect_total_size_;
|
||||
uint32_t sect_header_offset_;
|
||||
uint16_t sect_num_;
|
||||
uint16_t sect_entry_size_;
|
||||
public:
|
||||
const char* issuer() const { return issuer_; }
|
||||
void set_issuer(const char issuer[kIssuerLen]) { strncpy(issuer_, issuer, kIssuerLen); }
|
||||
|
||||
const byte_t* enc_title_key() const { return enc_title_key_; }
|
||||
void set_enc_title_key(const byte_t* enc_title_key, size_t len) { memset(enc_title_key_, 0, kEncTitleKeyLen); memcpy(enc_title_key_, enc_title_key, MIN(len, kEncTitleKeyLen)); }
|
||||
|
||||
byte_t format_version() const { return format_version_; }
|
||||
void set_format_version(byte_t version) { format_version_ = version; }
|
||||
|
||||
byte_t title_key_enc_type() const { return title_key_enc_type_; }
|
||||
void set_title_key_enc_type(byte_t type) { title_key_enc_type_ = type; }
|
||||
|
||||
uint16_t ticket_version() const { return le_hword(ticket_version_); }
|
||||
void set_ticket_version(uint16_t version) { ticket_version_ = le_hword(version); }
|
||||
|
||||
byte_t license_type() const { return license_type_; }
|
||||
void set_license_type(byte_t license_type) { license_type_ = license_type; }
|
||||
|
||||
byte_t common_key_id() const { return common_key_id_; }
|
||||
void set_common_key_id(byte_t common_key_id) { common_key_id_ = common_key_id; }
|
||||
|
||||
byte_t property_mask() const { return property_mask_; }
|
||||
void set_property_mask(byte_t mask) { property_mask_ = mask; }
|
||||
|
||||
const byte_t* reserved_region() const { return reserved_region_; }
|
||||
void set_reserved_region(const byte_t* reserved_region, size_t len) { memcpy(reserved_region_, reserved_region, MIN(len, kReservedRegionLen)); }
|
||||
|
||||
uint64_t ticket_id() const { return le_dword(ticket_id_); }
|
||||
void set_ticket_id(uint64_t ticket_id) { ticket_id_ = le_dword(ticket_id); }
|
||||
|
||||
uint64_t device_id() const { return le_dword(device_id_); }
|
||||
void set_device_id(uint64_t device_id) { device_id_ = le_dword(device_id); }
|
||||
|
||||
const byte_t* rights_id() const { return rights_id_; }
|
||||
void set_rights_id(const byte_t rights_id[kRightsIdLen]) { memcpy(rights_id_, rights_id, kRightsIdLen); }
|
||||
|
||||
uint32_t account_id() const { return le_word(account_id_); }
|
||||
void set_account_id(uint32_t id) { account_id_ = le_word(id); }
|
||||
|
||||
uint32_t sect_total_size() const { return le_word(sect_total_size_); }
|
||||
void set_sect_total_size(uint32_t size) { sect_total_size_ = le_word(size); }
|
||||
|
||||
uint32_t sect_header_offset() const { return le_word(sect_header_offset_); }
|
||||
void set_sect_header_offset(uint32_t offset) { sect_header_offset_ = le_word(offset); }
|
||||
|
||||
uint16_t sect_num() const { return le_hword(sect_num_); }
|
||||
void set_sect_num(uint16_t num) { sect_num_ = num; }
|
||||
|
||||
uint16_t sect_entry_size() const { return le_hword(sect_entry_size_); }
|
||||
void set_sect_entry_size(uint16_t size) { sect_entry_size_ = le_hword(size); }
|
||||
char issuer[kIssuerLen];
|
||||
byte_t enc_title_key[kEncTitleKeyLen];
|
||||
byte_t format_version;
|
||||
byte_t title_key_enc_type;
|
||||
le_uint16_t ticket_version;
|
||||
byte_t license_type;
|
||||
byte_t common_key_id;
|
||||
byte_t property_mask;
|
||||
byte_t reserved_0;
|
||||
byte_t reserved_region[kReservedRegionLen]; // explicitly reserved
|
||||
le_uint64_t ticket_id;
|
||||
le_uint64_t device_id;
|
||||
byte_t rights_id[kRightsIdLen];
|
||||
le_uint32_t account_id;
|
||||
le_uint32_t sect_total_size;
|
||||
le_uint32_t sect_header_offset;
|
||||
le_uint16_t sect_num;
|
||||
le_uint16_t sect_entry_size;
|
||||
|
||||
};
|
||||
#pragma pack (pop)
|
||||
|
||||
|
|
|
@ -23,21 +23,21 @@ namespace es
|
|||
static const uint16_t kGroupMask = 0xFC00;
|
||||
static const uint16_t kAccessMaskMask = 0x3FF;
|
||||
|
||||
uint32_t group_;
|
||||
byte_t access_mask_[kAccessMaskSize];
|
||||
be_uint32_t group;
|
||||
byte_t access_mask[kAccessMaskSize];
|
||||
public:
|
||||
uint32_t index_group() const { return be_word(group_); }
|
||||
uint32_t index_group() const { return group.get(); }
|
||||
bool is_index_enabled(uint16_t index) const
|
||||
{
|
||||
return (index_group() == get_group(index)) \
|
||||
&& ((access_mask_[get_access_mask(index) / 8] & BIT(get_access_mask(index) % 8)) != 0);
|
||||
&& ((access_mask[get_access_mask(index) / 8] & BIT(get_access_mask(index) % 8)) != 0);
|
||||
}
|
||||
|
||||
void clear() { memset(this, 0, sizeof(sContentRecord_v1)); }
|
||||
|
||||
void set_index_group(uint16_t index) { group_ = be_hword(get_group(index)); }
|
||||
void enable_index(uint16_t index) { access_mask_[get_access_mask(index) / 8] |= BIT(get_access_mask(index) % 8); }
|
||||
void disable_index(uint16_t index) { access_mask_[get_access_mask(index) / 8] &= ~BIT(get_access_mask(index) % 8); }
|
||||
void set_index_group(uint16_t index) { group = get_group(index); }
|
||||
void enable_index(uint16_t index) { access_mask[get_access_mask(index) / 8] |= BIT(get_access_mask(index) % 8); }
|
||||
void disable_index(uint16_t index) { access_mask[get_access_mask(index) / 8] &= ~BIT(get_access_mask(index) % 8); }
|
||||
|
||||
inline uint16_t get_access_mask(uint16_t index) const { return index & kAccessMaskMask; }
|
||||
inline uint16_t get_group(uint16_t index) const { return index & kGroupMask; }
|
||||
|
|
|
@ -58,27 +58,11 @@ namespace es
|
|||
#pragma pack (push, 1)
|
||||
struct sSectionHeader_v2
|
||||
{
|
||||
private:
|
||||
uint32_t section_offset_;
|
||||
uint32_t record_size_;
|
||||
uint32_t section_size_;
|
||||
uint16_t record_num_;
|
||||
uint16_t section_type_;
|
||||
public:
|
||||
uint32_t section_offset() const { return le_word(section_offset_); }
|
||||
void set_section_offset(uint32_t offset) { section_offset_ = le_word(offset); }
|
||||
|
||||
uint32_t record_size() const { return le_word(record_size_); }
|
||||
void set_record_size(uint32_t size) { record_size_ = le_word(size); }
|
||||
|
||||
uint32_t section_size() const { return le_word(section_size_); }
|
||||
void set_section_size(uint32_t size) { section_size_ = le_word(size); }
|
||||
|
||||
uint16_t record_num() const { return le_hword(record_num_); }
|
||||
void set_record_num(uint16_t num) { record_num_ = le_hword(num); }
|
||||
|
||||
uint16_t section_type() const { return le_hword(section_type_); }
|
||||
void set_section_type(uint16_t type) { section_type_ = le_hword(type); }
|
||||
le_uint32_t section_offset;
|
||||
le_uint32_t record_size;
|
||||
le_uint32_t section_size;
|
||||
le_uint16_t record_num;
|
||||
le_uint16_t section_type;
|
||||
};
|
||||
#pragma pack (pop)
|
||||
|
||||
|
|
|
@ -97,26 +97,26 @@ void es::ETicketBody_V2::exportBinary()
|
|||
mBinaryBlob.alloc(sizeof(sTicketBody_v2));
|
||||
sTicketBody_v2* body = (sTicketBody_v2*)mBinaryBlob.getBytes();
|
||||
|
||||
body->set_format_version(kFormatVersion);
|
||||
body->format_version = (kFormatVersion);
|
||||
|
||||
body->set_issuer(mIssuer.c_str());
|
||||
body->set_enc_title_key(mEncTitleKey, kEncTitleKeyLen);
|
||||
body->set_title_key_enc_type(mEncType);
|
||||
body->set_ticket_version(mTicketVersion);
|
||||
strncmp(body->issuer, mIssuer.c_str(), kIssuerLen);
|
||||
memcpy(body->enc_title_key, mEncTitleKey, kEncTitleKeyLen);
|
||||
body->title_key_enc_type = (mEncType);
|
||||
body->ticket_version = (mTicketVersion);
|
||||
byte_t property_mask = 0;
|
||||
property_mask |= mPreInstall ? BIT(FLAG_PRE_INSTALL) : 0;
|
||||
property_mask |= mSharedTitle ? BIT(FLAG_SHARED_TITLE) : 0;
|
||||
property_mask |= mAllowAllContent ? BIT(FLAG_ALLOW_ALL_CONTENT) : 0;
|
||||
body->set_property_mask(property_mask);
|
||||
body->set_reserved_region(mReservedRegion, kReservedRegionLen);
|
||||
body->set_ticket_id(mTicketId);
|
||||
body->set_device_id(mDeviceId);
|
||||
body->set_rights_id(mRightsId);
|
||||
body->set_account_id(mAccountId);
|
||||
body->set_sect_total_size(mSectTotalSize);
|
||||
body->set_sect_header_offset(mSectHeaderOffset);
|
||||
body->set_sect_num(mSectNum);
|
||||
body->set_sect_entry_size(mSectEntrySize);
|
||||
body->property_mask = (property_mask);
|
||||
memcpy(body->reserved_region, mReservedRegion, kReservedRegionLen);
|
||||
body->ticket_id = (mTicketId);
|
||||
body->device_id = (mDeviceId);
|
||||
memcmp(body->rights_id, mRightsId, kRightsIdLen);
|
||||
body->account_id = (mAccountId);
|
||||
body->sect_total_size = (mSectTotalSize);
|
||||
body->sect_header_offset = (mSectHeaderOffset);
|
||||
body->sect_num = (mSectNum);
|
||||
body->sect_entry_size = (mSectEntrySize);
|
||||
}
|
||||
|
||||
void es::ETicketBody_V2::importBinary(const byte_t * bytes, size_t len)
|
||||
|
@ -132,28 +132,28 @@ void es::ETicketBody_V2::importBinary(const byte_t * bytes, size_t len)
|
|||
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
||||
sTicketBody_v2* body = (sTicketBody_v2*)mBinaryBlob.getBytes();
|
||||
|
||||
if (body->format_version() != kFormatVersion)
|
||||
if (body->format_version != kFormatVersion)
|
||||
{
|
||||
throw fnd::Exception(kModuleName, "Unsupported format version");
|
||||
}
|
||||
|
||||
mIssuer.append(body->issuer(), kIssuerLen);
|
||||
memcpy(mEncTitleKey, body->enc_title_key(), kEncTitleKeyLen);
|
||||
mEncType = (TitleKeyEncType)body->title_key_enc_type();
|
||||
mTicketVersion = body->ticket_version();
|
||||
mLicenseType = (LicenseType)body->license_type();
|
||||
mPreInstall = (body->property_mask() & BIT(FLAG_PRE_INSTALL)) == BIT(FLAG_PRE_INSTALL);
|
||||
mSharedTitle = (body->property_mask() & BIT(FLAG_SHARED_TITLE)) == BIT(FLAG_SHARED_TITLE);
|
||||
mAllowAllContent = (body->property_mask() & BIT(FLAG_ALLOW_ALL_CONTENT)) == BIT(FLAG_ALLOW_ALL_CONTENT);
|
||||
memcpy(mReservedRegion, body->reserved_region(), kReservedRegionLen);
|
||||
mTicketId = body->ticket_id();
|
||||
mDeviceId = body->device_id();
|
||||
memcpy(mRightsId, body->rights_id(), kRightsIdLen);
|
||||
mAccountId = body->account_id();
|
||||
mSectTotalSize = body->sect_total_size();
|
||||
mSectHeaderOffset = body->sect_header_offset();
|
||||
mSectNum = body->sect_num();
|
||||
mSectEntrySize = body->sect_entry_size();
|
||||
mIssuer.append(body->issuer, kIssuerLen);
|
||||
memcpy(mEncTitleKey, body->enc_title_key, kEncTitleKeyLen);
|
||||
mEncType = (TitleKeyEncType)body->title_key_enc_type;
|
||||
mTicketVersion = body->ticket_version.get();
|
||||
mLicenseType = (LicenseType)body->license_type;
|
||||
mPreInstall = (body->property_mask & BIT(FLAG_PRE_INSTALL)) == BIT(FLAG_PRE_INSTALL);
|
||||
mSharedTitle = (body->property_mask & BIT(FLAG_SHARED_TITLE)) == BIT(FLAG_SHARED_TITLE);
|
||||
mAllowAllContent = (body->property_mask & BIT(FLAG_ALLOW_ALL_CONTENT)) == BIT(FLAG_ALLOW_ALL_CONTENT);
|
||||
memcpy(mReservedRegion, body->reserved_region, kReservedRegionLen);
|
||||
mTicketId = body->ticket_id.get();
|
||||
mDeviceId = body->device_id.get();
|
||||
memcpy(mRightsId, body->rights_id, kRightsIdLen);
|
||||
mAccountId = body->account_id.get();
|
||||
mSectTotalSize = body->sect_total_size.get();
|
||||
mSectHeaderOffset = body->sect_header_offset.get();
|
||||
mSectNum = body->sect_num.get();
|
||||
mSectEntrySize = body->sect_entry_size.get();
|
||||
}
|
||||
|
||||
void es::ETicketBody_V2::clear()
|
||||
|
|
|
@ -45,11 +45,11 @@ void es::ETicketSectionHeader_V2::exportBinary()
|
|||
mBinaryBlob.alloc(sizeof(sSectionHeader_v2));
|
||||
sSectionHeader_v2* hdr = (sSectionHeader_v2*)mBinaryBlob.getBytes();
|
||||
|
||||
hdr->set_section_offset(mSectionOffset);
|
||||
hdr->set_record_size(mRecordSize);
|
||||
hdr->set_section_size(mSectionSize);
|
||||
hdr->set_record_num(mRecordNum);
|
||||
hdr->set_section_type(mSectionType);
|
||||
hdr->section_offset = (mSectionOffset);
|
||||
hdr->record_size = (mRecordSize);
|
||||
hdr->section_size = (mSectionSize);
|
||||
hdr->record_num = (mRecordNum);
|
||||
hdr->section_type = (mSectionType);
|
||||
}
|
||||
|
||||
void es::ETicketSectionHeader_V2::importBinary(const byte_t * bytes, size_t len)
|
||||
|
@ -65,11 +65,11 @@ void es::ETicketSectionHeader_V2::importBinary(const byte_t * bytes, size_t len)
|
|||
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
||||
sSectionHeader_v2* hdr = (sSectionHeader_v2*)mBinaryBlob.getBytes();
|
||||
|
||||
mSectionOffset = hdr->section_offset();
|
||||
mRecordSize = hdr->record_size();
|
||||
mSectionSize = hdr->section_size();
|
||||
mRecordNum = hdr->record_num();
|
||||
mSectionType = (SectionType)hdr->section_type();
|
||||
mSectionOffset = hdr->section_offset.get();
|
||||
mRecordSize = hdr->record_size.get();
|
||||
mSectionSize = hdr->section_size.get();
|
||||
mRecordNum = hdr->record_num.get();
|
||||
mSectionType = (SectionType)hdr->section_type.get();
|
||||
}
|
||||
|
||||
bool es::ETicketSectionHeader_V2::isEqual(const ETicketSectionHeader_V2 & other) const
|
||||
|
|
Loading…
Reference in a new issue