-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdumpcode.c
48 lines (44 loc) · 892 Bytes
/
dumpcode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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");
}