mirror of
https://github.com/mbilker/vgpu_unlock-rs.git
synced 2025-06-08 05:28:21 +02:00
Add helper for pretty printing data
This commit is contained in:
parent
2f21bb8d9d
commit
28a699a184
41
src/dump.rs
Normal file
41
src/dump.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use std::cmp;
|
||||
use std::fmt::Write;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn dump(data: &[u8]) -> String {
|
||||
let mut output = String::new();
|
||||
|
||||
if data.is_empty() {
|
||||
output.push_str("\t--- Empty ---");
|
||||
}
|
||||
|
||||
for i in (0..data.len()).step_by(16) {
|
||||
let to_print = cmp::min(16, data.len() - i);
|
||||
let to_pad = 16 - to_print;
|
||||
let data = &data[i..i + to_print];
|
||||
|
||||
let _ = write!(output, " {:08x}", i);
|
||||
|
||||
for byte in data {
|
||||
let _ = write!(output, " {:02x}", byte);
|
||||
}
|
||||
|
||||
for _ in 0..to_pad {
|
||||
output.push_str(" ");
|
||||
}
|
||||
|
||||
output.push(' ');
|
||||
output.extend(data.iter().map(|&c| {
|
||||
if c < 0x20 || c >= 0x7f {
|
||||
'.'
|
||||
} else {
|
||||
c as char
|
||||
}
|
||||
}));
|
||||
output.push('\n');
|
||||
}
|
||||
|
||||
output.push('\n');
|
||||
|
||||
output
|
||||
}
|
@ -19,6 +19,7 @@ use std::str;
|
||||
use libc::RTLD_NEXT;
|
||||
use serde::Deserialize;
|
||||
|
||||
mod dump;
|
||||
mod format;
|
||||
mod log;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user