Skip to content

Commit

Permalink
add til struct modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed Dec 14, 2024
1 parent 5f31350 commit 2f761d2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/til/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use anyhow::ensure;

use crate::ida_reader::IdaGenericBufUnpack;
use crate::til::section::TILSectionHeader;
use crate::til::{Type, TypeRaw, TAH};
Expand Down Expand Up @@ -89,6 +87,7 @@ impl PointerRaw {
}

// TODO find the flag for this
// InnerRef fb47f2c2-3c08-4d40-b7ab-3c7736dce31d 0x459bc6 print_til_type_att
let modifier = match tah.0 .0 & 0x60 {
0x00 => None,
0x20 => Some(PointerModifier::Ptr32),
Expand Down
44 changes: 30 additions & 14 deletions src/til/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use anyhow::{anyhow, Context, Result};
pub enum Struct {
Ref {
ref_type: Box<Type>,
taudt_bits: SDACL,
},
NonRef {
effective_alignment: u16,
taudt_bits: SDACL,
modifiers: Vec<StructModifier>,
members: Vec<StructMember>,
},
}
Expand All @@ -22,30 +21,26 @@ impl Struct {
fields: Option<Vec<Vec<u8>>>,
) -> Result<Self> {
match value {
StructRaw::Ref {
ref_type,
taudt_bits,
} => {
StructRaw::Ref { ref_type } => {
if matches!(&fields, Some(f) if !f.is_empty()) {
return Err(anyhow!("fields in a Ref Struct"));
}
Ok(Struct::Ref {
ref_type: Type::new(til, *ref_type, None).map(Box::new)?,
taudt_bits,
})
}
StructRaw::NonRef {
effective_alignment,
taudt_bits,
members,
modifiers,
} => {
let members = associate_field_name_and_member(fields, members)
.context("Struct")?
.map(|(n, m)| StructMember::new(til, n, m))
.collect::<anyhow::Result<_, _>>()?;
Ok(Struct::NonRef {
effective_alignment,
taudt_bits,
modifiers,
members,
})
}
Expand All @@ -57,11 +52,10 @@ impl Struct {
pub(crate) enum StructRaw {
Ref {
ref_type: Box<TypeRaw>,
taudt_bits: SDACL,
},
NonRef {
effective_alignment: u16,
taudt_bits: SDACL,
modifiers: Vec<StructModifier>,
members: Vec<StructMemberRaw>,
},
}
Expand All @@ -73,10 +67,9 @@ impl StructRaw {
// InnerRef fb47f2c2-3c08-4d40-b7ab-3c7736dce31d 0x4803b4
// simple reference
let ref_type = TypeRaw::read_ref(&mut *input, header)?;
let taudt_bits = SDACL::read(&mut *input)?;
let _taudt_bits = SDACL::read(&mut *input)?;
return Ok(Self::Ref {
ref_type: Box::new(ref_type),
taudt_bits,
});
};

Expand All @@ -89,14 +82,37 @@ impl StructRaw {
let members = (0..mem_cnt)
.map(|_| StructMemberRaw::read(&mut *input, header, taudt_bits.0 .0))
.collect::<Result<_, _>>()?;

// InnerRef fb47f2c2-3c08-4d40-b7ab-3c7736dce31d 0x46c4fc print_til_types_att
let have_attribute = taudt_bits.0 .0 & 0x20 != 0;
let is_cpp = taudt_bits.0 .0 & 0x80 != 0;
let is_unaligned = taudt_bits.0 .0 & 0x40 != 0;
let have_other = taudt_bits.0 .0 & !0xE0 != 0;
let modifiers = is_cpp
.then_some(StructModifier::CppObj)
.into_iter()
.chain(is_unaligned.then_some(StructModifier::Unaligned))
.chain(have_attribute.then_some(StructModifier::Attribute))
.chain(have_other.then_some(StructModifier::Unknown))
.collect();
Ok(Self::NonRef {
effective_alignment,
taudt_bits,
modifiers,
members,
})
}
}

#[derive(Clone, Copy, Debug)]
pub enum StructModifier {
Unaligned,
// TODO include the att value indide this
Attribute,
CppObj,
/// Value of the att is unknown with unknown meaning
Unknown,
}

#[derive(Clone, Debug)]
pub struct StructMember {
pub name: Option<Vec<u8>>,
Expand Down
19 changes: 17 additions & 2 deletions src/tools/tilib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,24 @@ fn print_til_type(
print_pointer_space,
print_type_prefix,
),
Struct::NonRef { members, .. } => {
Struct::NonRef {
members, modifiers, ..
} => {
let name = name.unwrap_or("");
write!(fmt, "struct {name} {{")?;
write!(fmt, "struct ")?;
for modifier in modifiers {
match modifier {
idb_rs::til::r#struct::StructModifier::Unaligned => {
write!(fmt, "__unaligned ")?
}
idb_rs::til::r#struct::StructModifier::Attribute => {
write!(fmt, "__attribute__((msstruct)) ")?
}
idb_rs::til::r#struct::StructModifier::CppObj => write!(fmt, "__cppobj ")?,
idb_rs::til::r#struct::StructModifier::Unknown => write!(fmt, "__other ")?,
}
}
write!(fmt, "{name} {{")?;
for member in members {
let name = member
.name
Expand Down

0 comments on commit 2f761d2

Please sign in to comment.