Add Phoenix FlashMap parser

This commit is contained in:
Nikolaj Schlej 2025-02-25 10:31:28 +07:00
parent 6672450aef
commit af14650f4e
20 changed files with 412 additions and 39 deletions

View file

@ -23,7 +23,7 @@ void edk2_vss_t::_read() {
m_vss_size = m__io->read_u4le();
{
uint32_t _ = vss_size();
if (!( ((_ > len_vss_store_header()) && (_ < 4294967295UL)) )) {
if (!( ((_ > static_cast<uint32_t>(len_vss_store_header())) && (_ < 4294967295UL)) )) {
throw kaitai::validation_expr_error<uint32_t>(vss_size(), _io(), std::string("/seq/1"));
}
}
@ -149,7 +149,7 @@ void edk2_vss_t::vss_variable_t::_read() {
m_len_total = m__io->read_u4le();
{
uint32_t _ = len_total();
if (!(_ >= ((len_intel_legacy_header() + 4) + 1))) {
if (!(_ >= ((static_cast<uint32_t>(len_intel_legacy_header()) + 4) + 1))) {
throw kaitai::validation_expr_error<uint32_t>(len_total(), _io(), std::string("/types/vss_variable/seq/5"));
}
}

View file

@ -47,7 +47,7 @@ void edk2_vss2_t::_read() {
m_vss2_size = m__io->read_u4le();
{
uint32_t _ = vss2_size();
if (!( ((_ > len_vss2_store_header()) && (_ < 4294967295UL)) )) {
if (!( ((_ > static_cast<uint32_t>(len_vss2_store_header())) && (_ < 4294967295UL)) )) {
throw kaitai::validation_expr_error<uint32_t>(vss2_size(), _io(), std::string("/seq/4"));
}
}

View file

@ -21,7 +21,7 @@ void insyde_fdc_t::_read() {
m_fdc_size = m__io->read_u4le();
{
uint32_t _ = fdc_size();
if (!( ((_ > len_fdc_store_header()) && (_ < 4294967295UL)) )) {
if (!( ((_ > static_cast<uint32_t>(len_fdc_store_header())) && (_ < 4294967295UL)) )) {
throw kaitai::validation_expr_error<uint32_t>(fdc_size(), _io(), std::string("/seq/1"));
}
}

View file

@ -0,0 +1,93 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "phoenix_flm.h"
#include "../kaitai/exceptions.h"
phoenix_flm_t::phoenix_flm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, phoenix_flm_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this; (void)p__root;
m_entries = nullptr;
m_free_space = nullptr;
f_len_flm_store = false;
f_len_flm_store_header = false;
f_len_flm_entry = false;
_read();
}
void phoenix_flm_t::_read() {
m_signature = m__io->read_bytes(10);
if (!(signature() == std::string("\x5F\x46\x4C\x41\x53\x48\x5F\x4D\x41\x50", 10))) {
throw kaitai::validation_not_equal_error<std::string>(std::string("\x5F\x46\x4C\x41\x53\x48\x5F\x4D\x41\x50", 10), signature(), _io(), std::string("/seq/0"));
}
m_num_entries = m__io->read_u2le();
{
uint16_t _ = num_entries();
if (!(_ <= 113)) {
throw kaitai::validation_expr_error<uint16_t>(num_entries(), _io(), std::string("/seq/1"));
}
}
m_reserved = m__io->read_u4le();
m_entries = std::unique_ptr<std::vector<std::unique_ptr<flm_entry_t>>>(new std::vector<std::unique_ptr<flm_entry_t>>());
const int l_entries = num_entries();
for (int i = 0; i < l_entries; i++) {
m_entries->push_back(std::move(std::unique_ptr<flm_entry_t>(new flm_entry_t(m__io, this, m__root))));
}
m_free_space = std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
const int l_free_space = ((len_flm_store() - len_flm_store_header()) - (len_flm_entry() * num_entries()));
for (int i = 0; i < l_free_space; i++) {
m_free_space->push_back(std::move(m__io->read_u1()));
}
}
phoenix_flm_t::~phoenix_flm_t() {
_clean_up();
}
void phoenix_flm_t::_clean_up() {
}
phoenix_flm_t::flm_entry_t::flm_entry_t(kaitai::kstream* p__io, phoenix_flm_t* p__parent, phoenix_flm_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
_read();
}
void phoenix_flm_t::flm_entry_t::_read() {
m_guid = m__io->read_bytes(16);
m_data_type = m__io->read_u2le();
m_entry_type = m__io->read_u2le();
m_physical_address = m__io->read_u8le();
m_size = m__io->read_u4le();
m_offset = m__io->read_u4le();
}
phoenix_flm_t::flm_entry_t::~flm_entry_t() {
_clean_up();
}
void phoenix_flm_t::flm_entry_t::_clean_up() {
}
int32_t phoenix_flm_t::len_flm_store() {
if (f_len_flm_store)
return m_len_flm_store;
m_len_flm_store = 4096;
f_len_flm_store = true;
return m_len_flm_store;
}
int8_t phoenix_flm_t::len_flm_store_header() {
if (f_len_flm_store_header)
return m_len_flm_store_header;
m_len_flm_store_header = 16;
f_len_flm_store_header = true;
return m_len_flm_store_header;
}
int8_t phoenix_flm_t::len_flm_entry() {
if (f_len_flm_entry)
return m_len_flm_entry;
m_len_flm_entry = 36;
f_len_flm_entry = true;
return m_len_flm_entry;
}

View file

@ -0,0 +1,100 @@
#pragma once
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "../kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>
#include <vector>
#if KAITAI_STRUCT_VERSION < 9000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required"
#endif
class phoenix_flm_t : public kaitai::kstruct {
public:
class flm_entry_t;
phoenix_flm_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, phoenix_flm_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~phoenix_flm_t();
class flm_entry_t : public kaitai::kstruct {
public:
flm_entry_t(kaitai::kstream* p__io, phoenix_flm_t* p__parent = nullptr, phoenix_flm_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~flm_entry_t();
private:
std::string m_guid;
uint16_t m_data_type;
uint16_t m_entry_type;
uint64_t m_physical_address;
uint32_t m_size;
uint32_t m_offset;
phoenix_flm_t* m__root;
phoenix_flm_t* m__parent;
public:
std::string guid() const { return m_guid; }
uint16_t data_type() const { return m_data_type; }
uint16_t entry_type() const { return m_entry_type; }
uint64_t physical_address() const { return m_physical_address; }
uint32_t size() const { return m_size; }
uint32_t offset() const { return m_offset; }
phoenix_flm_t* _root() const { return m__root; }
phoenix_flm_t* _parent() const { return m__parent; }
};
private:
bool f_len_flm_store;
int32_t m_len_flm_store;
public:
int32_t len_flm_store();
private:
bool f_len_flm_store_header;
int8_t m_len_flm_store_header;
public:
int8_t len_flm_store_header();
private:
bool f_len_flm_entry;
int8_t m_len_flm_entry;
public:
int8_t len_flm_entry();
private:
std::string m_signature;
uint16_t m_num_entries;
uint32_t m_reserved;
std::unique_ptr<std::vector<std::unique_ptr<flm_entry_t>>> m_entries;
std::unique_ptr<std::vector<uint8_t>> m_free_space;
phoenix_flm_t* m__root;
kaitai::kstruct* m__parent;
public:
std::string signature() const { return m_signature; }
uint16_t num_entries() const { return m_num_entries; }
uint32_t reserved() const { return m_reserved; }
std::vector<std::unique_ptr<flm_entry_t>>* entries() const { return m_entries.get(); }
std::vector<uint8_t>* free_space() const { return m_free_space.get(); }
phoenix_flm_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};