2012. 12. 20. 02:48



[C] 덤프 메모리를 가져오는  dumpcode.h

01.void printchar(unsigned char c)
02.{
03.if(isprint(c))
04.printf("%c",c);
05.else
06.printf(".");
07.}
08.void dumpcode(unsigned char *buff, int len)
09.{
10.int i;
11. 
12.for(i=0; i<len; i++)
13.{
14.if(i%16==0)
15.printf("0x%08x  ",&buff[i]);
16.printf("%02x ",buff[i]);
17.if(i%16-15==0)
18.{
19.int j;
20.printf("  ");
21.for(j=i-15;j<=i;j++)
22.printchar(buff[j]);
23.printf("\n");
24.}
25.}
26.if(i%16!=0)
27.{
28.int j;
29.int spaces=(len-i+16-i%16)*3+2;
30. 
31.for(j=0;j<spaces;j++)
32.printf(" ");
33.for(j=i-i%16;j<len;j++)
34.printchar(buff[j]);
35.}
36.printf("\n");
37.}


Posted by k1rha