Skip to content

Commit

Permalink
Update kaitai runtime to the current version from the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajSchlej committed Feb 14, 2025
1 parent fd76e89 commit 9fbe700
Show file tree
Hide file tree
Showing 9 changed files with 694 additions and 102 deletions.
2 changes: 1 addition & 1 deletion UEFITool/qhexview5/qhexview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ void QHexView::mouseMoveEvent(QMouseEvent* e)
void QHexView::wheelEvent(QWheelEvent* e)
{
e->ignore();
#if defined Q_OS_OSX
#if defined Q_OS_MACOS
// In macOS scrollbar invisibility should not prevent scrolling from working
if(!m_hexdocument) return;
#else
Expand Down
40 changes: 34 additions & 6 deletions common/generated/ami_nvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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;
m__root = this; (void)p__root;
m_entries = nullptr;
_read();
}
Expand Down Expand Up @@ -188,22 +188,23 @@ 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;
}

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;
}

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_ascii_name = nullptr;
m_ucs2_name = nullptr;
m_extended_header_attributes = nullptr;
f_extended_header_attributes = false;
Expand Down Expand Up @@ -232,7 +233,7 @@ void ami_nvar_t::nvar_entry_body_t::_read() {
n_ascii_name = true;
if ( ((_parent()->attributes()->ascii_name()) && (!(_parent()->attributes()->data_only())) && (_parent()->attributes()->valid())) ) {
n_ascii_name = false;
m_ascii_name = kaitai::kstream::bytes_to_str(m__io->read_bytes_term(0, false, true, true), std::string("ASCII"));
m_ascii_name = std::unique_ptr<ascii_string_t>(new ascii_string_t(m__io, this, m__root));
}
n_ucs2_name = true;
if ( ((!(_parent()->attributes()->ascii_name())) && (!(_parent()->attributes()->data_only())) && (_parent()->attributes()->valid())) ) {
Expand Down Expand Up @@ -292,7 +293,7 @@ ami_nvar_t::nvar_extended_attributes_t* ami_nvar_t::nvar_entry_body_t::extended_
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;
}
Expand Down Expand Up @@ -353,7 +354,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;
}
Expand All @@ -380,3 +381,30 @@ std::string ami_nvar_t::nvar_entry_body_t::extended_header_hash() {
}
return m_extended_header_hash;
}

ami_nvar_t::ascii_string_t::ascii_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_ascii_chars = nullptr;
_read();
}

void ami_nvar_t::ascii_string_t::_read() {
m_ascii_chars = std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
{
int i = 0;
uint8_t _;
do {
_ = m__io->read_u1();
m_ascii_chars->push_back(_);
i++;
} while (!(_ == 0));
}
}

ami_nvar_t::ascii_string_t::~ascii_string_t() {
_clean_up();
}

void ami_nvar_t::ascii_string_t::_clean_up() {
}
29 changes: 27 additions & 2 deletions common/generated/ami_nvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ami_nvar_t : public kaitai::kstruct {
class nvar_extended_attributes_t;
class nvar_entry_t;
class nvar_entry_body_t;
class ascii_string_t;

ami_nvar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, ami_nvar_t* p__root = nullptr);

Expand Down Expand Up @@ -348,7 +349,7 @@ class ami_nvar_t : public kaitai::kstruct {
bool _is_null_guid() { guid(); return n_guid; };

private:
std::string m_ascii_name;
std::unique_ptr<ascii_string_t> m_ascii_name;
bool n_ascii_name;

public:
Expand Down Expand Up @@ -376,14 +377,38 @@ class ami_nvar_t : public kaitai::kstruct {
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; }
ascii_string_t* ascii_name() const { return m_ascii_name.get(); }
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; }
ami_nvar_t::nvar_entry_t* _parent() const { return m__parent; }
};

class ascii_string_t : public kaitai::kstruct {

public:

ascii_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();
void _clean_up();

public:
~ascii_string_t();

private:
std::unique_ptr<std::vector<uint8_t>> m_ascii_chars;
ami_nvar_t* m__root;
ami_nvar_t::nvar_entry_body_t* m__parent;

public:
std::vector<uint8_t>* ascii_chars() const { return m_ascii_chars.get(); }
ami_nvar_t* _root() const { return m__root; }
ami_nvar_t::nvar_entry_body_t* _parent() const { return m__parent; }
};

private:
std::unique_ptr<std::vector<std::unique_ptr<nvar_entry_t>>> m_entries;
ami_nvar_t* m__root;
Expand Down
82 changes: 69 additions & 13 deletions common/kaitai/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,57 @@

#include "kaitaistream.h"

#include <string>
#include <stdexcept>
#include <stdexcept> // std::runtime_error
#include <string> // std::string

// We need to use "noexcept" in virtual destructor of our exceptions
// subclasses. Different compilers have different ideas on how to
// achieve that: C++98 compilers prefer `throw()`, C++11 and later
// use `noexcept`. We define KS_NOEXCEPT macro for that.

#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
#ifdef KAITAI_STREAM_H_CPP11_SUPPORT
#define KS_NOEXCEPT noexcept
#else
#define KS_NOEXCEPT throw()
#endif

namespace kaitai {

/**
* Common ancestor for all errors related to `bytes_to_str` operation. Also used
* to signal misc non-specific `bytes_to_str` failures.
*/
class bytes_to_str_error: public std::runtime_error {
public:
bytes_to_str_error(const std::string what):
std::runtime_error(std::string("bytes_to_str error: ") + what) {}

virtual ~bytes_to_str_error() KS_NOEXCEPT {};
};

/**
* Exception to signal that `bytes_to_str` operation was requested to use some encoding
* that is not available in given runtime environment.
*/
class unknown_encoding: public bytes_to_str_error {
public:
unknown_encoding(const std::string enc_name):
bytes_to_str_error(std::string("unknown encoding: `") + enc_name + std::string("`")) {}

virtual ~unknown_encoding() KS_NOEXCEPT {};
};

/**
* Exception to signal that `bytes_to_str` operation failed to decode given byte sequence.
*/
class illegal_seq_in_encoding: public bytes_to_str_error {
public:
illegal_seq_in_encoding(const std::string what):
bytes_to_str_error("illegal sequence: " + what) {}

virtual ~illegal_seq_in_encoding() KS_NOEXCEPT {};
};

/**
* Common ancestor for all error originating from Kaitai Struct usage.
* Stores KSY source path, pointing to an element supposedly guilty of
Expand Down Expand Up @@ -80,7 +115,7 @@ class validation_failed_error: public kstruct_error {
template<typename T>
class validation_not_equal_error: public validation_failed_error {
public:
validation_not_equal_error<T>(const T& expected, const T& actual, kstream* io, const std::string src_path):
validation_not_equal_error(const T& expected, const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not equal", io, src_path),
m_expected(expected),
m_actual(actual)
Expand All @@ -89,7 +124,7 @@ class validation_not_equal_error: public validation_failed_error {

// "not equal, expected #{expected.inspect}, but got #{actual.inspect}"

virtual ~validation_not_equal_error<T>() KS_NOEXCEPT {};
virtual ~validation_not_equal_error() KS_NOEXCEPT {};

protected:
const T& m_expected;
Expand All @@ -103,7 +138,7 @@ class validation_not_equal_error: public validation_failed_error {
template<typename T>
class validation_less_than_error: public validation_failed_error {
public:
validation_less_than_error<T>(const T& min, const T& actual, kstream* io, const std::string src_path):
validation_less_than_error(const T& min, const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not in range", io, src_path),
m_min(min),
m_actual(actual)
Expand All @@ -112,7 +147,7 @@ class validation_less_than_error: public validation_failed_error {

// "not in range, min #{min.inspect}, but got #{actual.inspect}"

virtual ~validation_less_than_error<T>() KS_NOEXCEPT {};
virtual ~validation_less_than_error() KS_NOEXCEPT {};

protected:
const T& m_min;
Expand All @@ -126,7 +161,7 @@ class validation_less_than_error: public validation_failed_error {
template<typename T>
class validation_greater_than_error: public validation_failed_error {
public:
validation_greater_than_error<T>(const T& max, const T& actual, kstream* io, const std::string src_path):
validation_greater_than_error(const T& max, const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not in range", io, src_path),
m_max(max),
m_actual(actual)
Expand All @@ -135,7 +170,7 @@ class validation_greater_than_error: public validation_failed_error {

// "not in range, max #{max.inspect}, but got #{actual.inspect}"

virtual ~validation_greater_than_error<T>() KS_NOEXCEPT {};
virtual ~validation_greater_than_error() KS_NOEXCEPT {};

protected:
const T& m_max;
Expand All @@ -149,15 +184,36 @@ class validation_greater_than_error: public validation_failed_error {
template<typename T>
class validation_not_any_of_error: public validation_failed_error {
public:
validation_not_any_of_error<T>(const T& actual, kstream* io, const std::string src_path):
validation_not_any_of_error(const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not any of the list", io, src_path),
m_actual(actual)
{
}

// "not any of the list, got #{actual.inspect}"

virtual ~validation_not_any_of_error<T>() KS_NOEXCEPT {};
virtual ~validation_not_any_of_error() KS_NOEXCEPT {};

protected:
const T& m_actual;
};

/**
* Signals validation failure: we required "actual" value to be in
* the enum, but it turned out that it's not.
*/
template<typename T>
class validation_not_in_enum_error: public validation_failed_error {
public:
validation_not_in_enum_error(const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not in the enum", io, src_path),
m_actual(actual)
{
}

// "not in the enum, got #{actual.inspect}"

virtual ~validation_not_in_enum_error() KS_NOEXCEPT {};

protected:
const T& m_actual;
Expand All @@ -170,15 +226,15 @@ class validation_not_any_of_error: public validation_failed_error {
template<typename T>
class validation_expr_error: public validation_failed_error {
public:
validation_expr_error<T>(const T& actual, kstream* io, const std::string src_path):
validation_expr_error(const T& actual, kstream* io, const std::string src_path):
validation_failed_error("not matching the expression", io, src_path),
m_actual(actual)
{
}

// "not matching the expression, got #{actual.inspect}"

virtual ~validation_expr_error<T>() KS_NOEXCEPT {};
virtual ~validation_expr_error() KS_NOEXCEPT {};

protected:
const T& m_actual;
Expand Down
Loading

0 comments on commit 9fbe700

Please sign in to comment.