Print a big byte buffer Because it's long it'll be printed in several lines, each 16 bytes Example print_multiline_buffer(&[0xa0, 0x00, 0x00, 0x36, 0x62, 0x6e, 0x03, 0x00, 0xc5, 0x11, 0x80, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], 0x2000) Output: 00002000: a000 0036 626e 0300 c511 8035 0000 0000 ...6bn.....5.... 00
(buffer: &[u8], offset: usize)
| 237 | /// 00002000: a000 0036 626e 0300 c511 8035 0000 0000 ...6bn.....5.... |
| 238 | /// 00002010: 0000 0000 0000 0000 0000 0000 0000 00 ................ |
| 239 | pub fn print_multiline_buffer(buffer: &[u8], offset: usize) { |
| 240 | let chunk_size = 16; |
| 241 | for (i, chunk) in buffer.chunks(chunk_size).enumerate() { |
| 242 | print!("{:08x}:", offset + i * chunk_size); |
| 243 | print_chunk(chunk, false); |
| 244 | |
| 245 | // Make sure ASCII section aligns, even if less than 16 byte chunks |
| 246 | if chunk.len() < 16 { |
| 247 | let byte_padding = 16 - chunk.len(); |
| 248 | let space_padding = byte_padding / 2; |
| 249 | let padding = byte_padding * 2 + space_padding; |
| 250 | print!("{}", " ".repeat(padding)); |
| 251 | } |
| 252 | print!(" "); |
| 253 | |
| 254 | print_ascii_buffer(chunk, true); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | /// Find a sequence of bytes in a long slice of bytes |
| 259 | pub fn find_sequence(haystack: &[u8], needle: &[u8]) -> Option<usize> { |
no test coverage detected