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
impl Address
Sourcepub const fn try_new(raw: u64) -> Option<Self>
pub const fn try_new(raw: u64) -> Option<Self>
Wrap a raw address. None only when raw == BADADDR.
Sourcepub const fn new_const(raw: u64) -> Self
pub const fn new_const(raw: u64) -> Self
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}Sourcepub const fn get(self) -> u64
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}Trait Implementations§
impl Copy for Address
Source§impl<'de> Deserialize<'de> for Address
impl<'de> Deserialize<'de> for Address
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Address
Source§impl Ord for Address
impl Ord for Address
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Address
impl PartialOrd for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnsafeUnpin for Address
impl UnwindSafe for Address
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more