Skip to content

Commit

Permalink
Fix a version issue in ACBPv2 definition file
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajSchlej committed Sep 10, 2022
1 parent a9c6f34 commit c4ca232
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
18 changes: 7 additions & 11 deletions common/fitparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,10 @@ USTATUS FitParser::parseFitEntryMicrocode(const UByteArray & microcode, const UI

USTATUS FitParser::parseFitEntryAcm(const UByteArray & acm, const UINT32 localOffset, const UModelIndex & parent, UString & info, UINT32 &realSize)
{
// Parse Intel ACM using Kaitai-generated parser
// TODO: need to do something with the copy here, probably implement a custom wrapper
std::istringstream is(std::string(acm.constData(), acm.size()));
is.seekg(localOffset, is.beg);
kaitai::kstream ks(&is);
try {
std::istringstream is(std::string(acm.constData(), acm.size()));
is.seekg(localOffset, is.beg);
kaitai::kstream ks(&is);
intel_acm_t parsed(&ks);
intel_acm_t::header_t* header = parsed.header();

Expand Down Expand Up @@ -396,11 +394,9 @@ USTATUS FitParser::parseFitEntryBootGuardKeyManifest(const UByteArray & keyManif
{
U_UNUSED_PARAMETER(realSize);

// TODO: need to do something with the copy here, probably implement a custom wrapper
std::istringstream is(std::string(keyManifest.constData(), keyManifest.size()));

// v1
try {
std::istringstream is(std::string(keyManifest.constData(), keyManifest.size()));
is.seekg(localOffset, is.beg);
kaitai::kstream ks(&is);
intel_keym_v1_t parsed(&ks);
Expand Down Expand Up @@ -469,6 +465,7 @@ USTATUS FitParser::parseFitEntryBootGuardKeyManifest(const UByteArray & keyManif

// v2
try {
std::istringstream is(std::string(keyManifest.constData(), keyManifest.size()));
is.seekg(localOffset, is.beg);
kaitai::kstream ks(&is);
intel_keym_v2_t parsed(&ks);
Expand Down Expand Up @@ -564,11 +561,9 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic
{
U_UNUSED_PARAMETER(realSize);

// TODO: need to do something with the copy here, probably implement a custom wrapper
std::istringstream is(std::string(bootPolicy.constData(), bootPolicy.size()));

// v1
try {
std::istringstream is(std::string(bootPolicy.constData(), bootPolicy.size()));
is.seekg(localOffset, is.beg);
kaitai::kstream ks(&is);
intel_acbp_v1_t parsed(&ks);
Expand Down Expand Up @@ -826,6 +821,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic

// v2
try {
std::istringstream is(std::string(bootPolicy.constData(), bootPolicy.size()));
is.seekg(localOffset, is.beg);
kaitai::kstream ks(&is);
intel_acbp_v2_t parsed(&ks); // This already verified the version to be >= 0x20
Expand Down
6 changes: 3 additions & 3 deletions common/generated/intel_acbp_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ void intel_acbp_v2_t::pmda_entry_v3_t::_read() {
m_size = m__io->read_u4le();
m_total_entry_size = m__io->read_u2le();
m_version = m__io->read_u2le();
if (!(version() == 3)) {
throw kaitai::validation_not_equal_error<uint16_t>(3, version(), _io(), std::string("/types/pmda_entry_v3/seq/4"));
}
m_hash = new hash_t(m__io, this, m__root);
}

Expand Down Expand Up @@ -421,6 +418,9 @@ void intel_acbp_v2_t::pmda_body_t::_read() {
m_reserved = m__io->read_u2le();
m_total_size = m__io->read_u2le();
m_version = m__io->read_u4le();
if (!(version() == 3)) {
throw kaitai::validation_not_equal_error<uint32_t>(3, version(), _io(), std::string("/types/pmda_body/seq/2"));
}
m_num_entries = m__io->read_u4le();
m_entries = new std::vector<pmda_entry_v3_t*>();
const int l_entries = num_entries();
Expand Down
2 changes: 1 addition & 1 deletion common/ksy/intel_acbp_v2.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ types:
type: u2
- id: version
type: u2
valid: 3
- id: hash
type: hash

Expand All @@ -102,6 +101,7 @@ types:
type: u2
- id: version
type: u4
valid: 3
- id: num_entries
type: u4
- id: entries
Expand Down

0 comments on commit c4ca232

Please sign in to comment.