loadpe-rs/src/errors.rs

31 lines
1016 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use std::alloc::LayoutError;
use thiserror::Error;
use object::Error as ObjectError;
use windows::core::Error as WindowsError;
#[derive(Error, Debug)]
pub enum LoadPEError {
#[error("文件不存在: {0}")]
FileNotFound(String),
#[error("文件读取失败: {0}")]
FileReadError(#[from] std::io::Error),
#[error("文件解析失败: {0}")]
ParseError(#[from] ObjectError),
#[error("内存分配失败")]
MemoryAllocFailed,
#[error("可执行程序没有包含导入表!")]
ExecutableWithoutImportTable,
#[error("读取一个C风格字符串错误, {0}")]
ReadCStringError(#[from] std::str::Utf8Error),
#[error("LoadLibraryA错误, {0}")]
LoadLibraryError(#[from] WindowsError),
#[error("GetProcAddress错误, {0}")]
GetProcAddressError(String),
#[error("没有重定位表!")]
NoRelocationTable,
#[error(transparent)]
LayoutError(#[from] LayoutError),
#[error("更改内存属性失败!")]
ChangeMemoryProtectFailed,
}