Skip to content

Instantly share code, notes, and snippets.

@perillamint
Created March 24, 2015 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perillamint/af82793e4b1b7d83c20a to your computer and use it in GitHub Desktop.
Save perillamint/af82793e4b1b7d83c20a to your computer and use it in GitHub Desktop.
Ohhara's dumpcode - Linux kernel version.
#include <linux/kernel.h>
int isprintable(unsigned char c)
{
if(0x20 <= c && 0x7E >=c)
return 1;
return 0;
}
void printchar(unsigned char c)
{
if(isprintable(c))
printk("%c",c);
else
printk(".");
}
void dumpcode(unsigned char *buff, int len)
{
int i;
printk("----------BEGIN DUMP----------\n");
for(i=0;i<len;i++)
{
if(i%16==0)
printk("0x%08X ",(int)&buff[i]);
printk("%02X ",buff[i]);
if(i%16-15==0)
{
int j;
printk(" ");
for(j=i-15;j<=i;j++)
printchar(buff[j]);
printk("\n");
}
}
if(i%16!=0)
{
int j;
int spaces=(len-i+16-i%16)*3+2;
for(j=0;j<spaces;j++)
printk(" ");
for(j=i-i%16;j<len;j++)
printchar(buff[j]);
}
printk("\n");
printk("---------END DUMP----------\n");
}
void dumpcode(unsigned char *buff, int len);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment