Commit bce95d65 authored by Gabriele Svelto's avatar Gabriele Svelto
Browse files

Bug 1872920 - Introduce the process_reader crate a=diannaS

parent fde823c7
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -4184,6 +4184,17 @@ dependencies = [
 "unicode-ident",
]

[[package]]
name = "process_reader"
version = "0.1.0"
dependencies = [
 "goblin",
 "memoffset",
 "mozilla-central-workspace-hack",
 "thiserror",
 "winapi",
]

[[package]]
name = "processtools"
version = "0.1.0"
+18 −0
Original line number Diff line number Diff line
[package]
name = "process_reader"
version = "0.1.0"
authors = ["Gabriele Svelto"]
edition = "2018"
license = "MPL-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
goblin = { version = "0.6", features = ["elf32", "elf64", "pe32", "pe64"] }
memoffset = "0.8"
mozilla-central-workspace-hack = { path = "../../../build/workspace-hack" }
thiserror = "1.0"

[target."cfg(target_os = \"windows\")".dependencies]
[dependencies.winapi]
version = "0.3"
+30 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

use thiserror::Error;

#[derive(Debug, Error)]
pub enum ProcessReaderError {
    #[error("Could not convert address {0}")]
    ConvertAddressError(#[from] std::num::TryFromIntError),
    #[cfg(target_os = "windows")]
    #[error("Cannot enumerate the target process's modules")]
    EnumProcessModulesError,
    #[error("goblin failed to parse a module")]
    GoblinError(#[from] goblin::error::Error),
    #[error("Address was out of bounds")]
    InvalidAddress,
    #[error("Could not read from the target process address space")]
    ReadFromProcessError(#[from] ReadError),
    #[cfg(target_os = "windows")]
    #[error("Section was not found")]
    SectionNotFound,
}

#[derive(Debug, Error)]
pub enum ReadError {
    #[cfg(target_os = "windows")]
    #[error("ReadProcessMemory failed")]
    ReadProcessMemoryError,
}
+13 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#[cfg(target_os = "windows")]
type ProcessHandle = winapi::um::winnt::HANDLE;

pub struct ProcessReader {
    process: ProcessHandle,
}

mod error;
mod process_reader;
+6 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#[cfg(target_os = "windows")]
mod windows;
Loading