Skip to content

Instantly share code, notes, and snippets.

@kmod-midori
Created August 9, 2024 08:51
Show Gist options
  • Save kmod-midori/f57b260e25e6abedb3f63dfc2f683942 to your computer and use it in GitHub Desktop.
Save kmod-midori/f57b260e25e6abedb3f63dfc2f683942 to your computer and use it in GitHub Desktop.
ImHex Pattern for ZFS Vdev
#pragma endian big
#define VDEV_PAD_SIZE (8 << 10)
#define VDEV_PHYS_SIZE (112 << 10)
#define VDEV_UBERBLOCK_RING (128 << 10)
import std.mem;
enum nvpair_data_type_t: u32 {
boolean = 1,
uint64 = 8,
string = 9,
nvlist = 19,
};
struct nvpair_string_t {
u32 str_length;
char str_value[str_length];
padding[str_length % 4 == 0 ? 0 : (4 - str_length % 4)];
} [[format("format_nvpair_string_t")]];
using nvlist_t;
struct nvpair_t {
u32 encoded_size;
u32 decoded_size;
if (encoded_size == 0 && decoded_size == 0) {
break;
}
u32 name_len;
char name[name_len];
padding[name_len % 4 == 0 ? 0 : (4 - name_len % 4)];
nvpair_data_type_t data_type;
s32 num_elements;
match (data_type) {
// (nvpair_data_type_t::boolean):
(nvpair_data_type_t::string): nvpair_string_t values[num_elements] [[inline]];
(nvpair_data_type_t::uint64): u64 values[num_elements] [[inline]];
(nvpair_data_type_t::nvlist): nvlist_t values[num_elements] [[inline]];
}
} [[format("format_nvpair_t")]];
struct nvlist_t {
s32 version;
u32 flag;
nvpair_t pairs[100];
};
fn format_nvpair_t(nvpair_t pair) {
if (pair.encoded_size == 0 && pair.decoded_size == 0) {
return "(END)";
}
return pair.name;
};
fn format_nvpair_string_t(nvpair_string_t s) {
return s.str_value;
};
struct nvstream_t {
u8 encoding;
u8 endian;
u8 reserved1;
u8 reserved2;
nvlist_t embedded_list;
};
struct zio_eck_t {
u64 magic;
u64 cksum[4];
};
struct vdev_phys_t {
nvstream_t vp_nvlist;
padding[VDEV_PHYS_SIZE - sizeof(vp_nvlist) - sizeof(zio_eck_t)];
zio_eck_t vp_zbt;
};
struct vdev_boot_envblock_t {
u64 vbe_version;
padding[
VDEV_PAD_SIZE - sizeof(u64) - sizeof(zio_eck_t)
];
zio_eck_t vbe_zbt;
};
struct vdev_label_t {
padding[VDEV_PAD_SIZE]; // 8K
vdev_boot_envblock_t vl_be; // 8K
vdev_phys_t vl_vdev_phys;
padding[VDEV_UBERBLOCK_RING];
};
vdev_label_t label1 @ 0x00;
vdev_label_t label2 @ 0x40000;
vdev_label_t label3 @ std::mem::size() - 0x80000;
vdev_label_t label4 @ std::mem::size() - 0x40000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment