Struct VmiOsState

Source
pub struct VmiOsState<'a, Driver, Os>(/* private fields */)
where
    Driver: VmiDriver,
    Os: VmiOs<Driver>;
Expand description

Wrapper providing access to OS-specific operations.

Implementations§

Source§

impl<'a, Driver, Os> VmiOsState<'a, Driver, Os>
where Driver: VmiDriver, Os: VmiOs<Driver>,

Source

pub fn core(&self) -> &'a VmiCore<Driver>

Returns the VMI core.

Source

pub fn underlying_os(&self) -> &'a Os

Returns the underlying OS-specific implementation.

Source

pub fn session(&self) -> &VmiSession<'a, Driver, Os>

Returns the VMI session.

Source

pub fn state(&self) -> VmiState<'a, Driver, Os>

Returns the VMI state.

Source

pub fn registers(&self) -> &<Driver::Architecture as Architecture>::Registers

Returns the CPU registers associated with the current event.

Source

pub fn function_argument_for_registers( &self, registers: &<Driver::Architecture as Architecture>::Registers, index: u64, ) -> Result<u64, VmiError>

Retrieves a specific function argument according to the calling convention of the operating system.

Source

pub fn function_return_value_for_registers( &self, registers: &<Driver::Architecture as Architecture>::Registers, ) -> Result<u64, VmiError>

Retrieves the return value of a function.

Source§

impl<'__vmi, Driver, Os> VmiOsState<'__vmi, Driver, Os>
where Driver: VmiDriver, Os: VmiOs<Driver>,

Source

pub fn kernel_image_base(&self) -> Result<Va, VmiError>

Retrieves the base address of the kernel image.

The kernel image base address is usually found using some special CPU register - for example, a register that contains the address of the system call handler. Such register is set by the operating system during boot and is left unchanged (unless some rootkits are involved).

Therefore, this function can accept the CPU registers from any point of the VM execution (except for the early boot stage).

For catching the exact moment when the kernel image base address is set, you can monitor the MSR_LSTAR register (on AMD64) for writes.

§Architecture-specific
  • AMD64: The kernel image base address is usually found using the MSR_LSTAR register.
§Notes

A malicious code (such as a rootkit) could modify values of the registers, so the returned value might not be accurate.

Source

pub fn kernel_information_string(&self) -> Result<String, VmiError>

Retrieves an implementation-specific string containing kernel information.

§Platform-specific
  • Windows: Retrieves the NtBuildLab string from the kernel image.
  • Linux: Retrieves the linux_banner string from the kernel image.
Source

pub fn kpti_enabled(&self) -> Result<bool, VmiError>

Checks if Kernel Page Table Isolation (KPTI) is enabled.

§Platform-specific
  • Windows: Retrieves the KiKvaShadow global variable, if it exists.
Source

pub fn modules<'a>( &self, ) -> Result<impl Iterator<Item = Result<Os::Module<'a>, VmiError>> + 'a, VmiError>
where '__vmi: 'a,

Returns an iterator over the loaded kernel modules.

§Platform-specific
  • Windows: Retrieves information from the PsLoadedModuleList.
  • Linux: Retrieves information from the modules list.
Source

pub fn processes<'a>( &self, ) -> Result<impl Iterator<Item = Result<Os::Process<'a>, VmiError>> + 'a, VmiError>
where '__vmi: 'a,

Returns an iterator over the processes.

§Platform-specific
  • Windows: Retrieves information from the PsActiveProcessHead list.
  • Linux: Retrieves information from the tasks list.
Source

pub fn process<'a>( &self, process: ProcessObject, ) -> Result<Os::Process<'a>, VmiError>
where '__vmi: 'a,

Returns the process corresponding to the given process object.

Source

pub fn current_process<'a>(&self) -> Result<Os::Process<'a>, VmiError>
where '__vmi: 'a,

Returns the currently executing process.

Source

pub fn system_process<'a>(&self) -> Result<Os::Process<'a>, VmiError>
where '__vmi: 'a,

Returns the system process object.

The system process is the first process created by the kernel.

§Platform-specific
  • Windows: Retrieves the PsInitialSystemProcess global variable.
  • Linux: Retrieves the init_task global variable.
Source

pub fn thread<'a>( &self, thread: ThreadObject, ) -> Result<Os::Thread<'a>, VmiError>
where '__vmi: 'a,

Returns the thread corresponding to the given thread object.

Source

pub fn current_thread<'a>(&self) -> Result<Os::Thread<'a>, VmiError>
where '__vmi: 'a,

Returns the currently executing thread.

Source

pub fn image<'a>(&self, image_base: Va) -> Result<Os::Image<'a>, VmiError>
where '__vmi: 'a,

Returns the image corresponding to the given base address.

Source

pub fn module<'a>(&self, module: Va) -> Result<Os::Module<'a>, VmiError>
where '__vmi: 'a,

Returns the kernel module corresponding to the given base address.

Source

pub fn region<'a>(&self, region: Va) -> Result<Os::Region<'a>, VmiError>
where '__vmi: 'a,

Returns the memory region corresponding to the given address.

§Platform-specific
  • Windows: The region is represented by the _MMVAD structure.
  • Linux: The region is represented by the vm_area_struct structure.
Source

pub fn syscall_argument(&self, index: u64) -> Result<u64, VmiError>

Retrieves a specific syscall argument according to the system call ABI.

This function assumes that it is called in the prologue of the system call handler, i.e., the instruction pointer is pointing to the first instruction of the function.

Source

pub fn function_argument(&self, index: u64) -> Result<u64, VmiError>

Retrieves a specific function argument according to the calling convention of the operating system.

This function assumes that it is called in the function prologue, i.e., the instruction pointer is pointing to the first instruction of the function.

§Platform-specific
  • Windows: Assumes that the function is using the stdcall calling convention.
Source

pub fn function_return_value(&self) -> Result<u64, VmiError>

Retrieves the return value of a function.

This function assumes that it is called immediately after the function returns.

Source

pub fn last_error(&self) -> Result<Option<u32>, VmiError>

Retrieves the last error value.

§Platform-specific

Auto Trait Implementations§

§

impl<'a, Driver, Os> Freeze for VmiOsState<'a, Driver, Os>

§

impl<'a, Driver, Os> !RefUnwindSafe for VmiOsState<'a, Driver, Os>

§

impl<'a, Driver, Os> !Send for VmiOsState<'a, Driver, Os>

§

impl<'a, Driver, Os> !Sync for VmiOsState<'a, Driver, Os>

§

impl<'a, Driver, Os> Unpin for VmiOsState<'a, Driver, Os>

§

impl<'a, Driver, Os> !UnwindSafe for VmiOsState<'a, Driver, Os>

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