From 75bf036137fdc09562cc1832d112e6d4bb741efc Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Sun, 26 Feb 2023 13:23:25 -0800 Subject: [PATCH] Switch to C++11 for Kaitai-generated parsers --- common/fitparser.cpp | 22 ++- common/generated/ami_nvar.cpp | 114 ++++----------- common/generated/ami_nvar.h | 44 +++--- common/generated/intel_acbp_v1.cpp | 216 ++++++----------------------- common/generated/intel_acbp_v1.h | 86 ++++++------ common/generated/intel_acbp_v2.cpp | 208 ++++++--------------------- common/generated/intel_acbp_v2.h | 84 ++++++----- common/generated/intel_acm.cpp | 23 +-- common/generated/intel_acm.h | 14 +- common/generated/intel_keym_v1.cpp | 68 ++------- common/generated/intel_keym_v1.h | 32 ++--- common/generated/intel_keym_v2.cpp | 97 +++---------- common/generated/intel_keym_v2.h | 42 +++--- common/nvramparser.cpp | 2 +- kaitai_regenerate.sh | 9 +- 15 files changed, 316 insertions(+), 745 deletions(-) diff --git a/common/fitparser.cpp b/common/fitparser.cpp index 322a381..641d07f 100644 --- a/common/fitparser.cpp +++ b/common/fitparser.cpp @@ -541,7 +541,7 @@ USTATUS FitParser::parseFitEntryBootGuardKeyManifest(const UByteArray & keyManif else { kmInfo += UString("KM Hashes:\n"); for (UINT16 i = 0; i < parsed.num_km_hashes(); i++) { - intel_keym_v2_t::km_hash_t* current_km_hash = parsed.km_hashes()->at(i); + const auto & current_km_hash = parsed.km_hashes()->at(i); // Add KM hash kmInfo += usprintf("UsageFlags: %016" PRIX64 "h, ", current_km_hash->usage_flags()) + hashTypeToUString(current_km_hash->hash_algorithm_id()) + ": "; @@ -660,9 +660,8 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic parsed.nem_data_size()); bpInfo += UString("Boot Policy Elements:\n"); - const std::vector* elements = parsed.elements(); - for (intel_acbp_v1_t::acbp_element_t* element : *elements) { - const intel_acbp_v1_t::common_header_t* element_header = element->header(); + for (const auto & element : *parsed.elements()) { + const auto & element_header = element->header(); UINT64 structure_id = (UINT64) element_header->structure_id(); const char* structure_id_bytes = (const char*)&structure_id; @@ -742,7 +741,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic else { bpInfo += UString("IBB Segments:\n"); for (UINT8 i = 0; i < ibbs_body->num_ibb_segments(); i++) { - const intel_acbp_v1_t::ibb_segment_t* current_segment = ibbs_body->ibb_segments()->at(i); + const auto & current_segment = ibbs_body->ibb_segments()->at(i); bpInfo += usprintf("Flags: %04Xh, Address: %08Xh, Size: %08Xh\n", current_segment->flags(), @@ -780,7 +779,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic // v1 entries if (pmda_body->_is_null_entries_v1() == false) { for (UINT32 i = 0; i < pmda_body->num_entries(); i++) { - const intel_acbp_v1_t::pmda_entry_v1_t* current_element = pmda_body->entries_v1()->at(i); + const auto & current_element = pmda_body->entries_v1()->at(i); // Add element bpInfo += usprintf("Address: %08Xh, Size: %08Xh\n", @@ -809,7 +808,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic // v2 entries else if (pmda_body->_is_null_entries_v2() == false) { for (UINT32 i = 0; i < pmda_body->num_entries(); i++) { - const intel_acbp_v1_t::pmda_entry_v2_t* current_element = pmda_body->entries_v2()->at(i); + const auto & current_element = pmda_body->entries_v2()->at(i); // Add element bpInfo += usprintf("Address: %08Xh, Size: %08Xh\n", @@ -930,8 +929,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic parsed.nem_data_size()); bpInfo += UString("Boot Policy Elements:\n"); - const std::vector* elements = parsed.elements(); - for (intel_acbp_v2_t::acbp_element_t* element : *elements) { + for (const auto & element : *parsed.elements()) { const intel_acbp_v2_t::header_t* element_header = element->header(); UINT64 structure_id = element_header->structure_id(); @@ -1041,7 +1039,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic else { bpInfo += UString("IBB Hashes:\n"); for (UINT16 i = 0; i < ibbs_body->num_ibb_digests(); i++) { - const intel_acbp_v2_t::hash_t* current_hash = ibbs_body->ibb_digests()->at(i); + const auto & current_hash = ibbs_body->ibb_digests()->at(i); bpInfo += hashTypeToUString(current_hash->hash_algorithm_id()) + ": "; for (UINT16 j = 0; j < current_hash->len_hash(); j++) { bpInfo += usprintf("%02X", (UINT8)current_hash->hash().data()[j]); @@ -1058,7 +1056,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic else { bpInfo += UString("IBB Segments:\n"); for (UINT8 i = 0; i < ibbs_body->num_ibb_segments(); i++) { - const intel_acbp_v2_t::ibb_segment_t* current_segment = ibbs_body->ibb_segments()->at(i); + const auto & current_segment = ibbs_body->ibb_segments()->at(i); bpInfo += usprintf("Flags: %04Xh, Address: %08Xh, Size: %08Xh\n", current_segment->flags(), @@ -1095,7 +1093,7 @@ USTATUS FitParser::parseFitEntryBootGuardBootPolicy(const UByteArray & bootPolic else { bpInfo += UString("PMDA Entries:\n"); for (UINT32 i = 0; i < pmda_body->num_entries(); i++) { - const intel_acbp_v2_t::pmda_entry_v3_t* current_entry = pmda_body->entries()->at(i); + const auto & current_entry = pmda_body->entries()->at(i); UINT64 entry_id = current_entry->entry_id(); const char* entry_id_bytes = (const char*)&entry_id; diff --git a/common/generated/ami_nvar.cpp b/common/generated/ami_nvar.cpp index 28441a2..edd42d0 100644 --- a/common/generated/ami_nvar.cpp +++ b/common/generated/ami_nvar.cpp @@ -6,24 +6,18 @@ ami_nvar_t::ami_nvar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = this; (void)p__root; - m_entries = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_entries = nullptr; + _read(); } void ami_nvar_t::_read() { - m_entries = new std::vector(); + m_entries = std::unique_ptr>>(new std::vector>()); { int i = 0; nvar_entry_t* _; do { _ = new nvar_entry_t(m__io, this, m__root); - m_entries->push_back(_); + m_entries->push_back(std::move(std::unique_ptr(_))); i++; } while (!( ((_->signature_first() != 78) || (_io()->is_eof())) )); } @@ -34,24 +28,12 @@ ami_nvar_t::~ami_nvar_t() { } void ami_nvar_t::_clean_up() { - if (m_entries) { - for (std::vector::iterator it = m_entries->begin(); it != m_entries->end(); ++it) { - delete *it; - } - delete m_entries; m_entries = 0; - } } ami_nvar_t::nvar_attributes_t::nvar_attributes_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_t* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void ami_nvar_t::nvar_attributes_t::_read() { @@ -75,18 +57,12 @@ void ami_nvar_t::nvar_attributes_t::_clean_up() { ami_nvar_t::ucs2_string_t::ucs2_string_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_body_t* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_ucs2_chars = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_ucs2_chars = nullptr; + _read(); } void ami_nvar_t::ucs2_string_t::_read() { - m_ucs2_chars = new std::vector(); + m_ucs2_chars = std::unique_ptr>(new std::vector()); { int i = 0; uint16_t _; @@ -103,21 +79,12 @@ ami_nvar_t::ucs2_string_t::~ucs2_string_t() { } void ami_nvar_t::ucs2_string_t::_clean_up() { - if (m_ucs2_chars) { - delete m_ucs2_chars; m_ucs2_chars = 0; - } } ami_nvar_t::nvar_extended_attributes_t::nvar_extended_attributes_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_body_t* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void ami_nvar_t::nvar_extended_attributes_t::_read() { @@ -138,18 +105,12 @@ void ami_nvar_t::nvar_extended_attributes_t::_clean_up() { ami_nvar_t::nvar_entry_t::nvar_entry_t(kaitai::kstream* p__io, ami_nvar_t* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_attributes = 0; - m_body = 0; - m__io__raw_body = 0; + m_attributes = nullptr; + m_body = nullptr; + m__io__raw_body = nullptr; f_offset = false; f_end_offset = false; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void ami_nvar_t::nvar_entry_t::_read() { @@ -187,14 +148,14 @@ void ami_nvar_t::nvar_entry_t::_read() { n_attributes = true; if (signature_first() == 78) { n_attributes = false; - m_attributes = new nvar_attributes_t(m__io, this, m__root); + m_attributes = std::unique_ptr(new nvar_attributes_t(m__io, this, m__root)); } n_body = true; if (signature_first() == 78) { n_body = false; m__raw_body = m__io->read_bytes((size() - ((4 + 2) + 4))); - m__io__raw_body = new kaitai::kstream(m__raw_body); - m_body = new nvar_entry_body_t(m__io__raw_body, this, m__root); + m__io__raw_body = std::unique_ptr(new kaitai::kstream(m__raw_body)); + m_body = std::unique_ptr(new nvar_entry_body_t(m__io__raw_body.get(), this, m__root)); } n_invoke_end_offset = true; if ( ((signature_first() == 78) && (end_offset() >= 0)) ) { @@ -217,17 +178,8 @@ void ami_nvar_t::nvar_entry_t::_clean_up() { if (!n_next) { } if (!n_attributes) { - if (m_attributes) { - delete m_attributes; m_attributes = 0; - } } if (!n_body) { - if (m__io__raw_body) { - delete m__io__raw_body; m__io__raw_body = 0; - } - if (m_body) { - delete m_body; m_body = 0; - } } if (!n_invoke_end_offset) { } @@ -236,7 +188,7 @@ void ami_nvar_t::nvar_entry_t::_clean_up() { int32_t ami_nvar_t::nvar_entry_t::offset() { if (f_offset) return m_offset; - m_offset = _io()->pos(); + m_offset = (int32_t)_io()->pos(); f_offset = true; return m_offset; } @@ -244,7 +196,7 @@ int32_t ami_nvar_t::nvar_entry_t::offset() { int32_t ami_nvar_t::nvar_entry_t::end_offset() { if (f_end_offset) return m_end_offset; - m_end_offset = _io()->pos(); + m_end_offset = (int32_t)_io()->pos(); f_end_offset = true; return m_end_offset; } @@ -252,8 +204,8 @@ int32_t ami_nvar_t::nvar_entry_t::end_offset() { ami_nvar_t::nvar_entry_body_t::nvar_entry_body_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_t* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_ucs2_name = 0; - m_extended_header_attributes = 0; + m_ucs2_name = nullptr; + m_extended_header_attributes = nullptr; f_extended_header_attributes = false; f_data_start_offset = false; f_extended_header_size_field = false; @@ -263,13 +215,7 @@ ami_nvar_t::nvar_entry_body_t::nvar_entry_body_t(kaitai::kstream* p__io, ami_nva f_data_end_offset = false; f_extended_header_size = false; f_extended_header_hash = false; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void ami_nvar_t::nvar_entry_body_t::_read() { @@ -291,7 +237,7 @@ void ami_nvar_t::nvar_entry_body_t::_read() { n_ucs2_name = true; if ( ((!(_parent()->attributes()->ascii_name())) && (!(_parent()->attributes()->data_only())) && (_parent()->attributes()->valid())) ) { n_ucs2_name = false; - m_ucs2_name = new ucs2_string_t(m__io, this, m__root); + m_ucs2_name = std::unique_ptr(new ucs2_string_t(m__io, this, m__root)); } n_invoke_data_start = true; if (data_start_offset() >= 0) { @@ -313,16 +259,10 @@ void ami_nvar_t::nvar_entry_body_t::_clean_up() { if (!n_ascii_name) { } if (!n_ucs2_name) { - if (m_ucs2_name) { - delete m_ucs2_name; m_ucs2_name = 0; - } } if (!n_invoke_data_start) { } if (f_extended_header_attributes && !n_extended_header_attributes) { - if (m_extended_header_attributes) { - delete m_extended_header_attributes; m_extended_header_attributes = 0; - } } if (f_extended_header_size_field && !n_extended_header_size_field) { } @@ -336,23 +276,23 @@ void ami_nvar_t::nvar_entry_body_t::_clean_up() { ami_nvar_t::nvar_extended_attributes_t* ami_nvar_t::nvar_entry_body_t::extended_header_attributes() { if (f_extended_header_attributes) - return m_extended_header_attributes; + return m_extended_header_attributes.get(); n_extended_header_attributes = true; if ( ((_parent()->attributes()->valid()) && (_parent()->attributes()->extended_header()) && (extended_header_size() >= (1 + 2))) ) { n_extended_header_attributes = false; std::streampos _pos = m__io->pos(); m__io->seek((_io()->pos() - extended_header_size())); - m_extended_header_attributes = new nvar_extended_attributes_t(m__io, this, m__root); + m_extended_header_attributes = std::unique_ptr(new nvar_extended_attributes_t(m__io, this, m__root)); m__io->seek(_pos); f_extended_header_attributes = true; } - return m_extended_header_attributes; + return m_extended_header_attributes.get(); } int32_t ami_nvar_t::nvar_entry_body_t::data_start_offset() { if (f_data_start_offset) return m_data_start_offset; - m_data_start_offset = _io()->pos(); + m_data_start_offset = (int32_t)_io()->pos(); f_data_start_offset = true; return m_data_start_offset; } @@ -413,7 +353,7 @@ uint8_t ami_nvar_t::nvar_entry_body_t::extended_header_checksum() { int32_t ami_nvar_t::nvar_entry_body_t::data_end_offset() { if (f_data_end_offset) return m_data_end_offset; - m_data_end_offset = _io()->pos(); + m_data_end_offset = (int32_t)_io()->pos(); f_data_end_offset = true; return m_data_end_offset; } diff --git a/common/generated/ami_nvar.h b/common/generated/ami_nvar.h index b372835..9469bec 100644 --- a/common/generated/ami_nvar.h +++ b/common/generated/ami_nvar.h @@ -1,10 +1,10 @@ -#ifndef AMI_NVAR_H_ -#define AMI_NVAR_H_ +#pragma once // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild #include "../kaitai/kaitaistruct.h" #include +#include #include #if KAITAI_STRUCT_VERSION < 9000L @@ -20,7 +20,7 @@ public: class nvar_entry_t; class nvar_entry_body_t; - ami_nvar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, ami_nvar_t* p__root = 0); + ami_nvar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, ami_nvar_t* p__root = nullptr); private: void _read(); @@ -33,7 +33,7 @@ public: public: - nvar_attributes_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_t* p__parent = 0, ami_nvar_t* p__root = 0); + nvar_attributes_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_t* p__parent = nullptr, ami_nvar_t* p__root = nullptr); private: void _read(); @@ -71,7 +71,7 @@ public: public: - ucs2_string_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_body_t* p__parent = 0, ami_nvar_t* p__root = 0); + ucs2_string_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_body_t* p__parent = nullptr, ami_nvar_t* p__root = nullptr); private: void _read(); @@ -81,12 +81,12 @@ public: ~ucs2_string_t(); private: - std::vector* m_ucs2_chars; + std::unique_ptr> m_ucs2_chars; ami_nvar_t* m__root; ami_nvar_t::nvar_entry_body_t* m__parent; public: - std::vector* ucs2_chars() const { return m_ucs2_chars; } + std::vector* ucs2_chars() const { return m_ucs2_chars.get(); } ami_nvar_t* _root() const { return m__root; } ami_nvar_t::nvar_entry_body_t* _parent() const { return m__parent; } }; @@ -95,7 +95,7 @@ public: public: - nvar_extended_attributes_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_body_t* p__parent = 0, ami_nvar_t* p__root = 0); + nvar_extended_attributes_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_body_t* p__parent = nullptr, ami_nvar_t* p__root = nullptr); private: void _read(); @@ -127,7 +127,7 @@ public: public: - nvar_entry_t(kaitai::kstream* p__io, ami_nvar_t* p__parent = 0, ami_nvar_t* p__root = 0); + nvar_entry_t(kaitai::kstream* p__io, ami_nvar_t* p__parent = nullptr, ami_nvar_t* p__root = nullptr); private: void _read(); @@ -180,14 +180,14 @@ public: bool _is_null_next() { next(); return n_next; }; private: - nvar_attributes_t* m_attributes; + std::unique_ptr m_attributes; bool n_attributes; public: bool _is_null_attributes() { attributes(); return n_attributes; }; private: - nvar_entry_body_t* m_body; + std::unique_ptr m_body; bool n_body; public: @@ -210,7 +210,7 @@ public: bool _is_null__raw_body() { _raw_body(); return n__raw_body; }; private: - kaitai::kstream* m__io__raw_body; + std::unique_ptr m__io__raw_body; public: std::string invoke_offset() const { return m_invoke_offset; } @@ -218,20 +218,20 @@ public: std::string signature_rest() const { return m_signature_rest; } uint16_t size() const { return m_size; } uint64_t next() const { return m_next; } - nvar_attributes_t* attributes() const { return m_attributes; } - nvar_entry_body_t* body() const { return m_body; } + nvar_attributes_t* attributes() const { return m_attributes.get(); } + nvar_entry_body_t* body() const { return m_body.get(); } std::string invoke_end_offset() const { return m_invoke_end_offset; } ami_nvar_t* _root() const { return m__root; } ami_nvar_t* _parent() const { return m__parent; } std::string _raw_body() const { return m__raw_body; } - kaitai::kstream* _io__raw_body() const { return m__io__raw_body; } + kaitai::kstream* _io__raw_body() const { return m__io__raw_body.get(); } }; class nvar_entry_body_t : public kaitai::kstruct { public: - nvar_entry_body_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_t* p__parent = 0, ami_nvar_t* p__root = 0); + nvar_entry_body_t(kaitai::kstream* p__io, ami_nvar_t::nvar_entry_t* p__parent = nullptr, ami_nvar_t* p__root = nullptr); private: void _read(); @@ -242,7 +242,7 @@ public: private: bool f_extended_header_attributes; - nvar_extended_attributes_t* m_extended_header_attributes; + std::unique_ptr m_extended_header_attributes; bool n_extended_header_attributes; public: @@ -355,7 +355,7 @@ public: bool _is_null_ascii_name() { ascii_name(); return n_ascii_name; }; private: - ucs2_string_t* m_ucs2_name; + std::unique_ptr m_ucs2_name; bool n_ucs2_name; public: @@ -377,7 +377,7 @@ public: uint8_t guid_index() const { return m_guid_index; } std::string guid() const { return m_guid; } std::string ascii_name() const { return m_ascii_name; } - ucs2_string_t* ucs2_name() const { return m_ucs2_name; } + ucs2_string_t* ucs2_name() const { return m_ucs2_name.get(); } std::string invoke_data_start() const { return m_invoke_data_start; } std::string data() const { return m_data; } ami_nvar_t* _root() const { return m__root; } @@ -385,14 +385,12 @@ public: }; private: - std::vector* m_entries; + std::unique_ptr>> m_entries; ami_nvar_t* m__root; kaitai::kstruct* m__parent; public: - std::vector* entries() const { return m_entries; } + std::vector>* entries() const { return m_entries.get(); } ami_nvar_t* _root() const { return m__root; } kaitai::kstruct* _parent() const { return m__parent; } }; - -#endif // AMI_NVAR_H_ diff --git a/common/generated/intel_acbp_v1.cpp b/common/generated/intel_acbp_v1.cpp index 4107fff..92e540e 100644 --- a/common/generated/intel_acbp_v1.cpp +++ b/common/generated/intel_acbp_v1.cpp @@ -6,14 +6,8 @@ intel_acbp_v1_t::intel_acbp_v1_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = this; (void)p__root; - m_elements = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_elements = nullptr; + _read(); } void intel_acbp_v1_t::_read() { @@ -34,13 +28,13 @@ void intel_acbp_v1_t::_read() { m_acm_svn = m__io->read_u1(); m_reserved1 = m__io->read_u1(); m_nem_data_size = m__io->read_u2le(); - m_elements = new std::vector(); + m_elements = std::unique_ptr>>(new std::vector>()); { int i = 0; acbp_element_t* _; do { _ = new acbp_element_t(m__io, this, m__root); - m_elements->push_back(_); + m_elements->push_back(std::move(std::unique_ptr(_))); i++; } while (!( ((_->header()->structure_id() == intel_acbp_v1_t::STRUCTURE_IDS_PMSG) || (_io()->is_eof())) )); } @@ -51,34 +45,22 @@ intel_acbp_v1_t::~intel_acbp_v1_t() { } void intel_acbp_v1_t::_clean_up() { - if (m_elements) { - for (std::vector::iterator it = m_elements->begin(); it != m_elements->end(); ++it) { - delete *it; - } - delete m_elements; m_elements = 0; - } } intel_acbp_v1_t::pmsg_body_t::pmsg_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_public_key = 0; - m_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_public_key = nullptr; + m_signature = nullptr; + _read(); } void intel_acbp_v1_t::pmsg_body_t::_read() { m_version = m__io->read_u1(); m_key_id = m__io->read_u2le(); - m_public_key = new public_key_t(m__io, this, m__root); + m_public_key = std::unique_ptr(new public_key_t(m__io, this, m__root)); m_sig_scheme = m__io->read_u2le(); - m_signature = new signature_t(m__io, this, m__root); + m_signature = std::unique_ptr(new signature_t(m__io, this, m__root)); } intel_acbp_v1_t::pmsg_body_t::~pmsg_body_t() { @@ -86,46 +68,34 @@ intel_acbp_v1_t::pmsg_body_t::~pmsg_body_t() { } void intel_acbp_v1_t::pmsg_body_t::_clean_up() { - if (m_public_key) { - delete m_public_key; m_public_key = 0; - } - if (m_signature) { - delete m_signature; m_signature = 0; - } } intel_acbp_v1_t::acbp_element_t::acbp_element_t(kaitai::kstream* p__io, intel_acbp_v1_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_header = 0; - m_ibbs_body = 0; - m_pmda_body = 0; - m_pmsg_body = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_header = nullptr; + m_ibbs_body = nullptr; + m_pmda_body = nullptr; + m_pmsg_body = nullptr; + _read(); } void intel_acbp_v1_t::acbp_element_t::_read() { - m_header = new common_header_t(m__io, this, m__root); + m_header = std::unique_ptr(new common_header_t(m__io, this, m__root)); n_ibbs_body = true; if (header()->structure_id() == intel_acbp_v1_t::STRUCTURE_IDS_IBBS) { n_ibbs_body = false; - m_ibbs_body = new ibbs_body_t(m__io, this, m__root); + m_ibbs_body = std::unique_ptr(new ibbs_body_t(m__io, this, m__root)); } n_pmda_body = true; if (header()->structure_id() == intel_acbp_v1_t::STRUCTURE_IDS_PMDA) { n_pmda_body = false; - m_pmda_body = new pmda_body_t(m__io, this, m__root); + m_pmda_body = std::unique_ptr(new pmda_body_t(m__io, this, m__root)); } n_pmsg_body = true; if (header()->structure_id() == intel_acbp_v1_t::STRUCTURE_IDS_PMSG) { n_pmsg_body = false; - m_pmsg_body = new pmsg_body_t(m__io, this, m__root); + m_pmsg_body = std::unique_ptr(new pmsg_body_t(m__io, this, m__root)); } n_invalid_body = true; if ( ((header()->structure_id() != intel_acbp_v1_t::STRUCTURE_IDS_PMSG) && (header()->structure_id() != intel_acbp_v1_t::STRUCTURE_IDS_PMDA) && (header()->structure_id() != intel_acbp_v1_t::STRUCTURE_IDS_IBBS)) ) { @@ -145,23 +115,11 @@ intel_acbp_v1_t::acbp_element_t::~acbp_element_t() { } void intel_acbp_v1_t::acbp_element_t::_clean_up() { - if (m_header) { - delete m_header; m_header = 0; - } if (!n_ibbs_body) { - if (m_ibbs_body) { - delete m_ibbs_body; m_ibbs_body = 0; - } } if (!n_pmda_body) { - if (m_pmda_body) { - delete m_pmda_body; m_pmda_body = 0; - } } if (!n_pmsg_body) { - if (m_pmsg_body) { - delete m_pmsg_body; m_pmsg_body = 0; - } } if (!n_invalid_body) { } @@ -170,13 +128,7 @@ void intel_acbp_v1_t::acbp_element_t::_clean_up() { intel_acbp_v1_t::common_header_t::common_header_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v1_t::common_header_t::_read() { @@ -194,13 +146,7 @@ void intel_acbp_v1_t::common_header_t::_clean_up() { intel_acbp_v1_t::signature_t::signature_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmsg_body_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v1_t::signature_t::_read() { @@ -220,13 +166,7 @@ void intel_acbp_v1_t::signature_t::_clean_up() { intel_acbp_v1_t::pmda_entry_v1_t::pmda_entry_v1_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmda_body_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v1_t::pmda_entry_v1_t::_read() { @@ -245,13 +185,7 @@ void intel_acbp_v1_t::pmda_entry_v1_t::_clean_up() { intel_acbp_v1_t::ibb_segment_t::ibb_segment_t(kaitai::kstream* p__io, intel_acbp_v1_t::ibbs_body_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v1_t::ibb_segment_t::_read() { @@ -271,13 +205,7 @@ void intel_acbp_v1_t::ibb_segment_t::_clean_up() { intel_acbp_v1_t::public_key_t::public_key_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmsg_body_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v1_t::public_key_t::_read() { @@ -297,13 +225,7 @@ void intel_acbp_v1_t::public_key_t::_clean_up() { intel_acbp_v1_t::hash_t::hash_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v1_t::hash_t::_read() { @@ -322,20 +244,14 @@ void intel_acbp_v1_t::hash_t::_clean_up() { intel_acbp_v1_t::pmda_entry_v2_t::pmda_entry_v2_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmda_body_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_hash = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_hash = nullptr; + _read(); } void intel_acbp_v1_t::pmda_entry_v2_t::_read() { m_base = m__io->read_u4le(); m_size = m__io->read_u4le(); - m_hash = new hash_t(m__io, this, m__root); + m_hash = std::unique_ptr(new hash_t(m__io, this, m__root)); } intel_acbp_v1_t::pmda_entry_v2_t::~pmda_entry_v2_t() { @@ -343,32 +259,23 @@ intel_acbp_v1_t::pmda_entry_v2_t::~pmda_entry_v2_t() { } void intel_acbp_v1_t::pmda_entry_v2_t::_clean_up() { - if (m_hash) { - delete m_hash; m_hash = 0; - } } intel_acbp_v1_t::ibbs_body_t::ibbs_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_reserved = 0; - m_post_ibb_hash = 0; - m_ibb_hash = 0; - m_ibb_segments = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_reserved = nullptr; + m_post_ibb_hash = nullptr; + m_ibb_hash = nullptr; + m_ibb_segments = nullptr; + _read(); } void intel_acbp_v1_t::ibbs_body_t::_read() { - m_reserved = new std::vector(); + m_reserved = std::unique_ptr>(new std::vector()); const int l_reserved = 3; for (int i = 0; i < l_reserved; i++) { - m_reserved->push_back(m__io->read_u1()); + m_reserved->push_back(std::move(m__io->read_u1())); } m_flags = m__io->read_u4le(); m_mch_bar = m__io->read_u8le(); @@ -377,14 +284,14 @@ void intel_acbp_v1_t::ibbs_body_t::_read() { m_dma_protection_limit0 = m__io->read_u4le(); m_dma_protection_base1 = m__io->read_u8le(); m_dma_protection_limit1 = m__io->read_u8le(); - m_post_ibb_hash = new hash_t(m__io, this, m__root); + m_post_ibb_hash = std::unique_ptr(new hash_t(m__io, this, m__root)); m_ibb_entry_point = m__io->read_u4le(); - m_ibb_hash = new hash_t(m__io, this, m__root); + m_ibb_hash = std::unique_ptr(new hash_t(m__io, this, m__root)); m_num_ibb_segments = m__io->read_u1(); - m_ibb_segments = new std::vector(); + m_ibb_segments = std::unique_ptr>>(new std::vector>()); const int l_ibb_segments = num_ibb_segments(); for (int i = 0; i < l_ibb_segments; i++) { - m_ibb_segments->push_back(new ibb_segment_t(m__io, this, m__root)); + m_ibb_segments->push_back(std::move(std::unique_ptr(new ibb_segment_t(m__io, this, m__root)))); } } @@ -393,35 +300,14 @@ intel_acbp_v1_t::ibbs_body_t::~ibbs_body_t() { } void intel_acbp_v1_t::ibbs_body_t::_clean_up() { - if (m_reserved) { - delete m_reserved; m_reserved = 0; - } - if (m_post_ibb_hash) { - delete m_post_ibb_hash; m_post_ibb_hash = 0; - } - if (m_ibb_hash) { - delete m_ibb_hash; m_ibb_hash = 0; - } - if (m_ibb_segments) { - for (std::vector::iterator it = m_ibb_segments->begin(); it != m_ibb_segments->end(); ++it) { - delete *it; - } - delete m_ibb_segments; m_ibb_segments = 0; - } } intel_acbp_v1_t::pmda_body_t::pmda_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent, intel_acbp_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_entries_v1 = 0; - m_entries_v2 = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_entries_v1 = nullptr; + m_entries_v2 = nullptr; + _read(); } void intel_acbp_v1_t::pmda_body_t::_read() { @@ -431,19 +317,19 @@ void intel_acbp_v1_t::pmda_body_t::_read() { n_entries_v1 = true; if (version() == 1) { n_entries_v1 = false; - m_entries_v1 = new std::vector(); + m_entries_v1 = std::unique_ptr>>(new std::vector>()); const int l_entries_v1 = num_entries(); for (int i = 0; i < l_entries_v1; i++) { - m_entries_v1->push_back(new pmda_entry_v1_t(m__io, this, m__root)); + m_entries_v1->push_back(std::move(std::unique_ptr(new pmda_entry_v1_t(m__io, this, m__root)))); } } n_entries_v2 = true; if (version() == 2) { n_entries_v2 = false; - m_entries_v2 = new std::vector(); + m_entries_v2 = std::unique_ptr>>(new std::vector>()); const int l_entries_v2 = num_entries(); for (int i = 0; i < l_entries_v2; i++) { - m_entries_v2->push_back(new pmda_entry_v2_t(m__io, this, m__root)); + m_entries_v2->push_back(std::move(std::unique_ptr(new pmda_entry_v2_t(m__io, this, m__root)))); } } } @@ -454,19 +340,7 @@ intel_acbp_v1_t::pmda_body_t::~pmda_body_t() { void intel_acbp_v1_t::pmda_body_t::_clean_up() { if (!n_entries_v1) { - if (m_entries_v1) { - for (std::vector::iterator it = m_entries_v1->begin(); it != m_entries_v1->end(); ++it) { - delete *it; - } - delete m_entries_v1; m_entries_v1 = 0; - } } if (!n_entries_v2) { - if (m_entries_v2) { - for (std::vector::iterator it = m_entries_v2->begin(); it != m_entries_v2->end(); ++it) { - delete *it; - } - delete m_entries_v2; m_entries_v2 = 0; - } } } diff --git a/common/generated/intel_acbp_v1.h b/common/generated/intel_acbp_v1.h index 25413f9..2296ab6 100644 --- a/common/generated/intel_acbp_v1.h +++ b/common/generated/intel_acbp_v1.h @@ -1,10 +1,10 @@ -#ifndef INTEL_ACBP_V1_H_ -#define INTEL_ACBP_V1_H_ +#pragma once // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild #include "../kaitai/kaitaistruct.h" #include +#include #include #if KAITAI_STRUCT_VERSION < 9000L @@ -38,7 +38,7 @@ public: STRUCTURE_IDS_IBBS = 6872303100435717983LL }; - intel_acbp_v1_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_acbp_v1_t* p__root = 0); + intel_acbp_v1_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -51,7 +51,7 @@ public: public: - pmsg_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + pmsg_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -63,18 +63,18 @@ public: private: uint8_t m_version; uint16_t m_key_id; - public_key_t* m_public_key; + std::unique_ptr m_public_key; uint16_t m_sig_scheme; - signature_t* m_signature; + std::unique_ptr m_signature; intel_acbp_v1_t* m__root; intel_acbp_v1_t::acbp_element_t* m__parent; public: uint8_t version() const { return m_version; } uint16_t key_id() const { return m_key_id; } - public_key_t* public_key() const { return m_public_key; } + public_key_t* public_key() const { return m_public_key.get(); } uint16_t sig_scheme() const { return m_sig_scheme; } - signature_t* signature() const { return m_signature; } + signature_t* signature() const { return m_signature.get(); } intel_acbp_v1_t* _root() const { return m__root; } intel_acbp_v1_t::acbp_element_t* _parent() const { return m__parent; } }; @@ -83,7 +83,7 @@ public: public: - acbp_element_t(kaitai::kstream* p__io, intel_acbp_v1_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + acbp_element_t(kaitai::kstream* p__io, intel_acbp_v1_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -93,22 +93,22 @@ public: ~acbp_element_t(); private: - common_header_t* m_header; - ibbs_body_t* m_ibbs_body; + std::unique_ptr m_header; + std::unique_ptr m_ibbs_body; bool n_ibbs_body; public: bool _is_null_ibbs_body() { ibbs_body(); return n_ibbs_body; }; private: - pmda_body_t* m_pmda_body; + std::unique_ptr m_pmda_body; bool n_pmda_body; public: bool _is_null_pmda_body() { pmda_body(); return n_pmda_body; }; private: - pmsg_body_t* m_pmsg_body; + std::unique_ptr m_pmsg_body; bool n_pmsg_body; public: @@ -126,10 +126,10 @@ public: intel_acbp_v1_t* m__parent; public: - common_header_t* header() const { return m_header; } - ibbs_body_t* ibbs_body() const { return m_ibbs_body; } - pmda_body_t* pmda_body() const { return m_pmda_body; } - pmsg_body_t* pmsg_body() const { return m_pmsg_body; } + common_header_t* header() const { return m_header.get(); } + ibbs_body_t* ibbs_body() const { return m_ibbs_body.get(); } + pmda_body_t* pmda_body() const { return m_pmda_body.get(); } + pmsg_body_t* pmsg_body() const { return m_pmsg_body.get(); } std::string invalid_body() const { return m_invalid_body; } intel_acbp_v1_t* _root() const { return m__root; } intel_acbp_v1_t* _parent() const { return m__parent; } @@ -139,7 +139,7 @@ public: public: - common_header_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + common_header_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -165,7 +165,7 @@ public: public: - signature_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmsg_body_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + signature_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmsg_body_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -195,7 +195,7 @@ public: public: - pmda_entry_v1_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmda_body_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + pmda_entry_v1_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmda_body_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -223,7 +223,7 @@ public: public: - ibb_segment_t(kaitai::kstream* p__io, intel_acbp_v1_t::ibbs_body_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + ibb_segment_t(kaitai::kstream* p__io, intel_acbp_v1_t::ibbs_body_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -253,7 +253,7 @@ public: public: - public_key_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmsg_body_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + public_key_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmsg_body_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -283,7 +283,7 @@ public: public: - hash_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_acbp_v1_t* p__root = 0); + hash_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -311,7 +311,7 @@ public: public: - pmda_entry_v2_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmda_body_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + pmda_entry_v2_t(kaitai::kstream* p__io, intel_acbp_v1_t::pmda_body_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -323,14 +323,14 @@ public: private: uint32_t m_base; uint32_t m_size; - hash_t* m_hash; + std::unique_ptr m_hash; intel_acbp_v1_t* m__root; intel_acbp_v1_t::pmda_body_t* m__parent; public: uint32_t base() const { return m_base; } uint32_t size() const { return m_size; } - hash_t* hash() const { return m_hash; } + hash_t* hash() const { return m_hash.get(); } intel_acbp_v1_t* _root() const { return m__root; } intel_acbp_v1_t::pmda_body_t* _parent() const { return m__parent; } }; @@ -339,7 +339,7 @@ public: public: - ibbs_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + ibbs_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -349,7 +349,7 @@ public: ~ibbs_body_t(); private: - std::vector* m_reserved; + std::unique_ptr> m_reserved; uint32_t m_flags; uint64_t m_mch_bar; uint64_t m_vtd_bar; @@ -357,16 +357,16 @@ public: uint32_t m_dma_protection_limit0; uint64_t m_dma_protection_base1; uint64_t m_dma_protection_limit1; - hash_t* m_post_ibb_hash; + std::unique_ptr m_post_ibb_hash; uint32_t m_ibb_entry_point; - hash_t* m_ibb_hash; + std::unique_ptr m_ibb_hash; uint8_t m_num_ibb_segments; - std::vector* m_ibb_segments; + std::unique_ptr>> m_ibb_segments; intel_acbp_v1_t* m__root; intel_acbp_v1_t::acbp_element_t* m__parent; public: - std::vector* reserved() const { return m_reserved; } + std::vector* reserved() const { return m_reserved.get(); } uint32_t flags() const { return m_flags; } uint64_t mch_bar() const { return m_mch_bar; } uint64_t vtd_bar() const { return m_vtd_bar; } @@ -374,11 +374,11 @@ public: uint32_t dma_protection_limit0() const { return m_dma_protection_limit0; } uint64_t dma_protection_base1() const { return m_dma_protection_base1; } uint64_t dma_protection_limit1() const { return m_dma_protection_limit1; } - hash_t* post_ibb_hash() const { return m_post_ibb_hash; } + hash_t* post_ibb_hash() const { return m_post_ibb_hash.get(); } uint32_t ibb_entry_point() const { return m_ibb_entry_point; } - hash_t* ibb_hash() const { return m_ibb_hash; } + hash_t* ibb_hash() const { return m_ibb_hash.get(); } uint8_t num_ibb_segments() const { return m_num_ibb_segments; } - std::vector* ibb_segments() const { return m_ibb_segments; } + std::vector>* ibb_segments() const { return m_ibb_segments.get(); } intel_acbp_v1_t* _root() const { return m__root; } intel_acbp_v1_t::acbp_element_t* _parent() const { return m__parent; } }; @@ -387,7 +387,7 @@ public: public: - pmda_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = 0, intel_acbp_v1_t* p__root = 0); + pmda_body_t(kaitai::kstream* p__io, intel_acbp_v1_t::acbp_element_t* p__parent = nullptr, intel_acbp_v1_t* p__root = nullptr); private: void _read(); @@ -400,14 +400,14 @@ public: uint16_t m_total_size; uint32_t m_version; uint32_t m_num_entries; - std::vector* m_entries_v1; + std::unique_ptr>> m_entries_v1; bool n_entries_v1; public: bool _is_null_entries_v1() { entries_v1(); return n_entries_v1; }; private: - std::vector* m_entries_v2; + std::unique_ptr>> m_entries_v2; bool n_entries_v2; public: @@ -421,8 +421,8 @@ public: uint16_t total_size() const { return m_total_size; } uint32_t version() const { return m_version; } uint32_t num_entries() const { return m_num_entries; } - std::vector* entries_v1() const { return m_entries_v1; } - std::vector* entries_v2() const { return m_entries_v2; } + std::vector>* entries_v1() const { return m_entries_v1.get(); } + std::vector>* entries_v2() const { return m_entries_v2.get(); } intel_acbp_v1_t* _root() const { return m__root; } intel_acbp_v1_t::acbp_element_t* _parent() const { return m__parent; } }; @@ -436,7 +436,7 @@ private: uint8_t m_acm_svn; uint8_t m_reserved1; uint16_t m_nem_data_size; - std::vector* m_elements; + std::unique_ptr>> m_elements; intel_acbp_v1_t* m__root; kaitai::kstruct* m__parent; @@ -449,9 +449,7 @@ public: uint8_t acm_svn() const { return m_acm_svn; } uint8_t reserved1() const { return m_reserved1; } uint16_t nem_data_size() const { return m_nem_data_size; } - std::vector* elements() const { return m_elements; } + std::vector>* elements() const { return m_elements.get(); } intel_acbp_v1_t* _root() const { return m__root; } kaitai::kstruct* _parent() const { return m__parent; } }; - -#endif // INTEL_ACBP_V1_H_ diff --git a/common/generated/intel_acbp_v2.cpp b/common/generated/intel_acbp_v2.cpp index c7cabd6..e6f4e29 100644 --- a/common/generated/intel_acbp_v2.cpp +++ b/common/generated/intel_acbp_v2.cpp @@ -6,15 +6,9 @@ intel_acbp_v2_t::intel_acbp_v2_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = this; (void)p__root; - m_elements = 0; - m_key_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_elements = nullptr; + m_key_signature = nullptr; + _read(); } void intel_acbp_v2_t::_read() { @@ -40,17 +34,17 @@ void intel_acbp_v2_t::_read() { m_acm_svn = m__io->read_u1(); m_reserved = m__io->read_u1(); m_nem_data_size = m__io->read_u2le(); - m_elements = new std::vector(); + m_elements = std::unique_ptr>>(new std::vector>()); { int i = 0; acbp_element_t* _; do { _ = new acbp_element_t(m__io, this, m__root); - m_elements->push_back(_); + m_elements->push_back(std::move(std::unique_ptr(_))); i++; } while (!( ((_->header()->total_size() == 0) || (_->header()->structure_id() == intel_acbp_v2_t::STRUCTURE_IDS_PMSG)) )); } - m_key_signature = new key_signature_t(m__io, this, m__root); + m_key_signature = std::unique_ptr(new key_signature_t(m__io, this, m__root)); } intel_acbp_v2_t::~intel_acbp_v2_t() { @@ -58,43 +52,28 @@ intel_acbp_v2_t::~intel_acbp_v2_t() { } void intel_acbp_v2_t::_clean_up() { - if (m_elements) { - for (std::vector::iterator it = m_elements->begin(); it != m_elements->end(); ++it) { - delete *it; - } - delete m_elements; m_elements = 0; - } - if (m_key_signature) { - delete m_key_signature; m_key_signature = 0; - } } intel_acbp_v2_t::acbp_element_t::acbp_element_t(kaitai::kstream* p__io, intel_acbp_v2_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_header = 0; - m_ibbs_body = 0; - m_pmda_body = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_header = nullptr; + m_ibbs_body = nullptr; + m_pmda_body = nullptr; + _read(); } void intel_acbp_v2_t::acbp_element_t::_read() { - m_header = new header_t(m__io, this, m__root); + m_header = std::unique_ptr(new header_t(m__io, this, m__root)); n_ibbs_body = true; if ( ((header()->structure_id() == intel_acbp_v2_t::STRUCTURE_IDS_IBBS) && (header()->total_size() >= 12)) ) { n_ibbs_body = false; - m_ibbs_body = new ibbs_body_t(m__io, this, m__root); + m_ibbs_body = std::unique_ptr(new ibbs_body_t(m__io, this, m__root)); } n_pmda_body = true; if ( ((header()->structure_id() == intel_acbp_v2_t::STRUCTURE_IDS_PMDA) && (header()->total_size() >= 12)) ) { n_pmda_body = false; - m_pmda_body = new pmda_body_t(m__io, this, m__root); + m_pmda_body = std::unique_ptr(new pmda_body_t(m__io, this, m__root)); } n_generic_body = true; if ( ((header()->structure_id() != intel_acbp_v2_t::STRUCTURE_IDS_IBBS) && (header()->structure_id() != intel_acbp_v2_t::STRUCTURE_IDS_PMDA) && (header()->total_size() >= 12)) ) { @@ -108,18 +87,9 @@ intel_acbp_v2_t::acbp_element_t::~acbp_element_t() { } void intel_acbp_v2_t::acbp_element_t::_clean_up() { - if (m_header) { - delete m_header; m_header = 0; - } if (!n_ibbs_body) { - if (m_ibbs_body) { - delete m_ibbs_body; m_ibbs_body = 0; - } } if (!n_pmda_body) { - if (m_pmda_body) { - delete m_pmda_body; m_pmda_body = 0; - } } if (!n_generic_body) { } @@ -128,23 +98,17 @@ void intel_acbp_v2_t::acbp_element_t::_clean_up() { intel_acbp_v2_t::key_signature_t::key_signature_t(kaitai::kstream* p__io, intel_acbp_v2_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_public_key = 0; - m_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_public_key = nullptr; + m_signature = nullptr; + _read(); } void intel_acbp_v2_t::key_signature_t::_read() { m_version = m__io->read_u1(); m_key_id = m__io->read_u2le(); - m_public_key = new public_key_t(m__io, this, m__root); + m_public_key = std::unique_ptr(new public_key_t(m__io, this, m__root)); m_sig_scheme = m__io->read_u2le(); - m_signature = new signature_t(m__io, this, m__root); + m_signature = std::unique_ptr(new signature_t(m__io, this, m__root)); } intel_acbp_v2_t::key_signature_t::~key_signature_t() { @@ -152,24 +116,12 @@ intel_acbp_v2_t::key_signature_t::~key_signature_t() { } void intel_acbp_v2_t::key_signature_t::_clean_up() { - if (m_public_key) { - delete m_public_key; m_public_key = 0; - } - if (m_signature) { - delete m_signature; m_signature = 0; - } } intel_acbp_v2_t::signature_t::signature_t(kaitai::kstream* p__io, intel_acbp_v2_t::key_signature_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v2_t::signature_t::_read() { @@ -189,13 +141,7 @@ void intel_acbp_v2_t::signature_t::_clean_up() { intel_acbp_v2_t::ibb_segment_t::ibb_segment_t(kaitai::kstream* p__io, intel_acbp_v2_t::ibbs_body_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v2_t::ibb_segment_t::_read() { @@ -215,13 +161,7 @@ void intel_acbp_v2_t::ibb_segment_t::_clean_up() { intel_acbp_v2_t::public_key_t::public_key_t(kaitai::kstream* p__io, intel_acbp_v2_t::key_signature_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v2_t::public_key_t::_read() { @@ -241,13 +181,7 @@ void intel_acbp_v2_t::public_key_t::_clean_up() { intel_acbp_v2_t::hash_t::hash_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v2_t::hash_t::_read() { @@ -266,13 +200,7 @@ void intel_acbp_v2_t::hash_t::_clean_up() { intel_acbp_v2_t::header_t::header_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acbp_v2_t::header_t::_read() { @@ -292,14 +220,8 @@ void intel_acbp_v2_t::header_t::_clean_up() { intel_acbp_v2_t::pmda_entry_v3_t::pmda_entry_v3_t(kaitai::kstream* p__io, intel_acbp_v2_t::pmda_body_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_hash = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_hash = nullptr; + _read(); } void intel_acbp_v2_t::pmda_entry_v3_t::_read() { @@ -308,7 +230,7 @@ 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(); - m_hash = new hash_t(m__io, this, m__root); + m_hash = std::unique_ptr(new hash_t(m__io, this, m__root)); } intel_acbp_v2_t::pmda_entry_v3_t::~pmda_entry_v3_t() { @@ -316,26 +238,17 @@ intel_acbp_v2_t::pmda_entry_v3_t::~pmda_entry_v3_t() { } void intel_acbp_v2_t::pmda_entry_v3_t::_clean_up() { - if (m_hash) { - delete m_hash; m_hash = 0; - } } intel_acbp_v2_t::ibbs_body_t::ibbs_body_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_post_ibb_digest = 0; - m_ibb_digests = 0; - m_obb_digest = 0; - m_reserved2 = 0; - m_ibb_segments = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_post_ibb_digest = nullptr; + m_ibb_digests = nullptr; + m_obb_digest = nullptr; + m_reserved2 = nullptr; + m_ibb_segments = nullptr; + _read(); } void intel_acbp_v2_t::ibbs_body_t::_read() { @@ -350,26 +263,26 @@ void intel_acbp_v2_t::ibbs_body_t::_read() { m_dma_protection_limit0 = m__io->read_u4le(); m_dma_protection_base1 = m__io->read_u8le(); m_dma_protection_limit1 = m__io->read_u8le(); - m_post_ibb_digest = new hash_t(m__io, this, m__root); + m_post_ibb_digest = std::unique_ptr(new hash_t(m__io, this, m__root)); m_ibb_entry_point = m__io->read_u4le(); m_ibb_digests_size = m__io->read_u2le(); m_num_ibb_digests = m__io->read_u2le(); - m_ibb_digests = new std::vector(); + m_ibb_digests = std::unique_ptr>>(new std::vector>()); const int l_ibb_digests = num_ibb_digests(); for (int i = 0; i < l_ibb_digests; i++) { - m_ibb_digests->push_back(new hash_t(m__io, this, m__root)); + m_ibb_digests->push_back(std::move(std::unique_ptr(new hash_t(m__io, this, m__root)))); } - m_obb_digest = new hash_t(m__io, this, m__root); - m_reserved2 = new std::vector(); + m_obb_digest = std::unique_ptr(new hash_t(m__io, this, m__root)); + m_reserved2 = std::unique_ptr>(new std::vector()); const int l_reserved2 = 3; for (int i = 0; i < l_reserved2; i++) { - m_reserved2->push_back(m__io->read_u1()); + m_reserved2->push_back(std::move(m__io->read_u1())); } m_num_ibb_segments = m__io->read_u1(); - m_ibb_segments = new std::vector(); + m_ibb_segments = std::unique_ptr>>(new std::vector>()); const int l_ibb_segments = num_ibb_segments(); for (int i = 0; i < l_ibb_segments; i++) { - m_ibb_segments->push_back(new ibb_segment_t(m__io, this, m__root)); + m_ibb_segments->push_back(std::move(std::unique_ptr(new ibb_segment_t(m__io, this, m__root)))); } } @@ -378,40 +291,13 @@ intel_acbp_v2_t::ibbs_body_t::~ibbs_body_t() { } void intel_acbp_v2_t::ibbs_body_t::_clean_up() { - if (m_post_ibb_digest) { - delete m_post_ibb_digest; m_post_ibb_digest = 0; - } - if (m_ibb_digests) { - for (std::vector::iterator it = m_ibb_digests->begin(); it != m_ibb_digests->end(); ++it) { - delete *it; - } - delete m_ibb_digests; m_ibb_digests = 0; - } - if (m_obb_digest) { - delete m_obb_digest; m_obb_digest = 0; - } - if (m_reserved2) { - delete m_reserved2; m_reserved2 = 0; - } - if (m_ibb_segments) { - for (std::vector::iterator it = m_ibb_segments->begin(); it != m_ibb_segments->end(); ++it) { - delete *it; - } - delete m_ibb_segments; m_ibb_segments = 0; - } } intel_acbp_v2_t::pmda_body_t::pmda_body_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent, intel_acbp_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_entries = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_entries = nullptr; + _read(); } void intel_acbp_v2_t::pmda_body_t::_read() { @@ -422,10 +308,10 @@ void intel_acbp_v2_t::pmda_body_t::_read() { 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(); + m_entries = std::unique_ptr>>(new std::vector>()); const int l_entries = num_entries(); for (int i = 0; i < l_entries; i++) { - m_entries->push_back(new pmda_entry_v3_t(m__io, this, m__root)); + m_entries->push_back(std::move(std::unique_ptr(new pmda_entry_v3_t(m__io, this, m__root)))); } } @@ -434,10 +320,4 @@ intel_acbp_v2_t::pmda_body_t::~pmda_body_t() { } void intel_acbp_v2_t::pmda_body_t::_clean_up() { - if (m_entries) { - for (std::vector::iterator it = m_entries->begin(); it != m_entries->end(); ++it) { - delete *it; - } - delete m_entries; m_entries = 0; - } } diff --git a/common/generated/intel_acbp_v2.h b/common/generated/intel_acbp_v2.h index b3a25df..24a601e 100644 --- a/common/generated/intel_acbp_v2.h +++ b/common/generated/intel_acbp_v2.h @@ -1,10 +1,10 @@ -#ifndef INTEL_ACBP_V2_H_ -#define INTEL_ACBP_V2_H_ +#pragma once // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild #include "../kaitai/kaitaistruct.h" #include +#include #include #if KAITAI_STRUCT_VERSION < 9000L @@ -40,7 +40,7 @@ public: STRUCTURE_IDS_TXTS = 6872303178114948959LL }; - intel_acbp_v2_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_acbp_v2_t* p__root = 0); + intel_acbp_v2_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -53,7 +53,7 @@ public: public: - acbp_element_t(kaitai::kstream* p__io, intel_acbp_v2_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + acbp_element_t(kaitai::kstream* p__io, intel_acbp_v2_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -63,15 +63,15 @@ public: ~acbp_element_t(); private: - header_t* m_header; - ibbs_body_t* m_ibbs_body; + std::unique_ptr m_header; + std::unique_ptr m_ibbs_body; bool n_ibbs_body; public: bool _is_null_ibbs_body() { ibbs_body(); return n_ibbs_body; }; private: - pmda_body_t* m_pmda_body; + std::unique_ptr m_pmda_body; bool n_pmda_body; public: @@ -89,9 +89,9 @@ public: intel_acbp_v2_t* m__parent; public: - header_t* header() const { return m_header; } - ibbs_body_t* ibbs_body() const { return m_ibbs_body; } - pmda_body_t* pmda_body() const { return m_pmda_body; } + header_t* header() const { return m_header.get(); } + ibbs_body_t* ibbs_body() const { return m_ibbs_body.get(); } + pmda_body_t* pmda_body() const { return m_pmda_body.get(); } std::string generic_body() const { return m_generic_body; } intel_acbp_v2_t* _root() const { return m__root; } intel_acbp_v2_t* _parent() const { return m__parent; } @@ -101,7 +101,7 @@ public: public: - key_signature_t(kaitai::kstream* p__io, intel_acbp_v2_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + key_signature_t(kaitai::kstream* p__io, intel_acbp_v2_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -113,18 +113,18 @@ public: private: uint8_t m_version; uint16_t m_key_id; - public_key_t* m_public_key; + std::unique_ptr m_public_key; uint16_t m_sig_scheme; - signature_t* m_signature; + std::unique_ptr m_signature; intel_acbp_v2_t* m__root; intel_acbp_v2_t* m__parent; public: uint8_t version() const { return m_version; } uint16_t key_id() const { return m_key_id; } - public_key_t* public_key() const { return m_public_key; } + public_key_t* public_key() const { return m_public_key.get(); } uint16_t sig_scheme() const { return m_sig_scheme; } - signature_t* signature() const { return m_signature; } + signature_t* signature() const { return m_signature.get(); } intel_acbp_v2_t* _root() const { return m__root; } intel_acbp_v2_t* _parent() const { return m__parent; } }; @@ -133,7 +133,7 @@ public: public: - signature_t(kaitai::kstream* p__io, intel_acbp_v2_t::key_signature_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + signature_t(kaitai::kstream* p__io, intel_acbp_v2_t::key_signature_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -163,7 +163,7 @@ public: public: - ibb_segment_t(kaitai::kstream* p__io, intel_acbp_v2_t::ibbs_body_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + ibb_segment_t(kaitai::kstream* p__io, intel_acbp_v2_t::ibbs_body_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -193,7 +193,7 @@ public: public: - public_key_t(kaitai::kstream* p__io, intel_acbp_v2_t::key_signature_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + public_key_t(kaitai::kstream* p__io, intel_acbp_v2_t::key_signature_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -223,7 +223,7 @@ public: public: - hash_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_acbp_v2_t* p__root = 0); + hash_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -251,7 +251,7 @@ public: public: - header_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + header_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -281,7 +281,7 @@ public: public: - pmda_entry_v3_t(kaitai::kstream* p__io, intel_acbp_v2_t::pmda_body_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + pmda_entry_v3_t(kaitai::kstream* p__io, intel_acbp_v2_t::pmda_body_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -296,7 +296,7 @@ public: uint32_t m_size; uint16_t m_total_entry_size; uint16_t m_version; - hash_t* m_hash; + std::unique_ptr m_hash; intel_acbp_v2_t* m__root; intel_acbp_v2_t::pmda_body_t* m__parent; @@ -306,7 +306,7 @@ public: uint32_t size() const { return m_size; } uint16_t total_entry_size() const { return m_total_entry_size; } uint16_t version() const { return m_version; } - hash_t* hash() const { return m_hash; } + hash_t* hash() const { return m_hash.get(); } intel_acbp_v2_t* _root() const { return m__root; } intel_acbp_v2_t::pmda_body_t* _parent() const { return m__parent; } }; @@ -315,7 +315,7 @@ public: public: - ibbs_body_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + ibbs_body_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -336,15 +336,15 @@ public: uint32_t m_dma_protection_limit0; uint64_t m_dma_protection_base1; uint64_t m_dma_protection_limit1; - hash_t* m_post_ibb_digest; + std::unique_ptr m_post_ibb_digest; uint32_t m_ibb_entry_point; uint16_t m_ibb_digests_size; uint16_t m_num_ibb_digests; - std::vector* m_ibb_digests; - hash_t* m_obb_digest; - std::vector* m_reserved2; + std::unique_ptr>> m_ibb_digests; + std::unique_ptr m_obb_digest; + std::unique_ptr> m_reserved2; uint8_t m_num_ibb_segments; - std::vector* m_ibb_segments; + std::unique_ptr>> m_ibb_segments; intel_acbp_v2_t* m__root; intel_acbp_v2_t::acbp_element_t* m__parent; @@ -360,15 +360,15 @@ public: uint32_t dma_protection_limit0() const { return m_dma_protection_limit0; } uint64_t dma_protection_base1() const { return m_dma_protection_base1; } uint64_t dma_protection_limit1() const { return m_dma_protection_limit1; } - hash_t* post_ibb_digest() const { return m_post_ibb_digest; } + hash_t* post_ibb_digest() const { return m_post_ibb_digest.get(); } uint32_t ibb_entry_point() const { return m_ibb_entry_point; } uint16_t ibb_digests_size() const { return m_ibb_digests_size; } uint16_t num_ibb_digests() const { return m_num_ibb_digests; } - std::vector* ibb_digests() const { return m_ibb_digests; } - hash_t* obb_digest() const { return m_obb_digest; } - std::vector* reserved2() const { return m_reserved2; } + std::vector>* ibb_digests() const { return m_ibb_digests.get(); } + hash_t* obb_digest() const { return m_obb_digest.get(); } + std::vector* reserved2() const { return m_reserved2.get(); } uint8_t num_ibb_segments() const { return m_num_ibb_segments; } - std::vector* ibb_segments() const { return m_ibb_segments; } + std::vector>* ibb_segments() const { return m_ibb_segments.get(); } intel_acbp_v2_t* _root() const { return m__root; } intel_acbp_v2_t::acbp_element_t* _parent() const { return m__parent; } }; @@ -377,7 +377,7 @@ public: public: - pmda_body_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent = 0, intel_acbp_v2_t* p__root = 0); + pmda_body_t(kaitai::kstream* p__io, intel_acbp_v2_t::acbp_element_t* p__parent = nullptr, intel_acbp_v2_t* p__root = nullptr); private: void _read(); @@ -391,7 +391,7 @@ public: uint16_t m_total_size; uint32_t m_version; uint32_t m_num_entries; - std::vector* m_entries; + std::unique_ptr>> m_entries; intel_acbp_v2_t* m__root; intel_acbp_v2_t::acbp_element_t* m__parent; @@ -400,7 +400,7 @@ public: uint16_t total_size() const { return m_total_size; } uint32_t version() const { return m_version; } uint32_t num_entries() const { return m_num_entries; } - std::vector* entries() const { return m_entries; } + std::vector>* entries() const { return m_entries.get(); } intel_acbp_v2_t* _root() const { return m__root; } intel_acbp_v2_t::acbp_element_t* _parent() const { return m__parent; } }; @@ -416,8 +416,8 @@ private: uint8_t m_acm_svn; uint8_t m_reserved; uint16_t m_nem_data_size; - std::vector* m_elements; - key_signature_t* m_key_signature; + std::unique_ptr>> m_elements; + std::unique_ptr m_key_signature; intel_acbp_v2_t* m__root; kaitai::kstruct* m__parent; @@ -432,10 +432,8 @@ public: uint8_t acm_svn() const { return m_acm_svn; } uint8_t reserved() const { return m_reserved; } uint16_t nem_data_size() const { return m_nem_data_size; } - std::vector* elements() const { return m_elements; } - key_signature_t* key_signature() const { return m_key_signature; } + std::vector>* elements() const { return m_elements.get(); } + key_signature_t* key_signature() const { return m_key_signature.get(); } intel_acbp_v2_t* _root() const { return m__root; } kaitai::kstruct* _parent() const { return m__parent; } }; - -#endif // INTEL_ACBP_V2_H_ diff --git a/common/generated/intel_acm.cpp b/common/generated/intel_acm.cpp index 78fd1eb..8f60062 100644 --- a/common/generated/intel_acm.cpp +++ b/common/generated/intel_acm.cpp @@ -6,18 +6,12 @@ intel_acm_t::intel_acm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_acm_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = this; (void)p__root; - m_header = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_header = nullptr; + _read(); } void intel_acm_t::_read() { - m_header = new header_t(m__io, this, m__root); + m_header = std::unique_ptr(new header_t(m__io, this, m__root)); m_body = m__io->read_bytes((4 * ((header()->module_size() - header()->header_size()) - header()->scratch_space_size()))); } @@ -26,21 +20,12 @@ intel_acm_t::~intel_acm_t() { } void intel_acm_t::_clean_up() { - if (m_header) { - delete m_header; m_header = 0; - } } intel_acm_t::header_t::header_t(kaitai::kstream* p__io, intel_acm_t* p__parent, intel_acm_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_acm_t::header_t::_read() { diff --git a/common/generated/intel_acm.h b/common/generated/intel_acm.h index 43219eb..942070f 100644 --- a/common/generated/intel_acm.h +++ b/common/generated/intel_acm.h @@ -1,10 +1,10 @@ -#ifndef INTEL_ACM_H_ -#define INTEL_ACM_H_ +#pragma once // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild #include "../kaitai/kaitaistruct.h" #include +#include #if KAITAI_STRUCT_VERSION < 9000L #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" @@ -26,7 +26,7 @@ public: KNOWN_HEADER_VERSION_V3_0 = 196608 }; - intel_acm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_acm_t* p__root = 0); + intel_acm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_acm_t* p__root = nullptr); private: void _read(); @@ -39,7 +39,7 @@ public: public: - header_t(kaitai::kstream* p__io, intel_acm_t* p__parent = 0, intel_acm_t* p__root = 0); + header_t(kaitai::kstream* p__io, intel_acm_t* p__parent = nullptr, intel_acm_t* p__root = nullptr); private: void _read(); @@ -144,16 +144,14 @@ public: }; private: - header_t* m_header; + std::unique_ptr m_header; std::string m_body; intel_acm_t* m__root; kaitai::kstruct* m__parent; public: - header_t* header() const { return m_header; } + header_t* header() const { return m_header.get(); } std::string body() const { return m_body; } intel_acm_t* _root() const { return m__root; } kaitai::kstruct* _parent() const { return m__parent; } }; - -#endif // INTEL_ACM_H_ diff --git a/common/generated/intel_keym_v1.cpp b/common/generated/intel_keym_v1.cpp index 0f83d28..81f4b0a 100644 --- a/common/generated/intel_keym_v1.cpp +++ b/common/generated/intel_keym_v1.cpp @@ -6,15 +6,9 @@ intel_keym_v1_t::intel_keym_v1_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_keym_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = this; (void)p__root; - m_km_hash = 0; - m_key_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_km_hash = nullptr; + m_key_signature = nullptr; + _read(); } void intel_keym_v1_t::_read() { @@ -32,8 +26,8 @@ void intel_keym_v1_t::_read() { m_km_version = m__io->read_u1(); m_km_svn = m__io->read_u1(); m_km_id = m__io->read_u1(); - m_km_hash = new km_hash_t(m__io, this, m__root); - m_key_signature = new key_signature_t(m__io, this, m__root); + m_km_hash = std::unique_ptr(new km_hash_t(m__io, this, m__root)); + m_key_signature = std::unique_ptr(new key_signature_t(m__io, this, m__root)); } intel_keym_v1_t::~intel_keym_v1_t() { @@ -41,24 +35,12 @@ intel_keym_v1_t::~intel_keym_v1_t() { } void intel_keym_v1_t::_clean_up() { - if (m_km_hash) { - delete m_km_hash; m_km_hash = 0; - } - if (m_key_signature) { - delete m_key_signature; m_key_signature = 0; - } } intel_keym_v1_t::km_hash_t::km_hash_t(kaitai::kstream* p__io, intel_keym_v1_t* p__parent, intel_keym_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v1_t::km_hash_t::_read() { @@ -77,13 +59,7 @@ void intel_keym_v1_t::km_hash_t::_clean_up() { intel_keym_v1_t::public_key_t::public_key_t(kaitai::kstream* p__io, intel_keym_v1_t::key_signature_t* p__parent, intel_keym_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v1_t::public_key_t::_read() { @@ -103,13 +79,7 @@ void intel_keym_v1_t::public_key_t::_clean_up() { intel_keym_v1_t::signature_t::signature_t(kaitai::kstream* p__io, intel_keym_v1_t::key_signature_t* p__parent, intel_keym_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v1_t::signature_t::_read() { @@ -129,23 +99,17 @@ void intel_keym_v1_t::signature_t::_clean_up() { intel_keym_v1_t::key_signature_t::key_signature_t(kaitai::kstream* p__io, intel_keym_v1_t* p__parent, intel_keym_v1_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_public_key = 0; - m_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_public_key = nullptr; + m_signature = nullptr; + _read(); } void intel_keym_v1_t::key_signature_t::_read() { m_version = m__io->read_u1(); m_key_id = m__io->read_u2le(); - m_public_key = new public_key_t(m__io, this, m__root); + m_public_key = std::unique_ptr(new public_key_t(m__io, this, m__root)); m_sig_scheme = m__io->read_u2le(); - m_signature = new signature_t(m__io, this, m__root); + m_signature = std::unique_ptr(new signature_t(m__io, this, m__root)); } intel_keym_v1_t::key_signature_t::~key_signature_t() { @@ -153,10 +117,4 @@ intel_keym_v1_t::key_signature_t::~key_signature_t() { } void intel_keym_v1_t::key_signature_t::_clean_up() { - if (m_public_key) { - delete m_public_key; m_public_key = 0; - } - if (m_signature) { - delete m_signature; m_signature = 0; - } } diff --git a/common/generated/intel_keym_v1.h b/common/generated/intel_keym_v1.h index 2ec5a3f..c1c2ec8 100644 --- a/common/generated/intel_keym_v1.h +++ b/common/generated/intel_keym_v1.h @@ -1,10 +1,10 @@ -#ifndef INTEL_KEYM_V1_H_ -#define INTEL_KEYM_V1_H_ +#pragma once // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild #include "../kaitai/kaitaistruct.h" #include +#include #if KAITAI_STRUCT_VERSION < 9000L #error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required" @@ -22,7 +22,7 @@ public: STRUCTURE_IDS_KEYM = 6872296602200661855LL }; - intel_keym_v1_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_keym_v1_t* p__root = 0); + intel_keym_v1_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_keym_v1_t* p__root = nullptr); private: void _read(); @@ -35,7 +35,7 @@ public: public: - km_hash_t(kaitai::kstream* p__io, intel_keym_v1_t* p__parent = 0, intel_keym_v1_t* p__root = 0); + km_hash_t(kaitai::kstream* p__io, intel_keym_v1_t* p__parent = nullptr, intel_keym_v1_t* p__root = nullptr); private: void _read(); @@ -63,7 +63,7 @@ public: public: - public_key_t(kaitai::kstream* p__io, intel_keym_v1_t::key_signature_t* p__parent = 0, intel_keym_v1_t* p__root = 0); + public_key_t(kaitai::kstream* p__io, intel_keym_v1_t::key_signature_t* p__parent = nullptr, intel_keym_v1_t* p__root = nullptr); private: void _read(); @@ -93,7 +93,7 @@ public: public: - signature_t(kaitai::kstream* p__io, intel_keym_v1_t::key_signature_t* p__parent = 0, intel_keym_v1_t* p__root = 0); + signature_t(kaitai::kstream* p__io, intel_keym_v1_t::key_signature_t* p__parent = nullptr, intel_keym_v1_t* p__root = nullptr); private: void _read(); @@ -123,7 +123,7 @@ public: public: - key_signature_t(kaitai::kstream* p__io, intel_keym_v1_t* p__parent = 0, intel_keym_v1_t* p__root = 0); + key_signature_t(kaitai::kstream* p__io, intel_keym_v1_t* p__parent = nullptr, intel_keym_v1_t* p__root = nullptr); private: void _read(); @@ -135,18 +135,18 @@ public: private: uint8_t m_version; uint16_t m_key_id; - public_key_t* m_public_key; + std::unique_ptr m_public_key; uint16_t m_sig_scheme; - signature_t* m_signature; + std::unique_ptr m_signature; intel_keym_v1_t* m__root; intel_keym_v1_t* m__parent; public: uint8_t version() const { return m_version; } uint16_t key_id() const { return m_key_id; } - public_key_t* public_key() const { return m_public_key; } + public_key_t* public_key() const { return m_public_key.get(); } uint16_t sig_scheme() const { return m_sig_scheme; } - signature_t* signature() const { return m_signature; } + signature_t* signature() const { return m_signature.get(); } intel_keym_v1_t* _root() const { return m__root; } intel_keym_v1_t* _parent() const { return m__parent; } }; @@ -157,8 +157,8 @@ private: uint8_t m_km_version; uint8_t m_km_svn; uint8_t m_km_id; - km_hash_t* m_km_hash; - key_signature_t* m_key_signature; + std::unique_ptr m_km_hash; + std::unique_ptr m_key_signature; intel_keym_v1_t* m__root; kaitai::kstruct* m__parent; @@ -168,10 +168,8 @@ public: uint8_t km_version() const { return m_km_version; } uint8_t km_svn() const { return m_km_svn; } uint8_t km_id() const { return m_km_id; } - km_hash_t* km_hash() const { return m_km_hash; } - key_signature_t* key_signature() const { return m_key_signature; } + km_hash_t* km_hash() const { return m_km_hash.get(); } + key_signature_t* key_signature() const { return m_key_signature.get(); } intel_keym_v1_t* _root() const { return m__root; } kaitai::kstruct* _parent() const { return m__parent; } }; - -#endif // INTEL_KEYM_V1_H_ diff --git a/common/generated/intel_keym_v2.cpp b/common/generated/intel_keym_v2.cpp index 1778a7c..f9fd523 100644 --- a/common/generated/intel_keym_v2.cpp +++ b/common/generated/intel_keym_v2.cpp @@ -6,38 +6,32 @@ intel_keym_v2_t::intel_keym_v2_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, intel_keym_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = this; (void)p__root; - m_header = 0; - m_reserved = 0; - m_km_hashes = 0; - m_key_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_header = nullptr; + m_reserved = nullptr; + m_km_hashes = nullptr; + m_key_signature = nullptr; + _read(); } void intel_keym_v2_t::_read() { - m_header = new header_t(m__io, this, m__root); + m_header = std::unique_ptr(new header_t(m__io, this, m__root)); m_key_signature_offset = m__io->read_u2le(); - m_reserved = new std::vector(); + m_reserved = std::unique_ptr>(new std::vector()); const int l_reserved = 3; for (int i = 0; i < l_reserved; i++) { - m_reserved->push_back(m__io->read_u1()); + m_reserved->push_back(std::move(m__io->read_u1())); } m_km_version = m__io->read_u1(); m_km_svn = m__io->read_u1(); m_km_id = m__io->read_u1(); m_fpf_hash_algorithm_id = m__io->read_u2le(); m_num_km_hashes = m__io->read_u2le(); - m_km_hashes = new std::vector(); + m_km_hashes = std::unique_ptr>>(new std::vector>()); const int l_km_hashes = num_km_hashes(); for (int i = 0; i < l_km_hashes; i++) { - m_km_hashes->push_back(new km_hash_t(m__io, this, m__root)); + m_km_hashes->push_back(std::move(std::unique_ptr(new km_hash_t(m__io, this, m__root)))); } - m_key_signature = new key_signature_t(m__io, this, m__root); + m_key_signature = std::unique_ptr(new key_signature_t(m__io, this, m__root)); } intel_keym_v2_t::~intel_keym_v2_t() { @@ -45,43 +39,22 @@ intel_keym_v2_t::~intel_keym_v2_t() { } void intel_keym_v2_t::_clean_up() { - if (m_header) { - delete m_header; m_header = 0; - } - if (m_reserved) { - delete m_reserved; m_reserved = 0; - } - if (m_km_hashes) { - for (std::vector::iterator it = m_km_hashes->begin(); it != m_km_hashes->end(); ++it) { - delete *it; - } - delete m_km_hashes; m_km_hashes = 0; - } - if (m_key_signature) { - delete m_key_signature; m_key_signature = 0; - } } intel_keym_v2_t::key_signature_t::key_signature_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent, intel_keym_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - m_public_key = 0; - m_signature = 0; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + m_public_key = nullptr; + m_signature = nullptr; + _read(); } void intel_keym_v2_t::key_signature_t::_read() { m_version = m__io->read_u1(); m_key_id = m__io->read_u2le(); - m_public_key = new public_key_t(m__io, this, m__root); + m_public_key = std::unique_ptr(new public_key_t(m__io, this, m__root)); m_sig_scheme = m__io->read_u2le(); - m_signature = new signature_t(m__io, this, m__root); + m_signature = std::unique_ptr(new signature_t(m__io, this, m__root)); } intel_keym_v2_t::key_signature_t::~key_signature_t() { @@ -89,24 +62,12 @@ intel_keym_v2_t::key_signature_t::~key_signature_t() { } void intel_keym_v2_t::key_signature_t::_clean_up() { - if (m_public_key) { - delete m_public_key; m_public_key = 0; - } - if (m_signature) { - delete m_signature; m_signature = 0; - } } intel_keym_v2_t::km_hash_t::km_hash_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent, intel_keym_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v2_t::km_hash_t::_read() { @@ -126,13 +87,7 @@ void intel_keym_v2_t::km_hash_t::_clean_up() { intel_keym_v2_t::signature_t::signature_t(kaitai::kstream* p__io, intel_keym_v2_t::key_signature_t* p__parent, intel_keym_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v2_t::signature_t::_read() { @@ -152,13 +107,7 @@ void intel_keym_v2_t::signature_t::_clean_up() { intel_keym_v2_t::public_key_t::public_key_t(kaitai::kstream* p__io, intel_keym_v2_t::key_signature_t* p__parent, intel_keym_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v2_t::public_key_t::_read() { @@ -178,13 +127,7 @@ void intel_keym_v2_t::public_key_t::_clean_up() { intel_keym_v2_t::header_t::header_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent, intel_keym_v2_t* p__root) : kaitai::kstruct(p__io) { m__parent = p__parent; m__root = p__root; - - try { - _read(); - } catch(...) { - _clean_up(); - throw; - } + _read(); } void intel_keym_v2_t::header_t::_read() { diff --git a/common/generated/intel_keym_v2.h b/common/generated/intel_keym_v2.h index 40208b7..1512652 100644 --- a/common/generated/intel_keym_v2.h +++ b/common/generated/intel_keym_v2.h @@ -1,10 +1,10 @@ -#ifndef INTEL_KEYM_V2_H_ -#define INTEL_KEYM_V2_H_ +#pragma once // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild #include "../kaitai/kaitaistruct.h" #include +#include #include #if KAITAI_STRUCT_VERSION < 9000L @@ -31,7 +31,7 @@ public: KM_USAGE_FLAGS_SDEV = 8 }; - intel_keym_v2_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, intel_keym_v2_t* p__root = 0); + intel_keym_v2_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, intel_keym_v2_t* p__root = nullptr); private: void _read(); @@ -44,7 +44,7 @@ public: public: - key_signature_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent = 0, intel_keym_v2_t* p__root = 0); + key_signature_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent = nullptr, intel_keym_v2_t* p__root = nullptr); private: void _read(); @@ -56,18 +56,18 @@ public: private: uint8_t m_version; uint16_t m_key_id; - public_key_t* m_public_key; + std::unique_ptr m_public_key; uint16_t m_sig_scheme; - signature_t* m_signature; + std::unique_ptr m_signature; intel_keym_v2_t* m__root; intel_keym_v2_t* m__parent; public: uint8_t version() const { return m_version; } uint16_t key_id() const { return m_key_id; } - public_key_t* public_key() const { return m_public_key; } + public_key_t* public_key() const { return m_public_key.get(); } uint16_t sig_scheme() const { return m_sig_scheme; } - signature_t* signature() const { return m_signature; } + signature_t* signature() const { return m_signature.get(); } intel_keym_v2_t* _root() const { return m__root; } intel_keym_v2_t* _parent() const { return m__parent; } }; @@ -76,7 +76,7 @@ public: public: - km_hash_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent = 0, intel_keym_v2_t* p__root = 0); + km_hash_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent = nullptr, intel_keym_v2_t* p__root = nullptr); private: void _read(); @@ -106,7 +106,7 @@ public: public: - signature_t(kaitai::kstream* p__io, intel_keym_v2_t::key_signature_t* p__parent = 0, intel_keym_v2_t* p__root = 0); + signature_t(kaitai::kstream* p__io, intel_keym_v2_t::key_signature_t* p__parent = nullptr, intel_keym_v2_t* p__root = nullptr); private: void _read(); @@ -136,7 +136,7 @@ public: public: - public_key_t(kaitai::kstream* p__io, intel_keym_v2_t::key_signature_t* p__parent = 0, intel_keym_v2_t* p__root = 0); + public_key_t(kaitai::kstream* p__io, intel_keym_v2_t::key_signature_t* p__parent = nullptr, intel_keym_v2_t* p__root = nullptr); private: void _read(); @@ -166,7 +166,7 @@ public: public: - header_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent = 0, intel_keym_v2_t* p__root = 0); + header_t(kaitai::kstream* p__io, intel_keym_v2_t* p__parent = nullptr, intel_keym_v2_t* p__root = nullptr); private: void _read(); @@ -193,32 +193,30 @@ public: }; private: - header_t* m_header; + std::unique_ptr m_header; uint16_t m_key_signature_offset; - std::vector* m_reserved; + std::unique_ptr> m_reserved; uint8_t m_km_version; uint8_t m_km_svn; uint8_t m_km_id; uint16_t m_fpf_hash_algorithm_id; uint16_t m_num_km_hashes; - std::vector* m_km_hashes; - key_signature_t* m_key_signature; + std::unique_ptr>> m_km_hashes; + std::unique_ptr m_key_signature; intel_keym_v2_t* m__root; kaitai::kstruct* m__parent; public: - header_t* header() const { return m_header; } + header_t* header() const { return m_header.get(); } uint16_t key_signature_offset() const { return m_key_signature_offset; } - std::vector* reserved() const { return m_reserved; } + std::vector* reserved() const { return m_reserved.get(); } uint8_t km_version() const { return m_km_version; } uint8_t km_svn() const { return m_km_svn; } uint8_t km_id() const { return m_km_id; } uint16_t fpf_hash_algorithm_id() const { return m_fpf_hash_algorithm_id; } uint16_t num_km_hashes() const { return m_num_km_hashes; } - std::vector* km_hashes() const { return m_km_hashes; } - key_signature_t* key_signature() const { return m_key_signature; } + std::vector>* km_hashes() const { return m_km_hashes.get(); } + key_signature_t* key_signature() const { return m_key_signature.get(); } intel_keym_v2_t* _root() const { return m__root; } kaitai::kstruct* _parent() const { return m__parent; } }; - -#endif // INTEL_KEYM_V2_H_ diff --git a/common/nvramparser.cpp b/common/nvramparser.cpp index 2b7fbee..68b7454 100755 --- a/common/nvramparser.cpp +++ b/common/nvramparser.cpp @@ -125,7 +125,7 @@ USTATUS NvramParser::parseNvarStore(const UModelIndex & index) UModelIndex prevEntryIndex; if (currentEntryIndex > 0) { for (UINT32 i = currentEntryIndex - 1; i > 0; i--) { - const auto previousEntry = parsed.entries()->at(i); + const auto & previousEntry = parsed.entries()->at(i); if (previousEntry == entry) break; diff --git a/kaitai_regenerate.sh b/kaitai_regenerate.sh index 2b3a490..4c2a881 100755 --- a/kaitai_regenerate.sh +++ b/kaitai_regenerate.sh @@ -20,7 +20,7 @@ fi # Generate echo "Attempting to to generate parsers from Kaitai KSY files on ${UPLATFORM}..." -kaitai-struct-compiler --target cpp_stl --outdir common/generated common/ksy/* || exit 1 +kaitai-struct-compiler --target cpp_stl --cpp-standard 11 --outdir common/generated common/ksy/* || exit 1 # Show generated files ${UFIND} common/generated ${UFINDOPT} \ @@ -46,5 +46,10 @@ ${UFIND} common/generated ${UFINDOPT} \ ${UFIND} common/generated ${UFINDOPT} \ -regex '.*\.(h)' \ -exec sed -i ${USEDOPT} '/^ enum structure_ids_t {/s/{/: uint64_t {/g' {} + || exit 1 - + +# Suppress type downcast warning in ami_nvar.cpp +${UFIND} common/generated ${UFINDOPT} \ + -name 'ami_nvar.cpp' \ + -exec sed -i ${USEDOPT} 's/_offset = _io()->pos();/_offset = (int32_t)_io()->pos();/g' {} + || exit 1 + exit 0