
この記事はかなり昔に執筆されており、誤りを含む場合があります。
1986年(第三回)IOCCCグランプリ作品中に、なんとバイナリエディタ表示コードが投稿されていました! 以下にご紹介します~^^;)使い方は、パラメータにファイルパスを渡すと、バイナリコードとアスキーコードを表示してくれます。#include <stdio.h> #define O1O printf #define OlO putchar #define O10 exit #define Ol0 strlen #define QLQ fopen #define OlQ fgetc #define O1Q abs #define QO0 for typedef char lOL; lOL*QI[] = {"Use:\012\011dump file\012","Unable to open file '\x25s'\012", "\012"," ",""}; main(I,Il) lOL*Il[]; { FILE *L; unsigned lO; int Q,OL[' '^'0'],llO = EOF, O=1,l=0,lll=O+O+O+l,OQ=056; lOL*llL="%2x "; (I != 1<<1&&(O1O(QI[0]),O10(1011-1010))), ((L = QLQ(Il[O],"r"))==0&&(O1O(QI[O],Il[O]),O10(O))); lO = I-(O<<l<<O); while (L-l,1) { QO0(Q = 0L;((Q &~(0x10-O))== l); OL[Q++] = OlQ(L)); if (OL[0]==llO) break; O1O("\0454x: ",lO); if (I == (1<<1)) { QO0(Q=Ol0(QI[O<<O<<1]);Q=' '&&l<='\~'; } それでは早速解説を始めます^^;) まずは、いつもの如くプリプロセッサの実行結果を表示させ、ついでに typedef されている 「IOL」を「char」に戻します。
変数名がトリッキー過ぎる為、以下の様な 多少分かりやすい(?)変数名に置換します。#include <stdio.h> char*QI[] = {"Use:\012\011dump file\012","Unable to open file '\x25s'\012", "\012"," ",""}; main(I,Il) char*Il[]; { FILE *L; unsigned lO; int Q,OL[' '^'0'],llO = (-1), O=1,l=0,lll=O+O+O+l,OQ=056; char*llL="%2x "; (I != 1<<1&&(printf(QI[0]),exit(1011-1010))), ((L = fopen(Il[O],"r"))==0&&(printf(QI[O],Il[O]),exit(O))); lO = I-(O<<l<<O); while (L-l,1) { for(Q = 0L;((Q &~(0x10-O))== l); OL[Q++] = fgetc(L)); if (OL[0]==llO) break; printf("\0454x: ",lO); if (I == (1<<1)) { for(Q=strlen(QI[O<<O<<1]);Q=' '&&l<='\~'; }
| 元変数名 | 新変数名 | |
|---|---|---|
| QI | ⇒ | str |
| Il | ⇒ | argv |
| I | ⇒ | argc |
| llO | ⇒ | k |
| lll | ⇒ | s |
| OL | ⇒ | j |
| OQ | ⇒ | t |
| llL | ⇒ | psz |
| lO | ⇒ | io |
| Q | ⇒ | i |
| O | ⇒ | q |
| l | ⇒ | r |
| L | ⇒ | fp |
1 : #include <stdio.h>
2 :
3 : char *str[] = { "Use:\012\011dump file\012", "Unable to open file '\x25s'\012", "\012", " ", "" };
4 :
5 : main(argc,argv)
6 : char *argv[];
7 : {
8 : FILE *fp;
9 : unsigned io;
10 : int i, j[' ' ^ '0'], k = (-1), q = 1, r = 0, s = q+q+q+r, t = 056;
11 : char *psz = "%2x ";
12 :
13 : (argc != 1<<1 && (printf(str[0]), exit(1011-1010))),
14 : ( (fp = fopen(argv[q], "r")) == 0 && (printf(str[q], argv[q]), exit(q)) );
15 :
16 : io = argc-(q<<r<<q);
17 :
18 : while (fp-r,1)
19 : {
20 : for(i = 0L; ((i &~(0x10-q))== r); j[i++] = fgetc(fp));
21 :
22 : if (j[0]==k)
23 : break;
24 :
25 : printf("\0454x: ",io);
26 :
27 : if (argc == (1<<1))
28 : {
29 : for (i = strlen(str[q<<q<<1]); i= ' ' && r <= '\~';
49 : } 1 : #include <stdio.h>
2 :
3 : char *str[] = { "Use:\n\tdump file\n", "Unable to open file '%s'\n", "\n", " ", "" };
4 :
5 : main(argc,argv)
6 : char *argv[];
7 : {
8 : FILE *fp;
9 : unsigned io;
10 : int i, j[16];
11 : char *psz = "%2x ";
12 :
13 : (argc != 2 && (printf(str[0]), exit(1))),
14 : ( (fp = fopen(argv[1], "r")) == 0 && (printf(str[1], argv[1]), exit(1)) );
15 :
16 : io = argc - 2;
17 :
18 : while (fp,1)
19 : {
20 : for(i = 0; i != 16; j[i++] = fgetc(fp));
21 :
22 : if (j[0] == -1)
23 : break;
24 :
25 : printf("%4x: ",io);
26 :
27 : if (argc == 2)
28 : {
29 : for (i = strlen(str[4]); i= ' ' && r <= '\~';
49 : } 1 : #include <stdio.h>
2 :
3 : char *str[] = { "Use:\n\tdump file\n", "Unable to open file '%s'\n" };
4 :
5 : main(argc,argv)
6 : char *argv[];
7 : {
8 : FILE *fp;
9 : unsigned io;
10 : int i, j[16];
11 : char *psz = "%2x ";
12 :
13 : (argc != 2 && (printf(str[0]), exit(1))),
14 : ( (fp = fopen(argv[1], "r")) == 0 && (printf(str[1], argv[1]), exit(1)) );
15 :
16 : io = 0;
17 :
18 : while (fp,1)
19 : {
20 : for(i = 0; i != 16; j[i++] = fgetc(fp));
21 :
22 : if (j[0] == -1)
23 : break;
24 :
25 : printf("%4x: ",io);
26 :
27 : if (argc == 2)
28 : {
29 : for (i = 0; i < 16; i++)
30 : printf( (j[i] != -1) ? psz : " ", j[i]);
31 :
32 : printf(" ");
33 : }
34 :
35 : for (i = 0; i < 16; i++)
36 : {
37 : (j[i] != -1) ? ((D(j[i]) == 0 && (*(j + i) = '.')), putchar(j[i]))
38 : : putchar(' ');
39 : }
40 :
41 : printf("\n");
42 : io += i;
43 : }
44 : }
45 :
46 : D(r)
47 : {
48 : return r >= ' ' && r <= '\~';
49 : }