Skip to content

Commit

Permalink
refactor: update 'new' parameter to use 'impl AsRef<Path>' instead of…
Browse files Browse the repository at this point in the history
… '&Path' for flexibility
  • Loading branch information
joaoviictorti committed Jan 23, 2025
1 parent 8c42cd8 commit b9d316b
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "userdmp"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "A library in Rust for parsing Minidump (.dmp) files generated in user mode on Windows"
license = "MIT"
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ The userdmp library provides tools to parse and analyze Minidump (.dmp) files ge

To start working with a Minidump file, use the `UserDump::new` function to parse the file and create a `UserDump` instance:
```rust, ignore
use std::path::Path;
use userdmp::{UserDump, UserDmpError};
fn main() -> Result<(), UserDmpError> {
let path = Path::new("example.dmp");
// Parse the Minidump file
let dump = UserDump::new(path)?;
let dump = UserDump::new("example.dmp")?;
println!("Minidump parsed successfully!");
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/handles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions examples/handles/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::path::Path;
use userdmp::{error::UserDmpError, UserDump};

fn main() -> Result<(), UserDmpError> {
let path = Path::new("C:\\Examples.dmp");
let dmp = UserDump::new(path)?;
let dmp = UserDump::new("C:\\Examples.dmp")?;

for(_, handle) in dmp.handles() {
println!("Handle: {}", handle.handle());
Expand Down
2 changes: 1 addition & 1 deletion examples/memorys/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions examples/memorys/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::path::Path;
use userdmp::{error::UserDmpError, UserDump};

fn main() -> Result<(), UserDmpError> {
let path = Path::new("C:\\Examples.dmp");
let dmp = UserDump::new(path)?;
let dmp = UserDump::new("C:\\Examples.dmp")?;

for(_, memory) in dmp.memorys() {
println!("Start: {}", memory.start_addr());
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions examples/modules/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::path::Path;
use userdmp::{error::UserDmpError, UserDump};

fn main() -> Result<(), UserDmpError> {
let path = Path::new("C:\\Examples.dmp");
let dmp = UserDump::new(path)?;
let dmp = UserDump::new("C:\\Examples.dmp")?;

for (_, module) in dmp.modules().iter() {
println!("[*] Path: {:?}", module.path);
Expand Down
2 changes: 1 addition & 1 deletion examples/system/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions examples/system/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::path::Path;
use userdmp::{error::UserDmpError, UserDump};

fn main() -> Result<(), UserDmpError> {
let path = Path::new("C:\\Examples.dmp");
let dmp = UserDump::new(path)?;
let dmp = UserDump::new("C:\\Examples.dmp")?;
let system = dmp.system;

println!("Number Of Processors: {}", system.number_of_processors);
Expand Down
2 changes: 1 addition & 1 deletion examples/threads/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions examples/threads/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::path::Path;
use userdmp::{error::UserDmpError, UserDump};

fn main() -> Result<(), UserDmpError> {
let path = Path::new("C:\\Examples.dmp");
let dmp = UserDump::new(path)?;
let dmp = UserDump::new("C:\\Examples.dmp")?;

for (tid, thread) in dmp.threads().iter() {
println!("[*] TID: {:?}", tid);
Expand Down
2 changes: 1 addition & 1 deletion src/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a> MappingFile<'a> {
/// Ok(())
/// }
/// ```
pub fn new(path: &Path) -> Result<Self, UserDmpError> {
pub fn new(path: impl AsRef<Path>) -> Result<Self, UserDmpError> {
let file = File::open(path)?;
let (buffer, address) = mapper::map_file(file)?;
Ok(Self { buffer, address })
Expand Down
6 changes: 3 additions & 3 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ impl<'a> UserDump<'a> {
/// Err(e) => eprintln!("Failed to parse minidump: {:?}", e),
/// }
/// ```
pub fn new(path: &Path) -> Result<Self, UserDmpError> {
pub fn new(path: impl AsRef<Path>) -> Result<Self, UserDmpError> {
// Mapping the file in memory to the target environment (Windows or Linux).
let mapped_file = MappingFile::new(path)?;
Self::parser(mapped_file)
Self::parse(mapped_file)
}

/// Returns a reference to the list of threads in the parsed minidump.
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'a> UserDump<'a> {
///
/// * `Ok(Self)` - If the file is parsed successfully.
/// * `Err(UserDmpError)` - If the file format is invalid or if parsing fails.
fn parser(mapped_file: MappingFile<'a>) -> Result<Self, UserDmpError> {
fn parse(mapped_file: MappingFile<'a>) -> Result<Self, UserDmpError> {
// Creates a cursor to navigate the mapped file.
let mut cursor = mapped_file.cursor();

Expand Down

0 comments on commit b9d316b

Please sign in to comment.