pub struct Location<'db> { /* private fields */ }Expand description
A borrowed view of one address’s item, keyed by that address.
A cheap Copy handle that borrows the Database and re-queries per accessor, from
Database::at. The address-keyed counterpart to the noun views (Function,
Segment); LocationMut is its write cursor.
Implementations§
Source§impl Location<'_>
impl Location<'_>
Sourcepub fn name(&self) -> Option<String>
pub fn name(&self) -> Option<String>
The name at this address, or None if it is unnamed.
Examples found in repository?
50fn name_and_comment(idb: &mut Database, ea: Address) -> Result<(), Error> {
51 println!("== at_mut: rename + comment + patch (one read-capable cursor) ==");
52
53 // `at` is the read view; `at_mut` the write cursor. Snapshot the name to put it back after.
54 let original_name = idb.at(ea).name();
55 println!(" {ea:#x} name before: {original_name:?}");
56
57 {
58 // Scope the cursor: its Drop coalesces invalidation, holding the borrow until then.
59 let mut loc = idb.at_mut(ea);
60 loc.rename("idakit_edit_demo")?;
61 loc.set_comment("renamed by the edits example", false)?;
62 loc.set_comment("shown at every xref", true)?;
63 // Read back through the SAME cursor: no drop-and-reborrow between the write and the read.
64 println!(" name after: {:?}", loc.name());
65 println!(" regular cmt: {:?}", loc.comment());
66 println!(" repeatable cmt: {:?}", loc.repeatable_comment());
67 }
68
69 // Patch a few bytes, confirm the read-back, then restore the originals.
70 let original_bytes = idb.at(ea).bytes(4);
71 let flipped: Vec<u8> = original_bytes.iter().map(|b| !b).collect();
72 {
73 let mut loc = idb.at_mut(ea);
74 loc.patch(&flipped)?;
75 println!(
76 " patched 4 bytes, read-back matches: {}",
77 loc.bytes(4) == flipped
78 );
79 loc.patch(&original_bytes)?;
80 }
81
82 if let Some(name) = original_name {
83 idb.at_mut(ea).rename(name)?;
84 }
85 Ok(())
86}Sourcepub fn comment(&self) -> Option<String>
pub fn comment(&self) -> Option<String>
The regular comment at this address, or None when that channel carries none.
Sourcepub fn repeatable_comment(&self) -> Option<String>
pub fn repeatable_comment(&self) -> Option<String>
The repeatable comment at this address, or None when that channel carries none.
Sourcepub fn bytes(&self, len: usize) -> Vec<u8> ⓘ
pub fn bytes(&self, len: usize) -> Vec<u8> ⓘ
Read up to len bytes at this address into a fresh vector (empty on failure).
Examples found in repository?
50fn name_and_comment(idb: &mut Database, ea: Address) -> Result<(), Error> {
51 println!("== at_mut: rename + comment + patch (one read-capable cursor) ==");
52
53 // `at` is the read view; `at_mut` the write cursor. Snapshot the name to put it back after.
54 let original_name = idb.at(ea).name();
55 println!(" {ea:#x} name before: {original_name:?}");
56
57 {
58 // Scope the cursor: its Drop coalesces invalidation, holding the borrow until then.
59 let mut loc = idb.at_mut(ea);
60 loc.rename("idakit_edit_demo")?;
61 loc.set_comment("renamed by the edits example", false)?;
62 loc.set_comment("shown at every xref", true)?;
63 // Read back through the SAME cursor: no drop-and-reborrow between the write and the read.
64 println!(" name after: {:?}", loc.name());
65 println!(" regular cmt: {:?}", loc.comment());
66 println!(" repeatable cmt: {:?}", loc.repeatable_comment());
67 }
68
69 // Patch a few bytes, confirm the read-back, then restore the originals.
70 let original_bytes = idb.at(ea).bytes(4);
71 let flipped: Vec<u8> = original_bytes.iter().map(|b| !b).collect();
72 {
73 let mut loc = idb.at_mut(ea);
74 loc.patch(&flipped)?;
75 println!(
76 " patched 4 bytes, read-back matches: {}",
77 loc.bytes(4) == flipped
78 );
79 loc.patch(&original_bytes)?;
80 }
81
82 if let Some(name) = original_name {
83 idb.at_mut(ea).rename(name)?;
84 }
85 Ok(())
86}Sourcepub fn read_into(&self, buf: &mut [u8]) -> usize
pub fn read_into(&self, buf: &mut [u8]) -> usize
Read bytes at this address into buf, returning how many were supplied.
Sourcepub fn is_data(&self) -> bool
pub fn is_data(&self) -> bool
Whether the kernel classifies the item here as a data definition.
Sourcepub fn string_literal(&self) -> Option<String>
pub fn string_literal(&self) -> Option<String>
The C string at this address, decoded as UTF-8, or None if it holds no string.
Sourcepub fn xrefs_from(&self) -> Xrefs ⓘ
pub fn xrefs_from(&self) -> Xrefs ⓘ
Lazily iterates cross-references originating at this address.