1 /* hexdump.c - hexdump function */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/types.h>
21 #include <grub/misc.h>
22 #include <grub/lib/hexdump.h>
25 hexdump (unsigned long bse
, char *buf
, int len
)
34 pos
= grub_sprintf (line
, "%08lx ", bse
);
39 for (i
= 0; i
< cnt
; i
++)
41 pos
+= grub_sprintf (&line
[pos
], "%02x ", (unsigned char) buf
[i
]);
48 pos
+= grub_sprintf (&line
[pos
], " ");
55 for (i
= 0; i
< cnt
; i
++)
56 line
[pos
++] = ((buf
[i
] >= 32) && (buf
[i
] < 127)) ? buf
[i
] : '.';
62 grub_printf ("%s\n", line
);
64 /* Print only first and last line if more than 3 lines are identical. */
66 && ! grub_memcmp (buf
, buf
+ 1 * 16, 16)
67 && ! grub_memcmp (buf
, buf
+ 2 * 16, 16)
68 && ! grub_memcmp (buf
, buf
+ 3 * 16, 16))
77 while (len
>= 3 * 16 && ! grub_memcmp (buf
, buf
+ 2 * 16, 16));