#hex-dump #debugging #closures #u8 #u16 #u32 #dbgtools

dbgtools-hexdump

Hexdump functions for use in dbgtools

1 unstable release

0.1.0 May 5, 2021

#1961 in Development tools


Used in dbgtools

0BSD license

6KB
65 lines

A hex dumper which calls a closure to allow the application to choose how to output the dump.

Example: Dumping a struct

use dbgtools_hexdump::{Config, hexdump};

struct MyStruct {
  eight: u8,
  sixteen: u16,
  thirtytwo: u32
}

let data = MyStruct { eight: 8, sixteen: 16, thirtytwo: 32 };
hexdump(Config::default(), &data, |offs, hex, ascii| {
  println!("{:08x} {} {}", offs, hex, ascii);
});

Example: Dumping a struct with addresses

Sometimes it may be useful to include the real addresses in dumped buffers. This can be accomplished by adding a base offset to the configuration context.

use dbgtools_hexdump::{Config, hexdump};

struct MyStruct {
  eight: u8,
  sixteen: u16,
  thirtytwo: u32
}

let data = MyStruct { eight: 8, sixteen: 16, thirtytwo: 32 };
hexdump(Config {
   offs: &data as *const _ as usize,
   ..Default::default()
  }, &data, |offs, hex, ascii| {
  println!("{:08x} {} {}", offs, hex, ascii);
});

No runtime deps