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
impl VariableValue
Sourcepub fn byte_size(&self) -> usize
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);
Sourcepub fn to_u64(&self) -> u64
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);
Sourcepub fn resize_to_bytes(&self, target_size: usize) -> Vec<u8> ⓘ
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
impl Clone for VariableValue
Source§fn clone(&self) -> VariableValue
fn clone(&self) -> VariableValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for VariableValue
impl Debug for VariableValue
Source§impl From<Value> for VariableValue
impl From<Value> for VariableValue
Source§impl From<usize> for VariableValue
impl From<usize> for VariableValue
Auto Trait Implementations§
impl Freeze for VariableValue
impl RefUnwindSafe for VariableValue
impl Send for VariableValue
impl Sync for VariableValue
impl Unpin for VariableValue
impl UnwindSafe for VariableValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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