Add Apple SysF/Diag parser

This commit is contained in:
Nikolaj Schlej 2025-02-24 18:12:02 +07:00
parent 2d6eaa917f
commit 4e600eb986
17 changed files with 597 additions and 154 deletions

View file

@ -0,0 +1,115 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "apple_sysf.h"
#include "../kaitai/exceptions.h"
apple_sysf_t::apple_sysf_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, apple_sysf_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this; (void)p__root;
m_body = nullptr;
m__io__raw_body = nullptr;
f_len_sysf_store_header = false;
_read();
}
void apple_sysf_t::_read() {
m_signature = m__io->read_u4le();
{
uint32_t _ = signature();
if (!( ((_ == 1937339206) || (_ == 1684627783)) )) {
throw kaitai::validation_expr_error<uint32_t>(signature(), _io(), std::string("/seq/0"));
}
}
m_unknown = m__io->read_u1();
m_unknown1 = m__io->read_u4le();
m_sysf_size = m__io->read_u2le();
m__raw_body = m__io->read_bytes(((sysf_size() - len_sysf_store_header()) - 4));
m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
m_body = std::unique_ptr<sysf_store_body_t>(new sysf_store_body_t(m__io__raw_body.get(), this, m__root));
m_crc = m__io->read_u4le();
}
apple_sysf_t::~apple_sysf_t() {
_clean_up();
}
void apple_sysf_t::_clean_up() {
}
apple_sysf_t::sysf_store_body_t::sysf_store_body_t(kaitai::kstream* p__io, apple_sysf_t* p__parent, apple_sysf_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_variables = nullptr;
m_zeroes = nullptr;
_read();
}
void apple_sysf_t::sysf_store_body_t::_read() {
m_variables = std::unique_ptr<std::vector<std::unique_ptr<sysf_variable_t>>>(new std::vector<std::unique_ptr<sysf_variable_t>>());
{
int i = 0;
sysf_variable_t* _;
do {
_ = new sysf_variable_t(m__io, this, m__root);
m_variables->push_back(std::move(std::unique_ptr<sysf_variable_t>(_)));
i++;
} while (!( (( ((_->len_name() == 3) && (_->name() == (std::string("EOF")))) ) || (_io()->is_eof())) ));
}
m_zeroes = std::unique_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
{
int i = 0;
while (!m__io->is_eof()) {
m_zeroes->push_back(std::move(m__io->read_u1()));
i++;
}
}
}
apple_sysf_t::sysf_store_body_t::~sysf_store_body_t() {
_clean_up();
}
void apple_sysf_t::sysf_store_body_t::_clean_up() {
}
apple_sysf_t::sysf_variable_t::sysf_variable_t(kaitai::kstream* p__io, apple_sysf_t::sysf_store_body_t* p__parent, apple_sysf_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
_read();
}
void apple_sysf_t::sysf_variable_t::_read() {
m_len_name = m__io->read_bits_int_le(7);
m_invalid_flag = m__io->read_bits_int_le(1);
m__io->align_to_byte();
m_name = kaitai::kstream::bytes_to_str(kaitai::kstream::bytes_terminate(m__io->read_bytes(len_name()), 0, false), std::string("ascii"));
n_len_data = true;
if (name() != std::string("EOF")) {
n_len_data = false;
m_len_data = m__io->read_u2le();
}
n_data = true;
if (name() != std::string("EOF")) {
n_data = false;
m_data = m__io->read_bytes(len_data());
}
}
apple_sysf_t::sysf_variable_t::~sysf_variable_t() {
_clean_up();
}
void apple_sysf_t::sysf_variable_t::_clean_up() {
if (!n_len_data) {
}
if (!n_data) {
}
}
int8_t apple_sysf_t::len_sysf_store_header() {
if (f_len_sysf_store_header)
return m_len_sysf_store_header;
m_len_sysf_store_header = 11;
f_len_sysf_store_header = true;
return m_len_sysf_store_header;
}

View file

@ -0,0 +1,129 @@
#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 apple_sysf_t : public kaitai::kstruct {
public:
class sysf_store_body_t;
class sysf_variable_t;
apple_sysf_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, apple_sysf_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~apple_sysf_t();
class sysf_store_body_t : public kaitai::kstruct {
public:
sysf_store_body_t(kaitai::kstream* p__io, apple_sysf_t* p__parent = nullptr, apple_sysf_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~sysf_store_body_t();
private:
std::unique_ptr<std::vector<std::unique_ptr<sysf_variable_t>>> m_variables;
std::unique_ptr<std::vector<uint8_t>> m_zeroes;
apple_sysf_t* m__root;
apple_sysf_t* m__parent;
public:
std::vector<std::unique_ptr<sysf_variable_t>>* variables() const { return m_variables.get(); }
std::vector<uint8_t>* zeroes() const { return m_zeroes.get(); }
apple_sysf_t* _root() const { return m__root; }
apple_sysf_t* _parent() const { return m__parent; }
};
class sysf_variable_t : public kaitai::kstruct {
public:
sysf_variable_t(kaitai::kstream* p__io, apple_sysf_t::sysf_store_body_t* p__parent = nullptr, apple_sysf_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~sysf_variable_t();
private:
uint64_t m_len_name;
bool m_invalid_flag;
std::string m_name;
uint16_t m_len_data;
bool n_len_data;
public:
bool _is_null_len_data() { len_data(); return n_len_data; };
private:
std::string m_data;
bool n_data;
public:
bool _is_null_data() { data(); return n_data; };
private:
apple_sysf_t* m__root;
apple_sysf_t::sysf_store_body_t* m__parent;
public:
uint64_t len_name() const { return m_len_name; }
bool invalid_flag() const { return m_invalid_flag; }
std::string name() const { return m_name; }
uint16_t len_data() const { return m_len_data; }
std::string data() const { return m_data; }
apple_sysf_t* _root() const { return m__root; }
apple_sysf_t::sysf_store_body_t* _parent() const { return m__parent; }
};
private:
bool f_len_sysf_store_header;
int8_t m_len_sysf_store_header;
public:
int8_t len_sysf_store_header();
private:
uint32_t m_signature;
uint8_t m_unknown;
uint32_t m_unknown1;
uint16_t m_sysf_size;
std::unique_ptr<sysf_store_body_t> m_body;
uint32_t m_crc;
apple_sysf_t* m__root;
kaitai::kstruct* m__parent;
std::string m__raw_body;
std::unique_ptr<kaitai::kstream> m__io__raw_body;
public:
uint32_t signature() const { return m_signature; }
uint8_t unknown() const { return m_unknown; }
uint32_t unknown1() const { return m_unknown1; }
uint16_t sysf_size() const { return m_sysf_size; }
sysf_store_body_t* body() const { return m_body.get(); }
uint32_t crc() const { return m_crc; }
apple_sysf_t* _root() const { return m__root; }
kaitai::kstruct* _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.get(); }
};