#include <stdio.h>
int main(int argc, char **argv)
{
size_t length;
unsigned char buffer[0x100000];
FILE *fp;
int i, j;
if (argc != 2)
{
printf("Usage: binary filename\n");
return 0;
}
fp = fopen(argv[1], "r");
if (fp == NULL)
{
printf("No file named %s\n", argv[1]);
return 0;
}
length = fread(&buffer[0], 1, 0x100000, fp);
fclose(fp);
for (i = 0; i < length; i++)
{
if ((i % 16) == 0)
{
printf("\n%08x: ", i);
}
printf("%02x ", buffer[i]);
if ((i % 16) == 15)
{
printf("|");
for (j = i - 15; j <= i; j++)
{
if ((buffer[j] >= 33) && (buffer[j] <= 126) && (buffer[j] != 0))
{
printf("%c", buffer[j]);
}
else
{
printf(".");
}
}
}
}
for (j = i % 16; j < 16; j++)
{
printf(" ");
}
printf("|");
for (j = (i / 16) * 16; j < i; j++)
{
if ((buffer[j] >= 33) && (buffer[j] <= 126) && (buffer[j] != 0))
{
printf("%c", buffer[j]);
}
else
{
printf(".");
}
}
}
|