Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand the tilib implementation #31

Merged
merged 53 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0dda790
fix tilib cc print format
rbran Dec 30, 2024
5ef02d6
fix tilib invalid utf8 names
rbran Dec 31, 2024
fa6f8f8
add todos for tilib prints
rbran Dec 31, 2024
0448520
restrict til complex ref to typedefs
rbran Dec 31, 2024
8122efc
fix tilib enum/struct embed types
rbran Jan 2, 2025
f8ec1b8
fix tilib unamed complex ref types definitions
rbran Jan 2, 2025
3e9ea5e
follow clippy sugestions
rbran Jan 2, 2025
5ff6614
add til type ext att offset
rbran Jan 2, 2025
c0dee1f
add til basic type ext att parsing
rbran Jan 2, 2025
3319897
fix tilib not removing "_" from some symbols
rbran Jan 2, 2025
a39825b
fix tilib missing prefix name for complex ref
rbran Jan 3, 2025
651f579
fix tilib small formting issues
rbran Jan 3, 2025
65917c7
fix tilib enum format printing
rbran Jan 3, 2025
4398268
fix tilib missing vft flag
rbran Jan 3, 2025
f84cb0a
add tilib bitfield implementation
rbran Jan 3, 2025
e813ba6
add til struct unknown flag 8
rbran Jan 3, 2025
530b027
add tilib basic type offset att
rbran Jan 3, 2025
94a8aa7
fix tilib wrong struct alignment value
rbran Jan 3, 2025
c6e02c6
fix tilib missing basic offset att
rbran Jan 3, 2025
7b51fd8
fix tilib function not printing void for no args
rbran Jan 3, 2025
716ea99
fix tilib function not printing some flags
rbran Jan 6, 2025
b4c9ede
fix tilib const/volatile flag location
rbran Jan 6, 2025
3eefb5f
fix tilib multiple small print issues
rbran Jan 6, 2025
360a4da
fix til bitfield size calculation
rbran Jan 6, 2025
6ceee81
improve til type size calculation
rbran Jan 6, 2025
7c91b3a
fix til pointer flags
rbran Jan 7, 2025
703d954
fix til dependencies
rbran Jan 7, 2025
0b5a123
Revert "fix til pointer flags"
rbran Jan 7, 2025
6d16ec9
fix til pointer flags
rbran Jan 7, 2025
a2dc300
fix til dependencies
rbran Jan 7, 2025
ef8453e
move type attribute read into ida_reader
rbran Jan 8, 2025
778d38d
add tilib enum type attribute verifications
rbran Jan 8, 2025
e904ae0
add tilib pointer type attribute ext verifications
rbran Jan 8, 2025
d8a144a
add context to error messages
rbran Jan 8, 2025
c58e053
add tilib array type attribute ext verifications
rbran Jan 8, 2025
0d8fa3a
fix read sdacl
rbran Jan 8, 2025
f65024f
add tilib udt type attribute ext verifications
rbran Jan 8, 2025
692281d
follow clippy sugestions
rbran Jan 8, 2025
1743e1c
add tilib function type attribute ext verifications
rbran Jan 8, 2025
b99ce5f
add a permissive feature
rbran Jan 9, 2025
ce74502
fix til enum ext att parsing
rbran Jan 9, 2025
7aae356
replace the permissive feature with the restrictive feature
rbran Jan 10, 2025
3220e34
fix id0 dirtree not hadling EoF correctly
rbran Jan 10, 2025
67bb5fd
fix til type alignment
rbran Jan 10, 2025
ba9cf31
improve til type size calculation
rbran Jan 10, 2025
ec1e84b
add tilib cppobj print
rbran Jan 10, 2025
8f8739a
change max line width to 80 chars
rbran Jan 11, 2025
5faae39
allow a struct to reverse-inherit the cppobj from baseclass
rbran Jan 11, 2025
16f6152
fix tilib pointer not inheriting the VFT att
rbran Jan 11, 2025
5af5117
add til typeref resolution to creation
rbran Jan 13, 2025
1c5d29a
add til typeref ref kind to all typerefs
rbran Jan 13, 2025
73832de
fix tilib print format issues
rbran Jan 14, 2025
c449322
add IDBString for better debug format
rbran Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 80
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ flate2 = "1.0.31"
serde = { version = "1.0", features = ["derive"] }
num_enum = "0.7.3"

[features]
default = []
restrictive = []

[[bin]]
name = "idb-tools"
path = "src/tools/tools.rs"
46 changes: 34 additions & 12 deletions src/id0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ pub struct IDBFileRegions {
}

impl IDBFileRegions {
fn read(_key: &[u8], data: &[u8], version: u16, is_64: bool) -> Result<Self> {
fn read(
_key: &[u8],
data: &[u8],
version: u16,
is_64: bool,
) -> Result<Self> {
let mut input = IdaUnpacker::new(data, is_64);
// TODO detect versions with more accuracy
let (start, end, eva) = match version {
Expand All @@ -38,9 +43,9 @@ impl IDBFileRegions {
}
700.. => {
let start = input.unpack_usize()?;
let end = start
.checked_add(input.unpack_usize()?)
.ok_or_else(|| anyhow!("Overflow address in File Regions"))?;
let end = start.checked_add(input.unpack_usize()?).ok_or_else(
|| anyhow!("Overflow address in File Regions"),
)?;
let rva = input.unpack_usize()?;
// TODO some may include an extra 0 byte at the end?
if let Ok(_unknown) = input.unpack_usize() {
Expand Down Expand Up @@ -73,9 +78,13 @@ impl<'a> FunctionsAndComments<'a> {
ensure!(parse_maybe_cstr(value) == Some(&b"$ funcs"[..]));
Ok(Self::Name)
}
b'S' => IDBFunction::read(sub_key, value, is_64).map(Self::Function),
b'S' => {
IDBFunction::read(sub_key, value, is_64).map(Self::Function)
}
// some kind of style setting, maybe setting font and background color
b'R' | b'C' if value.starts_with(&[4, 3, 2, 1]) => Ok(Self::Unknown { key, value }),
b'R' | b'C' if value.starts_with(&[4, 3, 2, 1]) => {
Ok(Self::Unknown { key, value })
}
b'C' => {
let address = parse_number(sub_key, true, is_64)
.ok_or_else(|| anyhow!("Invalid Comment address"))?;
Expand All @@ -87,8 +96,10 @@ impl<'a> FunctionsAndComments<'a> {
.ok_or_else(|| anyhow!("Invalid Comment string"))
}
b'R' => {
let address = parse_number(sub_key, true, is_64)
.ok_or_else(|| anyhow!("Invalid Repetable Comment address"))?;
let address =
parse_number(sub_key, true, is_64).ok_or_else(|| {
anyhow!("Invalid Repetable Comment address")
})?;
parse_maybe_cstr(value)
.map(|value| Self::Comment {
address,
Expand Down Expand Up @@ -145,7 +156,9 @@ impl IDBFunction {
})
}

fn read_extra_regular(mut input: impl IdaUnpack) -> Result<IDBFunctionExtra> {
fn read_extra_regular(
mut input: impl IdaUnpack,
) -> Result<IDBFunctionExtra> {
// TODO Undertand the sub operation at InnerRef 5c1b89aa-5277-4c98-98f6-cec08e1946ec 0x28f98f
let frame = input.unpack_usize_ext_max()?;
let _unknown4 = input.unpack_dw()?;
Expand All @@ -155,7 +168,10 @@ impl IDBFunction {
Ok(IDBFunctionExtra::NonTail { frame })
}

fn read_extra_tail(mut input: impl IdaUnpack, address_start: u64) -> Result<IDBFunctionExtra> {
fn read_extra_tail(
mut input: impl IdaUnpack,
address_start: u64,
) -> Result<IDBFunctionExtra> {
// offset of the function owner in relation to the function start
let owner_offset = input.unpack_usize()? as i64;
let owner = match address_start.checked_add_signed(owner_offset) {
Expand Down Expand Up @@ -240,12 +256,18 @@ pub struct EntryPoint {
pub entry_type: Option<til::Type>,
}

pub(crate) fn parse_number(data: &[u8], big_endian: bool, is_64: bool) -> Option<u64> {
pub(crate) fn parse_number(
data: &[u8],
big_endian: bool,
is_64: bool,
) -> Option<u64> {
Some(match (data.len(), is_64, big_endian) {
(8, true, true) => u64::from_be_bytes(data.try_into().unwrap()),
(8, true, false) => u64::from_le_bytes(data.try_into().unwrap()),
(4, false, true) => u32::from_be_bytes(data.try_into().unwrap()).into(),
(4, false, false) => u32::from_le_bytes(data.try_into().unwrap()).into(),
(4, false, false) => {
u32::from_le_bytes(data.try_into().unwrap()).into()
}
_ => return None,
})
}
Expand Down
22 changes: 16 additions & 6 deletions src/id0/address_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ impl<'a> Comments<'a> {
}
}

pub(crate) struct SectionAddressInfoIter<'a, I: Iterator<Item = Result<IDBFileRegions>>> {
pub(crate) struct SectionAddressInfoIter<
'a,
I: Iterator<Item = Result<IDBFileRegions>>,
> {
all_entries: &'a [ID0Entry],
regions: I,
current_region: AddressInfoIter<'a>,
}

impl<'a, I: Iterator<Item = Result<IDBFileRegions>>> SectionAddressInfoIter<'a, I> {
impl<'a, I: Iterator<Item = Result<IDBFileRegions>>>
SectionAddressInfoIter<'a, I>
{
pub fn new(all_entries: &'a [ID0Entry], regions: I, is_64: bool) -> Self {
Self {
all_entries,
Expand All @@ -64,8 +69,10 @@ impl<'a, I: Iterator<Item = Result<IDBFileRegions>> + 'a> Iterator
Some(Err(err)) => return Some(Err(err)),
};
let is_64 = self.current_region.is_64;
let start_key: Vec<u8> = crate::id0::key_from_address(region.start, is_64).collect();
let end_key: Vec<u8> = crate::id0::key_from_address(region.end, is_64).collect();
let start_key: Vec<u8> =
crate::id0::key_from_address(region.start, is_64).collect();
let end_key: Vec<u8> =
crate::id0::key_from_address(region.end, is_64).collect();
let start = self
.all_entries
.binary_search_by_key(&&start_key[..], |b| &b.key[..])
Expand Down Expand Up @@ -105,9 +112,12 @@ impl<'a> Iterator for AddressInfoIter<'a> {
// 1.. because it starts with '.'
let addr_len = if self.is_64 { 8 } else { 4 };
let key_start = addr_len + 1;
let address = super::parse_number(&current.key[1..key_start], true, self.is_64).unwrap();
let address =
super::parse_number(&current.key[1..key_start], true, self.is_64)
.unwrap();
let key = &current.key[key_start..];
let Some((sub_type, id_value)) = id_subkey_from_idx(key, self.is_64) else {
let Some((sub_type, id_value)) = id_subkey_from_idx(key, self.is_64)
else {
return Some(Err(anyhow!("Missing SubType")));
};

Expand Down
Loading
Loading