kdmp_parser/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Axel '0vercl0k' Souchet - March 19 2024
//! This is the error type used across the codebase.
use std::fmt::Display;
use std::{io, string};

use thiserror::Error;

use crate::structs::{DUMP_HEADER64_EXPECTED_SIGNATURE, DUMP_HEADER64_EXPECTED_VALID_DUMP};
use crate::{Gpa, Gva};
pub type Result<R> = std::result::Result<R, KdmpParserError>;

#[derive(Debug)]
pub enum PxeNotPresent {
    Pml4e,
    Pdpte,
    Pde,
    Pte,
}

#[derive(Debug, Error)]
pub enum AddrTranslationError {
    Virt(Gva, PxeNotPresent),
    Phys(Gpa),
}

impl Display for AddrTranslationError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            AddrTranslationError::Virt(gva, not_pres) => f.write_fmt(format_args!(
                "virt to phys translation of {gva}: {not_pres:?}"
            )),
            AddrTranslationError::Phys(gpa) => {
                f.write_fmt(format_args!("phys to offset translation of {gpa}"))
            }
        }
    }
}

#[derive(Error, Debug)]
pub enum KdmpParserError {
    #[error("invalid UNICODE_STRING")]
    InvalidUnicodeString,
    #[error("utf16: {0}")]
    Utf16(#[from] string::FromUtf16Error),
    #[error("overflow: {0}")]
    Overflow(&'static str),
    #[error("io: {0}")]
    Io(#[from] io::Error),
    #[error("invalid data: {0}")]
    InvalidData(&'static str),
    #[error("unsupported dump type {0:#x}")]
    UnknownDumpType(u32),
    #[error("duplicate gpa found in physmem map for {0}")]
    DuplicateGpa(Gpa),
    #[error("header's signature looks wrong: {0:#x} vs {DUMP_HEADER64_EXPECTED_SIGNATURE:#x}")]
    InvalidSignature(u32),
    #[error("header's valid dump looks wrong: {0:#x} vs {DUMP_HEADER64_EXPECTED_VALID_DUMP:#x}")]
    InvalidValidDump(u32),
    #[error("overflow for phys addr w/ run {0} page {1}")]
    PhysAddrOverflow(u32, u64),
    #[error("overflow for page offset w/ run {0} page {1}")]
    PageOffsetOverflow(u32, u64),
    #[error("overflow for page offset w/ bitmap_idx {0} bit_idx {1}")]
    BitmapPageOffsetOverflow(u64, usize),
    #[error("partial physical memory read")]
    PartialPhysRead,
    #[error("partial virtual memory read")]
    PartialVirtRead,
    #[error("memory translation: {0}")]
    AddrTranslation(#[from] AddrTranslationError),
}