VariableValue

Enum VariableValue 

Source
pub enum VariableValue {
    Bytes(Vec<u8>),
    Other(Word),
    Numeric(Value),
}
Expand description

Represents a variable value in one of several forms

VariableValue encapsulates the various ways a variable’s value might be represented, such as raw bytes, numeric values, or machine words. This allows the debugger to work with variables of different types and sizes.

§Examples

use coreminer::variable::VariableValue;
use gimli::Value;

// Create a variable value from raw bytes
let bytes_value = VariableValue::Bytes(vec![0x01, 0x02, 0x03, 0x04]);

// Create a variable value from a machine word
let word_value = VariableValue::Other(0x123456789);

// Create a variable value from a DWARF numeric value
let numeric_value = VariableValue::Numeric(Value::U32(42));

// Convert a variable value to a u64
let value_as_u64 = bytes_value.to_u64();

Variants§

§

Bytes(Vec<u8>)

Raw byte representation of a value

§

Other(Word)

Machine word representation of a value

§

Numeric(Value)

DWARF numeric value

Implementations§

Source§

impl VariableValue

Source

pub fn byte_size(&self) -> usize

Returns the size of the variable value in bytes

§Returns

The size of the variable value in bytes

§Examples
use coreminer::variable::VariableValue;
use gimli::Value;

let bytes_value = VariableValue::Bytes(vec![0x01, 0x02, 0x03, 0x04]);
assert_eq!(bytes_value.byte_size(), 4);

let word_value = VariableValue::Other(0x123456789);
assert_eq!(word_value.byte_size(), 8); // Assuming 64-bit (8-byte) words

let numeric_value = VariableValue::Numeric(Value::U32(42));
assert_eq!(numeric_value.byte_size(), 4);
Source

pub fn to_u64(&self) -> u64

Converts the variable value to a u64

§Returns

The variable value as a u64

§Panics

This method will panic if self is a VariableValue::Bytes which has more bytes than a u64 can hold.

§Examples
use coreminer::variable::VariableValue;
use gimli::Value;

let bytes_value = VariableValue::Bytes(vec![0x42, 0x00, 0x00, 0x00]);
assert_eq!(bytes_value.to_u64(), 0x42);

let word_value = VariableValue::Other(0x123456789);
assert_eq!(word_value.to_u64(), 0x123456789);

let numeric_value = VariableValue::Numeric(Value::U32(42));
assert_eq!(numeric_value.to_u64(), 42);
Source

pub fn resize_to_bytes(&self, target_size: usize) -> Vec<u8>

Resizes a value to the specified number of bytes

§Parameters
  • target_size - The target size in bytes
§Returns

A vector of bytes with the specified size

§Panics

This method will panic if self is a VariableValue::Bytes which has more bytes than a u64 can hold.

§Examples
use coreminer::variable::VariableValue;
use gimli::Value;

let value = VariableValue::Other(0x123456789);

// Resize to 4 bytes
let bytes = value.resize_to_bytes(4);
assert_eq!(bytes, vec![0x89, 0x67, 0x45, 0x23]);

// Resize to 2 bytes
let bytes = value.resize_to_bytes(2);
assert_eq!(bytes, vec![0x89, 0x67]);

Trait Implementations§

Source§

impl Clone for VariableValue

Source§

fn clone(&self) -> VariableValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for VariableValue

Source§

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

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

impl From<Value> for VariableValue

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for VariableValue

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Serialize for VariableValue

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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