今回もsizeコマンド。
お気に入りのsizeコマンドですが、周辺についても知りたくなりました。
sizeコマンドはどのパッケージに含まれるのでしょうか。
takk@deb9:~$ which size /usr/bin/size takk@deb9:~$
takk@deb9:~/src$ apt-file search /usr/bin/size bin86: /usr/bin/size86 binutils: /usr/bin/size emboss: /usr/bin/sizeseq takk@deb9:~/src$
binutilsのようです。そういえば、binutilsって、バイナリ関連のツールであることは分かるのですが、 どんなコマンドがあるんでしょう。
ソースを取得します。
takk@deb9:~/src$ apt-get source binutils 省略 takk@deb9:~/src$ cd binutils-2.28/ takk@deb9:~/src/binutils-2.28$ ls COPYING config gprof md5.sum COPYING.LIB config-ml.in include missing COPYING3 config.guess install-sh mkdep COPYING3.LIB config.rpath intl mkinstalldirs ChangeLog config.sub ld move-if-change MAINTAINERS configure libiberty opcodes Makefile.def configure.ac libtool.m4 setup.com Makefile.in cpu ltgcc.m4 src-release.sh Makefile.tpl debian ltmain.sh symlink-tree README depcomp ltoptions.m4 texinfo README-maintainer-mode elfcpp ltsugar.m4 ylwrap bfd etc ltversion.m4 zlib binutils gas lt~obsolete.m4 compile gold makefile.vms takk@deb9:~/src/binutils-2.28$
sizeコマンドはおそらくsize.cなので、findで場所を確認。
takk@deb9:~/src/binutils-2.28$ find -name size.c ./binutils/size.c takk@deb9:~/src/binutils-2.28$
binutilsというディレクトリに、sizeの仲間たちがいるに違いありません。
takk@deb9:~/src/binutils-2.28$ cd binutils takk@deb9:~/src/binutils-2.28/binutils$
ファイルサイズでソートして一覧にしてみます。
takk@deb9:~/src/binutils-2.28/binutils$ wc *.c -l | sort | pr -t3
22 is-ranlib.c 617 size.c 1905 syslex.c
22 not-ranlib.c 662 bucomm.c 2034 arlex.c
23 is-strip.c 705 strings.c 2063 deflex.c
23 maybe-ranlib.c 715 sysdump.c 2071 defparse.c
23 maybe-strip.c 730 resres.c 2074 mcparse.c
23 not-strip.c 767 elfedit.c 2167 resbin.c
25 syslex_wrap.c 767 rescoff.c 2168 nlmconv.c
30 emul_vanilla.c 880 rdcoff.c 2211 od-macho.c
40 version.c 904 rclex.c 2271 wrstabs.c
66 bin2c.c 905 coffgrok.c 2617 nlmheader.c
70 bfdtest1.c 907 winduni.c 2838 prdbg.c
106 bfdtest2.c 918 elfcomm.c 3371 debug.c
140 emul_aix.c 1073 unwind-ia64.c 3390 resrc.c
148 binemul.c 1172 windmc.c 3927 objdump.c
212 rename.c 1254 dllwrap.c 4589 dlltool.c
248 filemode.c 1408 windres.c 4682 rcparse.c
291 cxxfilt.c 1492 ar.c 4898 objcopy.c
303 od-elf32_avr.c 1668 arparse.c 5439 stabs.c
440 mclex.c 1810 nm.c 7410 ieee.c
461 rddbg.c 1842 od-xcoff.c 7778 dwarf.c
484 arsup.c 1859 sysinfo.c 17217 readelf.c
510 addr2line.c 1861 srconv.c 116309 合計
563 coffdump.c
takk@deb9:~/src/binutils-2.28/binutils$
エルフやドワーフもいますね。
renameって、バイナリツールなんですね、意外です。
bin2c.cってのがバイナリを文字に変換?するようなコマンドに見えますが、聞いたことがないです。man bin2cでも出てこないし。
中身を見てみます。行数が少ないので全文。
takk@deb9:~/src/binutils-2.28/binutils$ cat -n bin2c.c
1 /* bin2c.c -- dump binary file in hex format
2 Copyright (C) 2007-2017 Free Software Foundation, Inc.
3
4 This file is part of GNU Binutils.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include "binary-io.h"
24
25 int
26 main (int argc, char *argv[])
27 {
28 int c;
29 int i;
30
31 if (argc != 1)
32 {
33 int ishelp = 0;
34 FILE *stream;
35
36 if (argc == 2 && argv[1][0] == '-')
37 {
38 const char *opt = &argv[1][1];
39 if (*opt == '-')
40 ++opt;
41 ishelp = *opt == 'h' || *opt == 'H';
42 }
43
44 stream = ishelp ? stdout : stderr;
45 fprintf (stream, "Usage: %s < input_file > output_file\n", argv[0]);
46 fprintf (stream, "Prints bytes from stdin in hex format.\n");
47 exit (!ishelp);
48 }
49
50 SET_BINARY (fileno (stdin));
51
52 i = 0;
53 while ((c = getc (stdin)) != EOF)
54 {
55 printf ("0x%02x,", c);
56 if (++i == 16)
57 {
58 printf ("\n");
59 i = 0;
60 }
61 }
62 if (i != 0)
63 printf ("\n");
64
65 exit (0);
66 }
16進ダンプするプログラムのようです。bin2cなんて名前を使うとコマンドとしても重複しやすいし、16進ダンプなら、他にもあるのに、このソースは何のために使うのかがよく分かりません。 不思議な存在です。



コメント