Skip to content

Commit

Permalink
Revert "fix til pointer flags"
Browse files Browse the repository at this point in the history
This reverts commit 7c91b3a.
  • Loading branch information
rbran committed Jan 7, 2025
1 parent 703d954 commit 0b5a123
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/til.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ impl TILTypeInfo {
let is_u64 = (flags >> 31) != 0;
let ordinal = match (til.format, is_u64) {
// formats below 0x12 doesn't have 64 bits ord
// TODO don't convert it directly into u64, tilib seems to handle
// u32 and u64 values diferently
(0..=0x11, _) | (_, false) => cursor.read_u32()?.into(),
(_, true) => cursor.read_u64()?,
};
Expand Down
61 changes: 30 additions & 31 deletions src/til/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ use crate::til::{Type, TypeRaw, TAH};
#[derive(Debug, Clone)]
pub struct Pointer {
pub closure: PointerType,
pub typ: Box<Type>,
pub modifier: Option<PointerModifier>,
pub shifted: Option<(Box<Type>, u32)>,
pub is_ptr32: bool,
pub is_ptr64: bool,
pub is_restricted: bool,
pub is_unknown_ta10: bool,
pub ta_lower: u8,
pub typ: Box<Type>,
}

impl Pointer {
Expand All @@ -36,13 +32,9 @@ impl Pointer {
Ok(Self {
// TODO forward fields to closure?
closure: PointerType::new(til, raw.closure)?,
typ,
modifier: raw.modifier,
shifted,
is_ptr32: raw.is_ptr32,
is_ptr64: raw.is_ptr64,
is_restricted: raw.is_restricted,
is_unknown_ta10: raw.is_unknown_ta10,
ta_lower: raw.ta_lower,
typ,
})
}
}
Expand Down Expand Up @@ -74,16 +66,19 @@ impl PointerType {
}
}

#[derive(Debug, Clone, Copy)]
pub enum PointerModifier {
Ptr32,
Ptr64,
Restricted,
}

#[derive(Debug, Clone)]
pub(crate) struct PointerRaw {
pub closure: PointerTypeRaw,
pub typ: Box<TypeRaw>,
pub is_ptr32: bool,
pub is_ptr64: bool,
pub is_restricted: bool,
pub is_unknown_ta10: bool,
pub modifier: Option<PointerModifier>,
pub shifted: Option<(Box<TypeRaw>, u32)>,
pub ta_lower: u8,
pub typ: Box<TypeRaw>,
}

impl PointerRaw {
Expand Down Expand Up @@ -112,28 +107,32 @@ impl PointerRaw {
let shifted = (tah.0 .0 & TAPTR_SHIFTED != 0)
.then(|| -> Result<_> {
// TODO allow typedef only?
// InnerRef fb47f2c2-3c08-4d40-b7ab-3c7736dce31d 0x459bc6 print_til_type_att
let typ = TypeRaw::read(&mut *input, header)?;
let value = input.read_de()?;
Ok((Box::new(typ), value))
})
.transpose()?;
let is_ptr32 = tah.0 .0 & TAPTR_PTR32 != 0;
let is_ptr64 = tah.0 .0 & TAPTR_PTR64 != 0;
let is_restricted = tah.0 .0 & TAPTR_RESTRICT != 0;
// TODO find the flag or doc for this
let is_unknown_ta10 = tah.0 .0 & 0x10 != 0;
let ta_lower = (tah.0 .0 & 0xf) as u8;

// InnerRef fb47f2c2-3c08-4d40-b7ab-3c7736dce31d 0x459bc6 print_til_type_att
let modifier = match tah.0 .0 & (TAPTR_RESTRICT | TAPTR_PTR64 | TAPTR_PTR32) {
0x00 => None,
TAPTR_PTR32 => Some(PointerModifier::Ptr32),
TAPTR_PTR64 => Some(PointerModifier::Ptr64),
TAPTR_RESTRICT => Some(PointerModifier::Restricted),
_ => unreachable!(),
};
// TODO other values are known to exist
//let all_flags = TAPTR_RESTRICT | TAPTR_PTR64 | TAPTR_PTR32 | TAPTR_SHIFTED;
//anyhow::ensure!(
// tah.0 .0 & !all_flags == 0,
// "Unknown value for pointer modifier"
//);

Ok(Self {
closure,
typ: Box::new(typ),
modifier,
shifted,
is_ptr32,
is_ptr64,
is_restricted,
is_unknown_ta10,
ta_lower,
typ: Box::new(typ),
})
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/tools/tilib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,12 @@ fn print_til_type_pointer(
if til_type.is_const {
write!(fmt, "const ")?;
}
if pointer.is_ptr32 {
write!(fmt, "__ptr32 ")?;
} else {
if pointer.is_ptr64 {
write!(fmt, "__ptr64 ")?;
} else {
if pointer.is_restricted {
write!(fmt, "__restricted ")?;
}
match pointer.modifier {
None => {}
Some(idb_rs::til::pointer::PointerModifier::Ptr32) => write!(fmt, "__ptr32 ")?,
Some(idb_rs::til::pointer::PointerModifier::Ptr64) => write!(fmt, "__ptr64 ")?,
Some(idb_rs::til::pointer::PointerModifier::Restricted) => {
write!(fmt, "__restricted ")?
}
}
if let Some((ty, value)) = &pointer.shifted {
Expand Down Expand Up @@ -560,7 +557,7 @@ fn print_til_type_function(
write!(fmt, ", ")?;
}
let param_name = param_name.as_ref().map(Vec::as_slice);
print_til_type(fmt, section, param_name, param, true, true, true)?;
print_til_type(fmt, section, param_name, param, true, false, true)?;
}
match til_function.calling_convention {
Some(CallingConvention::Voidarg) => write!(fmt, "void")?,
Expand Down Expand Up @@ -675,7 +672,7 @@ fn print_til_type_complex_ref(
fmt.write_all(name)?;
}
} else {
print_til_type_typedef(fmt, section, name, til_type, typedef, true)?;
print_til_type_typedef(fmt, section, name, til_type, typedef, print_prefix)?;
}
Ok(())
}
Expand Down

0 comments on commit 0b5a123

Please sign in to comment.