kdmp_parser/
error.rs

1// Axel '0vercl0k' Souchet - March 19 2024
2//! This is the error type used across the codebase.
3use std::fmt::Display;
4use std::{io, string};
5
6use thiserror::Error;
7
8use crate::structs::{DUMP_HEADER64_EXPECTED_SIGNATURE, DUMP_HEADER64_EXPECTED_VALID_DUMP};
9use crate::{Gpa, Gva};
10pub type Result<R> = std::result::Result<R, KdmpParserError>;
11
12#[derive(Debug)]
13pub enum PxeNotPresent {
14    Pml4e,
15    Pdpte,
16    Pde,
17    Pte,
18}
19
20#[derive(Debug, Error)]
21pub enum AddrTranslationError {
22    Virt(Gva, PxeNotPresent),
23    Phys(Gpa),
24}
25
26impl Display for AddrTranslationError {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            AddrTranslationError::Virt(gva, not_pres) => f.write_fmt(format_args!(
30                "virt to phys translation of {gva}: {not_pres:?}"
31            )),
32            AddrTranslationError::Phys(gpa) => {
33                f.write_fmt(format_args!("phys to offset translation of {gpa}"))
34            }
35        }
36    }
37}
38
39#[derive(Error, Debug)]
40pub enum KdmpParserError {
41    #[error("invalid UNICODE_STRING")]
42    InvalidUnicodeString,
43    #[error("utf16: {0}")]
44    Utf16(#[from] string::FromUtf16Error),
45    #[error("overflow: {0}")]
46    Overflow(&'static str),
47    #[error("io: {0}")]
48    Io(#[from] io::Error),
49    #[error("invalid data: {0}")]
50    InvalidData(&'static str),
51    #[error("unsupported dump type {0:#x}")]
52    UnknownDumpType(u32),
53    #[error("duplicate gpa found in physmem map for {0}")]
54    DuplicateGpa(Gpa),
55    #[error("header's signature looks wrong: {0:#x} vs {DUMP_HEADER64_EXPECTED_SIGNATURE:#x}")]
56    InvalidSignature(u32),
57    #[error("header's valid dump looks wrong: {0:#x} vs {DUMP_HEADER64_EXPECTED_VALID_DUMP:#x}")]
58    InvalidValidDump(u32),
59    #[error("overflow for phys addr w/ run {0} page {1}")]
60    PhysAddrOverflow(u32, u64),
61    #[error("overflow for page offset w/ run {0} page {1}")]
62    PageOffsetOverflow(u32, u64),
63    #[error("overflow for page offset w/ bitmap_idx {0} bit_idx {1}")]
64    BitmapPageOffsetOverflow(u64, usize),
65    #[error("partial physical memory read")]
66    PartialPhysRead,
67    #[error("partial virtual memory read")]
68    PartialVirtRead,
69    #[error("memory translation: {0}")]
70    AddrTranslation(#[from] AddrTranslationError),
71}