blob: 72accfb65b3a8f8aaa5f4918ec2a1c15611b9976 [file] [log] [blame]
Stefan Reinauer14d35122015-09-03 16:02:55 -07001/*
2 * Copyright 2013-2015 Google Inc.
3 *
Stefan Reinauer72b9baf2019-11-26 17:07:10 -08004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
Stefan Reinauer14d35122015-09-03 16:02:55 -07007 *
8 * This program is distributed in the hope that it will be useful,
Stefan Reinauer72b9baf2019-11-26 17:07:10 -08009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Stefan Reinauer14d35122015-09-03 16:02:55 -070010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Stefan Reinauer14d35122015-09-03 16:02:55 -070012 */
13
14#include <stdio.h>
15#include <stdint.h>
16#include <stddef.h>
17#include <ctype.h>
18#include "em100.h"
19
20void hexdump(const void *memory, size_t length)
21{
Stefan Reinauer79533882019-11-22 00:57:29 -080022 size_t i;
Stefan Reinauer14d35122015-09-03 16:02:55 -070023 uint8_t *m;
24 int all_zero = 0;
25 int all_one = 0;
26
27 m = (uint8_t *) memory;
28
29 for (i = 0; i < length; i += 16) {
Stefan Reinauer79533882019-11-22 00:57:29 -080030 size_t j;
Stefan Reinauer14d35122015-09-03 16:02:55 -070031
32 all_zero++;
33 all_one++;
34 for (j = 0; j < 16; j++) {
35 if (m[i + j] != 0) {
36 all_zero = 0;
37 break;
38 }
39 }
40 for (j = 0; j < 16; j++) {
41 if (m[i + j] != 0xff) {
42 all_one = 0;
43 break;
44 }
45 }
46 if (all_zero < 2 && all_one < 2) {
Stefan Reinauer79533882019-11-22 00:57:29 -080047 printf( "%08zx:", i);
Stefan Reinauer14d35122015-09-03 16:02:55 -070048 for (j = 0; j < 16; j++)
49 printf( " %02x", m[i + j]);
50 printf(" ");
51 for (j = 0; j < 16; j++)
52 printf( "%c",
53 isprint(m[i + j]) ? m[i + j] : '.');
54 printf( "\n");
55 } else if (all_zero == 2 || all_one == 2) {
56 printf( "...\n");
57 }
58 }
59}