Stefan Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013-2015 Google Inc. |
| 3 | * |
Stefan Reinauer | 72b9baf | 2019-11-26 17:07:10 -0800 | [diff] [blame] | 4 | * 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 Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
Stefan Reinauer | 72b9baf | 2019-11-26 17:07:10 -0800 | [diff] [blame] | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Stefan Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Stefan Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <stdint.h> |
| 16 | #include <stddef.h> |
| 17 | #include <ctype.h> |
| 18 | #include "em100.h" |
| 19 | |
| 20 | void hexdump(const void *memory, size_t length) |
| 21 | { |
Stefan Reinauer | 7953388 | 2019-11-22 00:57:29 -0800 | [diff] [blame] | 22 | size_t i; |
Stefan Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 23 | 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 Reinauer | 7953388 | 2019-11-22 00:57:29 -0800 | [diff] [blame] | 30 | size_t j; |
Stefan Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 31 | |
| 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 Reinauer | 7953388 | 2019-11-22 00:57:29 -0800 | [diff] [blame] | 47 | printf( "%08zx:", i); |
Stefan Reinauer | 14d3512 | 2015-09-03 16:02:55 -0700 | [diff] [blame] | 48 | 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 | } |