From 4a344bc57d880e43392988e26d7e35aff2e78934 Mon Sep 17 00:00:00 2001 From: Ryan McCrystal Date: Thu, 26 Jan 2023 18:07:15 -0800 Subject: [PATCH 1/4] feat: Print out error if pkg-config fails --- build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index a882cc5..9f4258e 100644 --- a/build.rs +++ b/build.rs @@ -4,8 +4,8 @@ use pkg_config::find_library; fn main() -> Result<()> { - if !find_library("liblzma").is_ok() { - panic!("You need to install liblzma-dev. Run \"apt install liblzma-dev\""); + if let Err(e) = find_library("liblzma") { + panic!("You need to install liblzma-dev. Run \"apt install liblzma-dev\"\n\n{}", e); } let mut config = Config::default(); From cde16c455df980f56b8a74db58ce3582d5344cfe Mon Sep 17 00:00:00 2001 From: Ryan McCrystal Date: Thu, 26 Jan 2023 18:18:54 -0800 Subject: [PATCH 2/4] fix: Change `assert!(x == y)` to `assert_eq!(x, y)` --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0abe27b..bf78eb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,7 @@ fn pause() { let _ = stdin.read(&mut [0u8]).unwrap(); } -#[derive(Tabled)] +#[derive(Tabled, Debug)] pub struct MemoryRange { #[tabled(display_with = "display_u64")] pub start_phys_addr: u64, @@ -374,6 +374,7 @@ impl DumpItForLinux { // is null when looking at "readelf -l /proc/kcore" // We retrieve the physical offset from /proc/iomem using the segment sizes. for mem_range in &self.iomem_ranges { + println!("mem_range: {:#X?}", mem_range); if h.p_paddr(endian) == mem_range.start_phys_addr || (h.p_paddr(endian) == 0 && h.p_filesz(endian) == mem_range.memsz) || (h.p_paddr(endian) >= mem_range.start_phys_addr && h.p_paddr(endian) < mem_range.end_phys_addr) { @@ -383,9 +384,9 @@ impl DumpItForLinux { let start_phys_addr = mem_range.start_phys_addr + delta; let memsz = h.p_filesz(endian); - assert!(h.p_filesz(endian) == h.p_memsz(endian)); + assert_eq!(h.p_filesz(endian), h.p_memsz(endian)); if !is_virtual { - assert!(memsz == mem_range.memsz); + assert_eq!(memsz, mem_range.memsz); } let end_phys_addr = start_phys_addr + memsz; let virt_addr = h.p_vaddr(endian); From d023d3475831701ae77fb663163e5b3ed9ec6ad6 Mon Sep 17 00:00:00 2001 From: Ryan McCrystal Date: Thu, 26 Jan 2023 18:20:31 -0800 Subject: [PATCH 3/4] fix: Change `assert!(x == y)` to `assert_eq!(x, y)` --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index bf78eb7..6bb6264 100644 --- a/src/main.rs +++ b/src/main.rs @@ -368,7 +368,7 @@ impl DumpItForLinux { let mut out_file_off = 0; for h in headers { // This should always be true. - assert!(h.p_filesz(endian) == h.p_memsz(endian)); + assert_eq!(h.p_filesz(endian), h.p_memsz(endian)); // NOTE: There is an issue on Amazon Linux and Ubuntu VMs where physaddr // is null when looking at "readelf -l /proc/kcore" From 1f21ef634f08835111f42d11fe376c06e28f7399 Mon Sep 17 00:00:00 2001 From: Ryan McCrystal Date: Fri, 27 Jan 2023 00:51:34 -0800 Subject: [PATCH 4/4] fix: Warn instead of panicking if /proc/iomem segment size and /proc/kcore sizes are different. Use max between the two to dump --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6bb6264..2b1be98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ use std::io::SeekFrom; use std::io::prelude::*; use std::io::BufReader; use std::{mem, env, cmp}; +use std::cmp::max; use std::time::{Instant}; use nix::unistd::Uid; @@ -386,7 +387,9 @@ impl DumpItForLinux { let memsz = h.p_filesz(endian); assert_eq!(h.p_filesz(endian), h.p_memsz(endian)); if !is_virtual { - assert_eq!(memsz, mem_range.memsz); + if memsz != mem_range.memsz { + log::warn!("Mismatch between /proc/iomem segment size ({:#X}) and /proc/kcore segment size ({:#X}). Dumping {:#X} bytes.", mem_range.memsz, memsz, max(memsz, mem_range.memsz)); + } } let end_phys_addr = start_phys_addr + memsz; let virt_addr = h.p_vaddr(endian); @@ -395,7 +398,7 @@ impl DumpItForLinux { self.mem_ranges.push(MemoryRange { start_phys_addr, end_phys_addr, - memsz, + memsz: max(memsz, mem_range.memsz), virt_addr, kcore_file_off, out_file_off,