Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
emesare committed Aug 29, 2024
1 parent b5f06a7 commit a38858b
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ mod test {
let current = input.seek(SeekFrom::Current(0))?;
let end = input.seek(SeekFrom::End(0))?;
ensure!(
current == end,
"unable to consume the entire TIL file, {current} != {end}"
);
current == end,
"unable to consume the entire TIL file, {current} != {end}"
);
Ok(())
}
Err(e) => Err(e),
Expand Down Expand Up @@ -532,4 +532,4 @@ mod test {
inner_find_all(path, exts, &mut result)?;
Ok(result)
}
}
}
22 changes: 12 additions & 10 deletions src/til.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod array;
pub mod bitfield;
pub mod r#enum;
/// The u8 values used to describes the type information records in IDA.
///
/// The recommended way of using type info is to use the [tinfo_t] class.
Expand All @@ -9,14 +12,11 @@
/// NOTE: to work with the types of instructions or data in the database,
/// use `get_tinfo()`/`set_tinfo()` and similar functions.
pub mod flag;
pub mod section;
pub mod function;
pub mod array;
pub mod pointer;
pub mod section;
pub mod r#struct;
pub mod union;
pub mod r#enum;
pub mod pointer;
pub mod bitfield;

use std::io::{BufRead, Read};
use std::num::NonZeroU8;
Expand Down Expand Up @@ -304,11 +304,13 @@ impl Basic {
BTMT_SIGNED => Some(true),
BTMT_UNSIGNED => Some(false),
// special case for char
BTMT_CHAR => return match bt_int {
BT_INT8 => Ok(Self::Char),
BT_INT => Ok(Self::SegReg),
_ => Err(anyhow!("Reserved use of tf_int::BTMT_CHAR {:x}", btmt)),
},
BTMT_CHAR => {
return match bt_int {
BT_INT8 => Ok(Self::Char),
BT_INT => Ok(Self::SegReg),
_ => Err(anyhow!("Reserved use of tf_int::BTMT_CHAR {:x}", btmt)),
}
}
_ => unreachable!(),
};
let bytes = match bt_int {
Expand Down
14 changes: 11 additions & 3 deletions src/til/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ pub struct Array {
pub elem_type: Box<Type>,
}
impl Array {
pub(crate) fn new(til: &TILSectionHeader, value: ArrayRaw, fields: Option<Vec<String>>) -> anyhow::Result<Self> {
pub(crate) fn new(
til: &TILSectionHeader,
value: ArrayRaw,
fields: Option<Vec<String>>,
) -> anyhow::Result<Self> {
if matches!(&fields, Some(f) if !f.is_empty()) {
return Err(anyhow!("fields in a Array"));
}
Expand All @@ -33,7 +37,11 @@ pub(crate) struct ArrayRaw {
}

impl ArrayRaw {
pub(crate) fn read<I: BufRead>(input: &mut I, header: &TILSectionHeader, metadata: u8) -> anyhow::Result<Self> {
pub(crate) fn read<I: BufRead>(
input: &mut I,
header: &TILSectionHeader,
metadata: u8,
) -> anyhow::Result<Self> {
use crate::til::flag::tf_array::*;
let (base, nelem) = match metadata {
BTMT_NONBASED => {
Expand All @@ -56,4 +64,4 @@ impl ArrayRaw {
elem_type: Box::new(elem_type),
})
}
}
}
2 changes: 1 addition & 1 deletion src/til/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ impl Bitfield {
nbytes,
})
}
}
}
16 changes: 13 additions & 3 deletions src/til/enum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::til::section::TILSectionHeader;
use crate::til::{associate_field_name_and_member, flag, read_de, read_dt, read_dt_de, Type, TypeAttribute, TypeRaw, SDACL, TAH};
use crate::til::{
associate_field_name_and_member, flag, read_de, read_dt, read_dt_de, Type, TypeAttribute,
TypeRaw, SDACL, TAH,
};
use anyhow::{anyhow, Context};
use std::io::BufRead;

Expand All @@ -18,7 +21,11 @@ pub enum Enum {
},
}
impl Enum {
pub(crate) fn new(til: &TILSectionHeader, value: EnumRaw, fields: Option<Vec<String>>) -> anyhow::Result<Self> {
pub(crate) fn new(
til: &TILSectionHeader,
value: EnumRaw,
fields: Option<Vec<String>>,
) -> anyhow::Result<Self> {
match value {
EnumRaw::Ref {
ref_type,
Expand Down Expand Up @@ -70,7 +77,10 @@ pub(crate) enum EnumRaw {
}

impl EnumRaw {
pub(crate) fn read<I: BufRead>(input: &mut I, header: &TILSectionHeader) -> anyhow::Result<Self> {
pub(crate) fn read<I: BufRead>(
input: &mut I,
header: &TILSectionHeader,
) -> anyhow::Result<Self> {
let Some(n) = read_dt_de(&mut *input)? else {
// is ref
let ref_type = TypeRaw::read_ref(&mut *input, header)?;
Expand Down
12 changes: 9 additions & 3 deletions src/til/function.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::til::section::TILSectionHeader;
use crate::til::{associate_field_name_and_member, read_de, read_dt, Basic, Type, TypeMetadata, TypeRaw, TAH};
use crate::til::{
associate_field_name_and_member, read_de, read_dt, Basic, Type, TypeMetadata, TypeRaw, TAH,
};
use anyhow::{ensure, Context};
use std::io::BufRead;

Expand Down Expand Up @@ -70,7 +72,11 @@ pub struct ArgLocDist {
}

impl FunctionRaw {
pub(crate) fn read<I: BufRead>(input: &mut I, header: &TILSectionHeader, metadata: u8) -> anyhow::Result<Self> {
pub(crate) fn read<I: BufRead>(
input: &mut I,
header: &TILSectionHeader,
metadata: u8,
) -> anyhow::Result<Self> {
// TODO what is that?
let mut flags = metadata << 2;

Expand Down Expand Up @@ -216,4 +222,4 @@ impl ArgLoc {
}
}
}
}
}
14 changes: 11 additions & 3 deletions src/til/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ pub struct Pointer {
}

impl Pointer {
pub(crate) fn new(til: &TILSectionHeader, raw: PointerRaw, fields: Option<Vec<String>>) -> anyhow::Result<Self> {
pub(crate) fn new(
til: &TILSectionHeader,
raw: PointerRaw,
fields: Option<Vec<String>>,
) -> anyhow::Result<Self> {
Ok(Self {
closure: raw.closure.map(|x| Closure::new(til, x)).transpose()?,
tah: raw.tah,
Expand Down Expand Up @@ -42,7 +46,11 @@ pub(crate) struct PointerRaw {
}

impl PointerRaw {
pub(crate) fn read<I: BufRead>(input: &mut I, header: &TILSectionHeader, metadata: u8) -> anyhow::Result<Self> {
pub(crate) fn read<I: BufRead>(
input: &mut I,
header: &TILSectionHeader,
metadata: u8,
) -> anyhow::Result<Self> {
use crate::til::flag::tf_ptr::*;
let closure = match metadata {
BTMT_DEFPTR => None,
Expand Down Expand Up @@ -79,4 +87,4 @@ impl ClosureRaw {
Ok(Self::PointerBased(closure_ptr))
}
}
}
}
12 changes: 9 additions & 3 deletions src/til/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ impl TILSection {
Self::read_inner(&mut input)
}

pub(crate) fn read<I: BufRead>(input: &mut I, compress: IDBSectionCompression) -> anyhow::Result<Self> {
pub(crate) fn read<I: BufRead>(
input: &mut I,
compress: IDBSectionCompression,
) -> anyhow::Result<Self> {
match compress {
IDBSectionCompression::None => Self::read_inner(input),
IDBSectionCompression::Zlib => {
Expand Down Expand Up @@ -380,7 +383,10 @@ impl TILSection {
Ok(type_info)
}

fn read_macros<I: BufRead>(input: &mut I, header: &TILSectionHeader) -> anyhow::Result<Vec<TILMacro>> {
fn read_macros<I: BufRead>(
input: &mut I,
header: &TILSectionHeader,
) -> anyhow::Result<Vec<TILMacro>> {
if header.flags.is_zip() {
Self::read_macros_zip(&mut *input)
} else {
Expand Down Expand Up @@ -445,4 +451,4 @@ impl TILSection {
);
Ok(())
}
}
}
14 changes: 11 additions & 3 deletions src/til/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub enum Struct {
},
}
impl Struct {
pub(crate) fn new(til: &TILSectionHeader, value: StructRaw, fields: Option<Vec<String>>) -> anyhow::Result<Self> {
pub(crate) fn new(
til: &TILSectionHeader,
value: StructRaw,
fields: Option<Vec<String>>,
) -> anyhow::Result<Self> {
match value {
StructRaw::Ref {
ref_type,
Expand Down Expand Up @@ -97,7 +101,11 @@ pub struct StructMember {
}

impl StructMember {
fn new(til: &TILSectionHeader, name: Option<String>, m: StructMemberRaw) -> anyhow::Result<Self> {
fn new(
til: &TILSectionHeader,
name: Option<String>,
m: StructMemberRaw,
) -> anyhow::Result<Self> {
Ok(Self {
name,
member_type: Type::new(til, m.0, None)?,
Expand All @@ -114,4 +122,4 @@ impl StructMemberRaw {
let sdacl = SDACL::read(&mut *input)?;
Ok(Self(member_type, sdacl))
}
}
}
8 changes: 6 additions & 2 deletions src/til/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub enum Union {
},
}
impl Union {
pub(crate) fn new(til: &TILSectionHeader, value: UnionRaw, fields: Option<Vec<String>>) -> anyhow::Result<Self> {
pub(crate) fn new(
til: &TILSectionHeader,
value: UnionRaw,
fields: Option<Vec<String>>,
) -> anyhow::Result<Self> {
match value {
UnionRaw::Ref {
ref_type,
Expand Down Expand Up @@ -88,4 +92,4 @@ impl UnionRaw {
members,
})
}
}
}

0 comments on commit a38858b

Please sign in to comment.