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