Created
March 24, 2015 16:02
-
-
Save perillamint/af82793e4b1b7d83c20a to your computer and use it in GitHub Desktop.
Ohhara's dumpcode - Linux kernel version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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