Skip to content

Commit f8352f3

Browse files
authored
v0.3.0 (#5)
Prefer `impl AsRef<Path>`, expose `read` / `seek`, clippy fixes
1 parent d9f8177 commit f8352f3

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: 0vercl0k

.github/workflows/kdmp-parser-rs.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- name: cargo clippy
5858
env:
5959
RUSTFLAGS: "-Dwarnings"
60-
run: cargo clippy --example parser
60+
run: cargo clippy --workspace --tests --examples
6161

6262
doc:
6363
name: doc
@@ -99,18 +99,18 @@ jobs:
9999
- name: cargo test
100100
env:
101101
TESTDATAS: "."
102-
run: cargo test
102+
run: cargo test --workspace
103103

104104
- name: cargo test release
105105
env:
106106
TESTDATAS: "."
107-
run: cargo test --release
107+
run: cargo test --release --workspace
108108

109109
- name: cargo check
110-
run: cargo check
110+
run: cargo check --workspace
111111

112112
- name: cargo build
113-
run: cargo build --release --example parser
113+
run: cargo build --release --examples
114114

115115
- name: Upload artifacts
116116
uses: actions/upload-artifact@v4

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kdmp-parser"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["Axel '0vercl0k' Souchet"]
66
categories = ["parser-implementations"]

src/bits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ mod tests {
106106
}
107107

108108
#[test]
109+
#[allow(clippy::reversed_empty_ranges)]
109110
fn invalid_ranges() {
110111
assert!(std::panic::catch_unwind(|| 1u64.bits(10..=0)).is_err());
111112
assert!(std::panic::catch_unwind(|| 1u128.bits(0..=128)).is_err());

src/map.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! Unix and Windows (cf [`memory_map_file`] / [`unmap_memory_mapped_file`]).
44
use std::fmt::Debug;
55
use std::io::{Read, Seek};
6-
use std::{convert, fs, io, path, ptr, slice};
6+
use std::path::Path;
7+
use std::{fs, io, ptr, slice};
78

89
pub trait Reader: Read + Seek {}
910

@@ -24,10 +25,7 @@ impl<'map> Debug for MappedFileReader<'map> {
2425

2526
impl<'map> MappedFileReader<'map> {
2627
/// Create a new [`MappedFileReader`] from a path using a memory map.
27-
pub fn new<P>(path: P) -> io::Result<Self>
28-
where
29-
P: convert::AsRef<path::Path>,
30-
{
28+
pub fn new(path: impl AsRef<Path>) -> io::Result<Self> {
3129
// Open the file..
3230
let file = fs::File::open(path)?;
3331

src/parse.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ impl KernelDumpParser {
332332
Ok(parser)
333333
}
334334

335-
pub fn new<P>(dump_path: &P) -> Result<Self>
336-
where
337-
P: AsRef<Path>,
338-
{
335+
pub fn new(dump_path: impl AsRef<Path>) -> Result<Self> {
339336
// We'll assume that if you are opening a dump file larger than 4gb, you don't
340337
// want it memory mapped.
341338
let size = dump_path.as_ref().metadata()?.len();
@@ -612,11 +609,11 @@ impl KernelDumpParser {
612609
filter_addr_translation_err(self.virt_read_struct::<T>(gva))
613610
}
614611

615-
fn seek(&self, pos: io::SeekFrom) -> Result<u64> {
612+
pub fn seek(&self, pos: io::SeekFrom) -> Result<u64> {
616613
Ok(self.reader.borrow_mut().seek(pos)?)
617614
}
618615

619-
fn read(&self, buf: &mut [u8]) -> Result<usize> {
616+
pub fn read(&self, buf: &mut [u8]) -> Result<usize> {
620617
Ok(self.reader.borrow_mut().read(buf)?)
621618
}
622619

tests/regression.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ struct Module {
2828
at: Range<Gva>,
2929
}
3030

31-
impl Into<Module> for M {
32-
fn into(self) -> Module {
33-
Module {
34-
name: self.name,
35-
at: hex_str(&self.start).into()..hex_str(&self.end).into(),
31+
impl From<M> for Module {
32+
fn from(value: M) -> Self {
33+
Self {
34+
name: value.name,
35+
at: hex_str(&value.start).into()..hex_str(&value.end).into(),
3636
}
3737
}
3838
}
@@ -78,7 +78,7 @@ fn compare_modules(parser: &KernelDumpParser, modules: &[Module]) -> bool {
7878
let found_mod = modules.iter().find(|m| m.at == *r).unwrap();
7979
seen.insert(r.start);
8080

81-
let filename = name.rsplit_once('\\').map(|(_, s)| s).unwrap_or(&name);
81+
let filename = name.rsplit_once('\\').map(|(_, s)| s).unwrap_or(name);
8282
if filename.to_lowercase() != found_mod.name.to_lowercase() {
8383
if found_mod.name == "nt" && filename == "ntoskrnl.exe" {
8484
continue;

0 commit comments

Comments
 (0)