From c4ca232b3a85ce9272a350b9eb29e857a783d230 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Sat, 10 Sep 2022 16:08:06 +0200 Subject: [PATCH] Fix a version issue in ACBPv2 definition file --- common/fitparser.cpp | 18 +++++++----------- common/generated/intel_acbp_v2.cpp | 6 +++--- common/ksy/intel_acbp_v2.ksy | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/common/fitparser.cpp b/common/fitparser.cpp index 1bdf0d7..62a4429 100644 --- a/common/fitparser.cpp +++ b/common/fitparser.cpp @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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 diff --git a/common/generated/intel_acbp_v2.cpp b/common/generated/intel_acbp_v2.cpp index 2684f9d..c7cabd6 100644 --- a/common/generated/intel_acbp_v2.cpp +++ b/common/generated/intel_acbp_v2.cpp @@ -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(3, version(), _io(), std::string("/types/pmda_entry_v3/seq/4")); - } m_hash = new hash_t(m__io, this, m__root); } @@ -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(3, version(), _io(), std::string("/types/pmda_body/seq/2")); + } m_num_entries = m__io->read_u4le(); m_entries = new std::vector(); const int l_entries = num_entries(); diff --git a/common/ksy/intel_acbp_v2.ksy b/common/ksy/intel_acbp_v2.ksy index 2782bdd..ce98e54 100644 --- a/common/ksy/intel_acbp_v2.ksy +++ b/common/ksy/intel_acbp_v2.ksy @@ -90,7 +90,6 @@ types: type: u2 - id: version type: u2 - valid: 3 - id: hash type: hash @@ -102,6 +101,7 @@ types: type: u2 - id: version type: u4 + valid: 3 - id: num_entries type: u4 - id: entries