Skip to main content

Location

Struct Location 

Source
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<'_>

Source

pub const fn address(&self) -> Address

The address this handle is keyed by.

Source

pub fn name(&self) -> Option<String>

The name at this address, or None if it is unnamed.

Examples found in repository?
examples/edits.rs (line 54)
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}
Source

pub fn comment(&self) -> Option<String>

The regular comment at this address, or None when that channel carries none.

Source

pub fn repeatable_comment(&self) -> Option<String>

The repeatable comment at this address, or None when that channel carries none.

Source

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?
examples/edits.rs (line 70)
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}
Source

pub fn read_into(&self, buf: &mut [u8]) -> usize

Read bytes at this address into buf, returning how many were supplied.

Source

pub fn is_code(&self) -> bool

Whether the kernel classifies the item here as an instruction.

Source

pub fn is_data(&self) -> bool

Whether the kernel classifies the item here as a data definition.

Source

pub fn string_literal(&self) -> Option<String>

The C string at this address, decoded as UTF-8, or None if it holds no string.

Source

pub fn xrefs_to(&self) -> Xrefs

Lazily iterates cross-references targeting this address.

Source

pub fn xrefs_from(&self) -> Xrefs

Lazily iterates cross-references originating at this address.

Trait Implementations§

Source§

impl<'db> Clone for Location<'db>

Source§

fn clone(&self) -> Location<'db>

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<'db> Copy for Location<'db>

Source§

impl Debug for Location<'_>

Source§

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

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

impl Eq for Location<'_>

Source§

impl Hash for Location<'_>

Source§

fn hash<H: Hasher>(&self, s: &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 PartialEq for Location<'_>

Source§

fn eq(&self, o: &Self) -> bool

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

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'db> !RefUnwindSafe for Location<'db>

§

impl<'db> !Send for Location<'db>

§

impl<'db> !Sync for Location<'db>

§

impl<'db> !UnwindSafe for Location<'db>

§

impl<'db> Freeze for Location<'db>

§

impl<'db> Unpin for Location<'db>

§

impl<'db> UnsafeUnpin for Location<'db>

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> 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, 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