Skip to main content

VmiOsState

Struct VmiOsState 

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

Wrapper providing access to OS-specific operations.

Implementations§

Source§

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

Source

pub fn core(&self) -> &'a VmiCore<Os::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, Os>

Returns the VMI session.

Source

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

Returns the VMI state.

Source

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

Returns the CPU registers associated with the current event.

Source

pub fn function_argument_for_registers( &self, registers: &<Os::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: &<Os::Architecture as Architecture>::Registers, ) -> Result<u64, VmiError>

Retrieves the return value of a function.

Source§

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

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>> + use<'a, Os>, 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>> + use<'a, Os>, 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 user_module<'a>( &self, module: Va, root: Pa, ) -> Result<Os::UserModule<'a>, VmiError>
where '__vmi: 'a,

Returns the user-mode 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, Os> Freeze for VmiOsState<'a, Os>

§

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

§

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

§

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

§

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

§

impl<'a, Os> UnsafeUnpin for VmiOsState<'a, Os>

§

impl<'a, Os> !UnwindSafe for VmiOsState<'a, 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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