hex_patch/headers/
section.rs

1use std::fmt::Display;
2
3use mlua::UserData;
4
5#[derive(Debug, PartialEq, Eq, Clone)]
6pub struct Section {
7    pub name: String,
8    pub virtual_address: u64,
9    pub file_offset: u64,
10    pub size: u64,
11}
12
13impl Display for Section {
14    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15        write!(
16            f,
17            "{}: [{:X} - {:X})",
18            self.name,
19            self.file_offset,
20            self.file_offset + self.size
21        )
22    }
23}
24
25impl UserData for Section {
26    fn add_fields<'lua, F: mlua::UserDataFields<Self>>(fields: &mut F) {
27        fields.add_field_method_get("name", |_, this| Ok(this.name.clone()));
28        fields.add_field_method_get("virtual_address", |_, this| Ok(this.virtual_address));
29        fields.add_field_method_get("file_offset", |_, this| Ok(this.file_offset));
30        fields.add_field_method_get("size", |_, this| Ok(this.size));
31    }
32}