wireshark 같은 프로그램을 보게 되면 hex로 된 string과 그냥 string 등으로 view를 바꿀 수 있다.
linux에서는 xxd라는 명령어로 hex와 일반 string을 변경할 수 있다.
xxd - make a hexdump or do the reverse.
[예시]
file
GET / HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: ko-KR
User-Agent: Mozilla/4.0 ()
Accept-Encoding: gzip, deflate
Host: local.host
Connection: Keep-Alive
0000000: 4745 5420 2f20 4854 5450 2f31 2e31 0a41 GET / HTTP/1.1.A
0000010: 6363 6570 743a 2069 6d61 6765 2f6a 7065 ccept: image/jpe
0000020: 672c 2061 7070 6c69 6361 7469 6f6e 2f78 g, application/x
0000030: 2d6d 732d 6170 706c 6963 6174 696f 6e2c -ms-application,
0000040: 2069 6d61 6765 2f67 6966 2c20 6170 706c image/gif, appl
0000050: 6963 6174 696f 6e2f 7861 6d6c 2b78 6d6c ication/xaml+xml
0000060: 2c20 696d 6167 652f 706a 7065 672c 2061 , image/pjpeg, a
0000070: 7070 6c69 6361 7469 6f6e 2f78 2d6d 732d pplication/x-ms-
0000080: 7862 6170 2c20 6170 706c 6963 6174 696f xbap, applicatio
0000090: 6e2f 766e 642e 6d73 2d65 7863 656c 2c20 n/vnd.ms-excel,
00000a0: 6170 706c 6963 6174 696f 6e2f 766e 642e application/vnd.
00000b0: 6d73 2d70 6f77 6572 706f 696e 742c 2061 ms-powerpoint, a
00000c0: 7070 6c69 6361 7469 6f6e 2f6d 7377 6f72 pplication/mswor
00000d0: 642c 202a 2f2a 0a41 6363 6570 742d 4c61 d, */*.Accept-La
00000e0: 6e67 7561 6765 3a20 6b6f 2d4b 520a 5573 nguage: ko-KR.Us
00000f0: 6572 2d41 6765 6e74 3a20 4d6f 7a69 6c6c er-Agent: Mozill
0000100: 612f 342e 3020 2829 0a41 6363 6570 742d a/4.0 ().Accept-
0000110: 456e 636f 6469 6e67 3a20 677a 6970 2c20 Encoding: gzip,
0000120: 6465 666c 6174 650a 486f 7374 3a20 6c6f deflate.Host: lo
0000130: 6361 6c2e 686f 7374 0a43 6f6e 6e65 6374 cal.host.Connect
0000140: 696f 6e3a 204b 6565 702d 416c 6976 650a ion: Keep-Alive.
xxd로 수정된 hex 데이터를 다시 수정하려면 아래 명령어를 사용하면 된다.
xxd -r hexa_file
GET / HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: ko-KR
User-Agent: Mozilla/4.0 ()
Accept-Encoding: gzip, deflate
Host: local.host
Connection: Keep-Alive
이걸 .vimrc에 넣고 사용해보자.
map <F5> <ESC>:%!xxd<CR>
map <F6> <ESC>:%!xxd -r<CR>
hexa로 보고 싶은 파일을 vi로 열고 <F5> 를 누르면 hexa string으로 보인다.
<F6>을 누르면 다시 일반 string으로 변할 것이다.
'장인으로의 여정' 카테고리의 다른 글
[linux] cut (0) | 2016.02.22 |
---|---|
[linux] awk (0) | 2016.01.27 |
[bash script] log_viewer.sh (4) | 2016.01.19 |
댓글