Enum Error

pub enum Error {
Show 18 variants InvalidOffset, Malformed { message: String, file: &'static str, line: u32, }, OutOfBounds, NotSupported, Empty, FileError(Error), Error(String), GoblinErr(Error), TypeInsert(Token), TypeNotFound(Token), TypeError(String), TypeMissingParent, TypeNotPrimitive, TypeNotConst(u8), TypeConversionInvalid, RecursionLimit(usize), LockError, GraphError(String),
}
Expand description

dotscope Error type.

The main error type for all operations in this crate. Provides detailed error information for file parsing, metadata validation, and disassembly operations.

§Usage Examples

use dotscope::{Error, CilObject};

match CilObject::from_file(std::path::Path::new("tests/samples/crafted_2.exe")) {
    Ok(assembly) => println!("Loaded successfully"),
    Err(Error::NotSupported) => println!("File format not supported"),
    Err(Error::Malformed { message, .. }) => println!("Malformed: {}", message),
    Err(e) => println!("Error: {}", e),
}

The generic Error type, which provides coverage for all errors this library can potentially return.

This enum covers all possible error conditions that can occur during .NET assembly parsing, metadata analysis, and disassembly operations. Each variant provides specific context about the failure mode to enable appropriate error handling.

§Error Categories

§File Parsing Errors

§I/O and External Errors

§Type System Errors

§Analysis Errors

Variants§

§

InvalidOffset

Encountered an invalid offset while parsing file structures.

This error occurs when the parser encounters an offset that is invalid for the current file context, such as negative offsets or offsets that would point outside the valid file structure.

§

Malformed

The file is damaged and could not be parsed.

This error indicates that the file structure is corrupted or doesn’t conform to the expected .NET PE format. The error includes the source location where the malformation was detected for debugging purposes.

§Fields

  • message - Detailed description of what was malformed
  • file - Source file where the error was detected
  • line - Source line where the error was detected

Fields

§message: String

The message to be printed for the Malformed error

§file: &'static str

The source file in which this error occured

§line: u32

The source line in which this error occured

§

OutOfBounds

An out of bound access was attempted while parsing the file.

This error occurs when trying to read data beyond the end of the file or stream. It’s a safety check to prevent buffer overruns during parsing.

§

NotSupported

This file type is not supported.

Indicates that the input file is not a supported .NET PE executable, or uses features that are not yet implemented in this library.

§

Empty

Provided input was empty.

This error occurs when an empty file or buffer is provided where actual .NET assembly data was expected.

§

FileError(Error)

File I/O error.

Wraps standard I/O errors that can occur during file operations such as reading from disk, permission issues, or filesystem errors.

§

Error(String)

Generic error for miscellaneous failures.

Used for errors that don’t fit into other categories or for wrapping external library errors with additional context.

§

GoblinErr(Error)

Error from the goblin crate during PE/ELF parsing.

The goblin crate is used for low-level PE format parsing. This error wraps any failures from that parsing layer.

§

TypeInsert(Token)

Failed to insert new type into TypeSystem.

This error occurs when attempting to register a new type in the type system fails, typically due to conflicting metadata tokens or invalid type definitions.

The associated crate::metadata::token::Token identifies which type caused the failure.

§

TypeNotFound(Token)

Failed to find type in TypeSystem.

This error occurs when looking up a type by token that doesn’t exist in the loaded metadata or type system registry.

The associated crate::metadata::token::Token identifies which type was not found.

§

TypeError(String)

General error during TypeSystem usage.

Covers various type system operations that can fail, such as type resolution, inheritance chain analysis, or generic instantiation.

§

TypeMissingParent

The parent of the current type is missing.

This error occurs when analyzing type inheritance and the parent type referenced by a type definition cannot be found or resolved.

§

TypeNotPrimitive

This type can not be converted to a primitive.

Occurs when attempting to convert a complex type to a primitive type representation, but the type is not compatible with primitive type semantics.

§

TypeNotConst(u8)

This type can not be converted to a ConstType.

Indicates that a type cannot be represented as a compile-time constant value. The associated value indicates the type code that failed conversion.

§

TypeConversionInvalid

The requested type conversion is not possible.

This error occurs when attempting type conversions that are semantically invalid in the .NET type system.

§

RecursionLimit(usize)

Recursion limit reached.

To prevent stack overflow during recursive operations like type resolution or dependency analysis, a maximum recursion depth is enforced. This error indicates that limit was exceeded.

The associated value shows the recursion limit that was reached.

§

LockError

Failed to lock target.

This error occurs when thread synchronization fails, typically when trying to acquire a mutex or rwlock that is in an invalid state.

§

GraphError(String)

LoaderGraph error.

Errors related to dependency graph analysis and metadata loading order resolution. This can occur when circular dependencies are detected or when the dependency graph cannot be properly constructed.

Trait Implementations§

§

impl Debug for Error

§

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

Formats the value using the given formatter. Read more
§

impl Display for Error

§

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

Formats the value using the given formatter. Read more
§

impl Error for Error

§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
§

impl From<Error> for Error

§

fn from(source: Error) -> Self

Converts to this type from the input type.
§

impl From<Error> for Error

§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

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, 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.