Skip to main content

Address

Struct Address 

Source
pub struct Address(/* private fields */);
Expand description

A validated address, any real value other than the invalid sentinel.

The invalid-address sentinel maps to None, and a niche keeps Option<Address> the same size as a bare u64.

Ordering is by the real address: the niche stores !raw, so a derived Ord would compare inverted bits and reverse the order. Callers expect an Address to sort like the raw address it wraps (linear walks, chunk bounds, BTreeMap keys), so Ord/PartialOrd are hand-written over get.

Implementations§

Source§

impl Address

Source

pub const fn try_new(raw: u64) -> Option<Self>

Wrap a raw address. None only when raw == BADADDR.

Source

pub const fn new_const(raw: u64) -> Self

Const constructor for literals.

§Panics

At compile time, if raw == BADADDR.

Examples found in repository?
examples/edits.rs (line 109)
91fn function_types(idb: &mut Database, ea: Address) -> Result<(), Error> {
92    println!("\n== function_mut: prototypes ==");
93    println!("  prototype before: {:?}", idb.function(ea).prototype());
94
95    // Acquire by key (a two-phase borrow keeps it a one-liner). `function_mut` is an `Option`: an
96    // address in no function yields `None`, never a cursor over nothing.
97    if let Some(mut f) = idb.function_mut(ea) {
98        f.set_type("int edits_probe(int a, int b)")?;
99    }
100    println!("  prototype after:  {:?}", idb.function(ea).prototype());
101
102    // The scoped-closure form returns `Option<Result<_>>` (None = no function, then the write's own
103    // Result). `.transpose()?` collapses both layers at once, the idiom for that shape.
104    idb.with_function_mut(ea, |f| f.set_type("void edits_probe(void)"))
105        .transpose()?;
106    println!("  prototype now:    {:?}", idb.function(ea).prototype());
107
108    // An address inside no function: the cursor is simply absent.
109    let nowhere = Address::new_const(0xffff_ffff_f000);
110    println!(
111        "  function_mut(unmapped) is_some: {}",
112        idb.function_mut(nowhere).is_some()
113    );
114
115    // For the entry address, `function_mut(ea).set_type` and `at_mut(ea).set_type` are the same
116    // apply today; `FunctionEdit` earns its own weight when signature surgery (return/arg edits)
117    // arrives.
118
119    // `clear_type` is the inverse of `set_type`; it removes the prototype and is idempotent.
120    idb.at_mut(ea).clear_type()?;
121    println!(
122        "  prototype after clear: {:?}",
123        idb.function(ea).prototype()
124    );
125    Ok(())
126}
Source

pub const fn get(self) -> u64

The raw address.

Examples found in repository?
examples/probe_names.rs (line 53)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let mut args = std::env::args().skip(1);
10    let bin = args
11        .next()
12        .expect("usage: probe_names <db.i64> [max-names]");
13    let max: usize = args.next().and_then(|s| s.parse().ok()).unwrap_or(50_000);
14
15    Ida::run(move |ida| -> Result<(), Error> {
16        ida.call(move |idb| -> Result<(), Error> {
17            idb.open(&bin).call()?;
18
19            let (mut total, mut weak, mut public, mut mangled) = (0usize, 0usize, 0usize, 0usize);
20            let mut demangles = 0usize;
21            let mut substitutes = 0usize;
22            let mut short_differs = 0usize;
23            let mut short_vs_long = 0usize;
24            let mut samples: Vec<String> = Vec::new();
25            let mut first_weak: Option<usize> = None;
26            let mut first_public: Option<usize> = None;
27
28            for Name { address, name } in idb.names().take(max) {
29                total += 1;
30                let is_weak = idb.is_weak_name(address);
31                weak += usize::from(is_weak);
32                if is_weak && first_weak.is_none() {
33                    first_weak = Some(total - 1);
34                }
35                if idb.is_public_name(address) && first_public.is_none() {
36                    first_public = Some(total - 1);
37                }
38                public += usize::from(idb.is_public_name(address));
39                if name.starts_with("_Z") {
40                    mangled += 1;
41                }
42                if idb.demangle(&name).is_some() {
43                    demangles += 1;
44                }
45
46                let raw = idb.name_with(address, NameFlags::empty());
47                let visible = idb.visible_name(address);
48                if raw != visible {
49                    substitutes += 1;
50                    if samples.len() < 4 {
51                        samples.push(format!(
52                            "  subst {:#x}\n    raw     {raw:?}\n    visible {visible:?}",
53                            address.get()
54                        ));
55                    }
56                }
57
58                // The mutant that survives collapses `short_name` to plain VISIBLE, so this is
59                // the exact comparison that has to differ somewhere for a test to catch it.
60                let short = idb.short_name(address);
61                if short != visible {
62                    short_differs += 1;
63                }
64                if short != idb.long_name(address) {
65                    short_vs_long += 1;
66                }
67
68                if is_weak && name.starts_with("_Z") && samples.len() < 8 {
69                    samples.push(format!(
70                        "  weak+mangled {:#x}\n    raw   {name:?}\n    short {short:?}",
71                        address.get()
72                    ));
73                }
74            }
75
76            println!("=== {total} names scanned");
77            println!("weak            {weak}  (first at index {first_weak:?})");
78            println!("public          {public}  (first at index {first_public:?})");
79            println!("raw '_Z' prefix {mangled}");
80            println!("demangle(name)  {demangles}");
81            println!("raw != visible  {substitutes}");
82            println!("short != visible {short_differs}   <- kills the short_name mutant");
83            println!("short != long    {short_vs_long}");
84            println!("=== samples");
85            for s in &samples {
86                println!("{s}");
87            }
88
89            idb.close(false);
90            Ok(())
91        })??;
92        Ok(())
93    })??;
94
95    println!("PROBE_NAMES OK");
96    Ok(())
97}
Source§

impl Address

Source

pub const fn distance_to(self, end: Self) -> u64

The non-negative byte span end - self, saturating to 0 when end is below self.

The natural length of a [self, end) range, so a caller reads start.distance_to(end) rather than an unsigned-cast subtraction.

Trait Implementations§

Source§

impl Add<u64> for Address

Source§

fn add(self, bytes: u64) -> Self

Advance by a byte count, saturating into [0, BADADDR) so the result is always a valid Address, never the sentinel.

Source§

type Output = Address

The resulting type after applying the + operator.
Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Address

Source§

impl Debug for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Address

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Address

Source§

impl From<Address> for u64

Source§

fn from(address: Address) -> Self

Converts to this type from the input type.
Source§

impl Hash for Address

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Address

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Address

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Address

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Address

Source§

impl UpperHex for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more