C/Linux :: 리눅스에서 파일 덤프... dump.c
2010/12/05 23:37
리눅스 프로그래밍 과제로 작성했던 dump 프로그램입니다.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define BUFSIZE 16
char * getDump (char *data, int size, char *out)
{
int offs;
for (offs = 0; offs < size; offs++)
{
sprintf (&out[offs * 3], "%02x ", (unsigned char)data[offs]);
}
return out;
}
char * getASCII (char *data, int size, char *out)
{
int offs;
for (offs = 0; offs < size; offs++)
{
if (data[offs] < 0x20 || data[offs] >= 0x7f)
sprintf (&out[offs], "%c", '.');
else
sprintf (&out[offs], "%c", data[offs]);
}
return out;
}
int main (int argc, char **argv)
{
char buf[BUFSIZE + 1] = {0};
char dumpbuf[BUFSIZE * 3 + 1] = {0};
char asciibuf[BUFSIZE + 1] = {0};
int fdes;
int offs = 0;
if (argc < 2)
{
printf ("[*] USAGE : $%s [file]\n", argv[0]);
exit (1);
}
fdes = open (argv[1], O_RDONLY);
if (fdes == -1)
{
perror ("[*] FILE");
exit (1);
}
while (read (fdes, buf, BUFSIZE) > 0)
{
printf ("%08x: %s %s\n", \
(offs++) * BUFSIZE, \
getDump (buf, BUFSIZE, dumpbuf), \
getASCII (buf, BUFSIZE, asciibuf));
memset (buf, 0, BUFSIZE);
}
close (fdes);
return 0;
}
"0x08 과거의 글모음 / 내 머리 속의 노트" 분류의 다른 글
| 블로그(텍스트큐브) 서버를 직접 만들어보기 - OS & Package 설치 | 2011/02/16 |
| C/Linux :: ls -l 을 수행하는 ll.c | 2010/10/30 |
| python :: Socket Communication with Thread | 2010/10/10 |
| 리눅스(우분투)에서 부경대학교 무선랜 접속하기 | 2010/07/19 |
| python :: python과 C의 삼항연산 | 2010/06/24 |
Trackback Address:http://hisjournal.net/blog/trackback/347