The smallest possible Unix program is one that simply exits, returning either true
(0
) or false
(any other value).
Indeed, true and false are standard Unix utilities that do just that. Those that come with FreeBSD are written in C, as are just about all system utilities.
Their source code is very simple. Here, for example, is the code for true, as found in /usr/src/usr.bin/true/true.c:
/* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)true.c 8.1 (Berkeley) 6/9/93"; #endif /* not lint */ main() { exit(0); } |
Not counting the copyright, it is simply one C statement: exit(0)
. The compiled and linked executable is 2,364 bytes long. Let us take a look at what is inside:
0000 0000 : 7F 45 4C 46 01 01 01 00 | 46 72 65 65 42 53 44 00 .ELF....FreeBSD. 0000 0001 : 02 00 03 00 01 00 00 00 | DC 82 04 08 34 00 00 00 ............4... 0000 0002 : 1C 06 00 00 00 00 00 00 | 34 00 20 00 05 00 28 00 ........4. ...(. 0000 0003 : 14 00 13 00 06 00 00 00 | 34 00 00 00 34 80 04 08 ........4...4... 0000 0004 : 34 80 04 08 A0 00 00 00 | A0 00 00 00 05 00 00 00 4............... 0000 0005 : 04 00 00 00 03 00 00 00 | D4 00 00 00 D4 80 04 08 ................ 0000 0006 : D4 80 04 08 19 00 00 00 | 19 00 00 00 04 00 00 00 ................ 0000 0007 : 01 00 00 00 01 00 00 00 | 00 00 00 00 00 80 04 08 ................ 0000 0008 : 00 80 04 08 C7 03 00 00 | C7 03 00 00 05 00 00 00 ................ 0000 0009 : 00 10 00 00 01 00 00 00 | C8 03 00 00 C8 93 04 08 ................ 0000 000A : C8 93 04 08 1C 01 00 00 | 20 01 00 00 06 00 00 00 ........ ....... 0000 000B : 00 10 00 00 02 00 00 00 | 74 04 00 00 74 94 04 08 ........t...t... 0000 000C : 74 94 04 08 70 00 00 00 | 70 00 00 00 06 00 00 00 t...p...p....... 0000 000D : 04 00 00 00 2F 75 73 72 | 2F 6C 69 62 65 78 65 63 ..../usr/libexec 0000 000E : 2F 6C 64 2D 65 6C 66 2E | 73 6F 2E 31 00 00 00 00 /ld-elf.so.1.... 0000 000F : 03 00 00 00 0E 00 00 00 | 0A 00 00 00 05 00 00 00 ................ 0000 0010 : 02 00 00 00 00 00 00 00 | 00 00 00 00 0B 00 00 00 ................ 0000 0011 : 00 00 00 00 09 00 00 00 | 0C 00 00 00 0D 00 00 00 ................ 0000 0012 : 04 00 00 00 00 00 00 00 | 01 00 00 00 03 00 00 00 ................ 0000 0013 : 06 00 00 00 07 00 00 00 | 08 00 00 00 00 00 00 00 ................ 0000 0014 : 00 00 00 00 00 00 00 00 | 00 00 00 00 0B 00 00 00 ................ 0000 0015 : 74 94 04 08 00 00 00 00 | 11 00 F1 FF 14 00 00 00 t............... 0000 0016 : 60 94 04 08 00 00 00 00 | 11 00 F1 FF 2A 00 00 00 `...........*... 0000 0017 : A4 82 04 08 00 00 00 00 | 12 00 06 00 30 00 00 00 ............0... 0000 0018 : C0 83 04 08 00 00 00 00 | 12 00 09 00 36 00 00 00 ............6... 0000 0019 : CC 82 04 08 50 00 00 00 | 12 00 00 00 3B 00 00 00 ....P.......;... 0000 001A : C8 93 04 08 04 00 00 00 | 11 00 0B 00 46 00 00 00 ............F... 0000 001B : BC 82 04 08 74 00 00 00 | 12 00 00 00 4D 00 00 00 ....t.......M... 0000 001C : E4 94 04 08 04 00 00 00 | 11 00 10 00 55 00 00 00 ............U... 0000 001D : C0 83 04 08 00 00 00 00 | 11 00 F1 FF 5C 00 00 00 ............\... 0000 001E : E4 94 04 08 00 00 00 00 | 11 00 F1 FF 63 00 00 00 ............c... 0000 001F : E4 94 04 08 00 00 00 00 | 11 00 F1 FF 6F 00 00 00 ............o... 0000 0020 : E8 94 04 08 00 00 00 00 | 11 00 F1 FF 74 00 00 00 ............t... 0000 0021 : E8 94 04 08 00 00 00 00 | 11 00 F1 FF 00 6C 69 62 .............lib 0000 0022 : 63 2E 73 6F 2E 33 00 5F | 44 59 4E 41 4D 49 43 00 c.so.3._DYNAMIC. 0000 0023 : 5F 47 4C 4F 42 41 4C 5F | 4F 46 46 53 45 54 5F 54 _GLOBAL_OFFSET_T 0000 0024 : 41 42 4C 45 5F 00 5F 69 | 6E 69 74 00 5F 66 69 6E ABLE_._init._fin 0000 0025 : 69 00 65 78 69 74 00 5F | 5F 70 72 6F 67 6E 61 6D i.exit.__prognam 0000 0026 : 65 00 61 74 65 78 69 74 | 00 65 6E 76 69 72 6F 6E e.atexit.environ 0000 0027 : 00 5F 65 74 65 78 74 00 | 5F 65 64 61 74 61 00 5F ._etext._edata._ 0000 0028 : 5F 62 73 73 5F 73 74 61 | 72 74 00 5F 65 6E 64 00 _bss_start._end. 0000 0029 : 65 6E 64 00 6C 94 04 08 | 07 07 00 00 70 94 04 08 end.l.......p... 0000 002A : 07 05 00 00 E8 A7 00 00 | 00 C3 00 00 FF 35 64 94 .............5d. 0000 002B : 04 08 FF 25 68 94 04 08 | 00 00 00 00 FF 25 6C 94 ...h........l. 0000 002C : 04 08 68 00 00 00 00 E9 | E0 FF FF FF FF 25 70 94 ..h..........p. 0000 002D : 04 08 68 08 00 00 00 E9 | D0 FF FF FF 55 89 E5 57 ..h.........U..W 0000 002E : 56 53 89 D2 8D 7D 08 8B | 75 04 8D 5C B5 0C 89 1D VS...}..u..\.... 0000 002F : E4 94 04 08 85 F6 7E 28 | 83 7D 08 00 74 22 8B 45 ......~(.}..t".E 0000 0030 : 08 A3 C8 93 04 08 80 38 | 00 74 15 90 80 38 2F 75 .......8.t...8/u 0000 0031 : 09 8D 48 01 89 0D C8 93 | 04 08 40 80 38 00 75 EC ..H.......@.8.u. 0000 0032 : B8 74 94 04 08 85 C0 74 | 09 52 E8 8D FF FF FF 83 .t.....t.R...... 0000 0033 : C4 04 68 C0 83 04 08 E8 | 80 FF FF FF E8 63 FF FF ..h..........c.. 0000 0034 : FF 53 57 56 E8 6B 00 00 | 00 50 E8 7D FF FF FF 90 .SWV.k...P.}.... 0000 0035 : 55 89 E5 53 BB 54 94 04 | 08 83 3D 54 94 04 08 00 U..S.T....=T.... 0000 0036 : 74 0E 89 F6 8B 03 FF D0 | 83 C3 04 83 3B 00 75 F4 t...........;.u. 0000 0037 : 8B 5D FC C9 C3 8D 76 00 | 55 89 E5 53 BB 5C 94 04 .]....v.U..S.\.. 0000 0038 : 08 83 3D 5C 94 04 08 00 | 74 12 89 F6 83 C3 04 83 ..=\....t....... 0000 0039 : 3B 00 75 F8 EB 06 89 F6 | 8B 03 FF D0 83 C3 FC 81 ;.u............. 0000 003A : FB 58 94 04 08 77 F1 8B | 5D FC C9 C3 55 89 E5 C9 .X...w..]...U... 0000 003B : C3 90 90 90 55 89 E5 6A | 00 E8 0E FF FF FF 89 F6 ....U..j........ 0000 003C : E8 B3 FF FF FF C3 00 00 | C6 83 04 08 40 28 23 29 ............@(#) 0000 003D : 20 43 6F 70 79 72 69 67 | 68 74 20 28 63 29 20 31 Copyright (c) 1 0000 003E : 39 38 38 2C 20 31 39 39 | 33 0A 09 54 68 65 20 52 988, 1993..The R 0000 003F : 65 67 65 6E 74 73 20 6F | 66 20 74 68 65 20 55 6E egents of the Un 0000 0040 : 69 76 65 72 73 69 74 79 | 20 6F 66 20 43 61 6C 69 iversity of Cali 0000 0041 : 66 6F 72 6E 69 61 2E 20 | 20 41 6C 6C 20 72 69 67 fornia. All rig 0000 0042 : 68 74 73 20 72 65 73 65 | 72 76 65 64 2E 0A 00 40 hts reserved...@ 0000 0043 : 28 23 29 74 72 75 65 2E | 63 09 38 2E 31 20 28 42 (#)true.c.8.1 (B 0000 0044 : 65 72 6B 65 6C 65 79 29 | 20 36 2F 39 2F 39 33 00 erkeley) 6/9/93. 0000 0045 : FF FF FF FF 00 00 00 00 | FF FF FF FF 00 00 00 00 ................ 0000 0046 : 74 94 04 08 00 00 00 00 | 00 00 00 00 C2 82 04 08 t............... 0000 0047 : D2 82 04 08 01 00 00 00 | 01 00 00 00 0C 00 00 00 ................ 0000 0048 : A4 82 04 08 0D 00 00 00 | C0 83 04 08 04 00 00 00 ................ 0000 0049 : F0 80 04 08 05 00 00 00 | 1C 82 04 08 06 00 00 00 ................ 0000 004A : 3C 81 04 08 0A 00 00 00 | 78 00 00 00 0B 00 00 00 <.......x....... 0000 004B : 10 00 00 00 15 00 00 00 | 00 00 00 00 03 00 00 00 ................ 0000 004C : 60 94 04 08 02 00 00 00 | 10 00 00 00 14 00 00 00 `............... 0000 004D : 11 00 00 00 17 00 00 00 | 94 82 04 08 00 00 00 00 ................ 0000 004E : 00 00 00 00 00 47 43 43 | 3A 20 28 47 4E 55 29 20 .....GCC: (GNU) 0000 004F : 32 2E 37 2E 32 2E 31 00 | 00 47 43 43 3A 20 28 47 2.7.2.1..GCC: (G 0000 0050 : 4E 55 29 20 32 2E 37 2E | 32 2E 31 00 00 47 43 43 NU) 2.7.2.1..GCC 0000 0051 : 3A 20 28 47 4E 55 29 20 | 32 2E 37 2E 32 2E 31 00 : (GNU) 2.7.2.1. 0000 0052 : 00 47 43 43 3A 20 28 47 | 4E 55 29 20 32 2E 37 2E .GCC: (GNU) 2.7. 0000 0053 : 32 2E 31 00 08 00 00 00 | 00 00 00 00 01 00 00 00 2.1............. 0000 0054 : 30 31 2E 30 31 00 00 00 | 08 00 00 00 00 00 00 00 01.01........... 0000 0055 : 01 00 00 00 30 31 2E 30 | 31 00 00 00 08 00 00 00 ....01.01....... 0000 0056 : 00 00 00 00 01 00 00 00 | 30 31 2E 30 31 00 00 00 ........01.01... 0000 0057 : 08 00 00 00 00 00 00 00 | 01 00 00 00 30 31 2E 30 ............01.0 0000 0058 : 31 00 00 00 00 2E 73 79 | 6D 74 61 62 00 2E 73 74 1.....symtab..st 0000 0059 : 72 74 61 62 00 2E 73 68 | 73 74 72 74 61 62 00 2E rtab..shstrtab.. 0000 005A : 69 6E 74 65 72 70 00 2E | 68 61 73 68 00 2E 64 79 interp..hash..dy 0000 005B : 6E 73 79 6D 00 2E 64 79 | 6E 73 74 72 00 2E 72 65 nsym..dynstr..re 0000 005C : 6C 2E 70 6C 74 00 2E 69 | 6E 69 74 00 2E 70 6C 74 l.plt..init..plt 0000 005D : 00 2E 74 65 78 74 00 2E | 66 69 6E 69 00 2E 72 6F ..text..fini..ro 0000 005E : 64 61 74 61 00 2E 64 61 | 74 61 00 2E 63 74 6F 72 data..data..ctor 0000 005F : 73 00 2E 64 74 6F 72 73 | 00 2E 67 6F 74 00 2E 64 s..dtors..got..d 0000 0060 : 79 6E 61 6D 69 63 00 2E | 62 73 73 00 2E 63 6F 6D ynamic..bss..com 0000 0061 : 6D 65 6E 74 00 2E 6E 6F | 74 65 00 00 00 00 00 00 ment..note...... 0000 0062 : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 0063 : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 0064 : 00 00 00 00 1B 00 00 00 | 01 00 00 00 02 00 00 00 ................ 0000 0065 : D4 80 04 08 D4 00 00 00 | 19 00 00 00 00 00 00 00 ................ 0000 0066 : 00 00 00 00 01 00 00 00 | 00 00 00 00 23 00 00 00 ............#... 0000 0067 : 05 00 00 00 02 00 00 00 | F0 80 04 08 F0 00 00 00 ................ 0000 0068 : 4C 00 00 00 03 00 00 00 | 00 00 00 00 04 00 00 00 L............... 0000 0069 : 04 00 00 00 29 00 00 00 | 0B 00 00 00 02 00 00 00 ....)........... 0000 006A : 3C 81 04 08 3C 01 00 00 | E0 00 00 00 04 00 00 00 <...<........... 0000 006B : 01 00 00 00 04 00 00 00 | 10 00 00 00 31 00 00 00 ............1... 0000 006C : 03 00 00 00 02 00 00 00 | 1C 82 04 08 1C 02 00 00 ................ 0000 006D : 78 00 00 00 00 00 00 00 | 00 00 00 00 01 00 00 00 x............... 0000 006E : 00 00 00 00 39 00 00 00 | 09 00 00 00 02 00 00 00 ....9........... 0000 006F : 94 82 04 08 94 02 00 00 | 10 00 00 00 03 00 00 00 ................ 0000 0070 : 07 00 00 00 04 00 00 00 | 08 00 00 00 42 00 00 00 ............B... 0000 0071 : 01 00 00 00 06 00 00 00 | A4 82 04 08 A4 02 00 00 ................ 0000 0072 : 06 00 00 00 00 00 00 00 | 00 00 00 00 04 00 00 00 ................ 0000 0073 : 00 00 00 00 48 00 00 00 | 01 00 00 00 06 00 00 00 ....H........... 0000 0074 : AC 82 04 08 AC 02 00 00 | 30 00 00 00 00 00 00 00 ........0....... 0000 0075 : 00 00 00 00 04 00 00 00 | 04 00 00 00 4D 00 00 00 ............M... 0000 0076 : 01 00 00 00 06 00 00 00 | DC 82 04 08 DC 02 00 00 ................ 0000 0077 : E4 00 00 00 00 00 00 00 | 00 00 00 00 04 00 00 00 ................ 0000 0078 : 00 00 00 00 53 00 00 00 | 01 00 00 00 06 00 00 00 ....S........... 0000 0079 : C0 83 04 08 C0 03 00 00 | 06 00 00 00 00 00 00 00 ................ 0000 007A : 00 00 00 00 04 00 00 00 | 00 00 00 00 59 00 00 00 ............Y... 0000 007B : 01 00 00 00 02 00 00 00 | C6 83 04 08 C6 03 00 00 ................ 0000 007C : 01 00 00 00 00 00 00 00 | 00 00 00 00 01 00 00 00 ................ 0000 007D : 00 00 00 00 61 00 00 00 | 01 00 00 00 03 00 00 00 ....a........... 0000 007E : C8 93 04 08 C8 03 00 00 | 88 00 00 00 00 00 00 00 ................ 0000 007F : 00 00 00 00 04 00 00 00 | 00 00 00 00 67 00 00 00 ............g... 0000 0080 : 01 00 00 00 03 00 00 00 | 50 94 04 08 50 04 00 00 ........P...P... 0000 0081 : 08 00 00 00 00 00 00 00 | 00 00 00 00 04 00 00 00 ................ 0000 0082 : 00 00 00 00 6E 00 00 00 | 01 00 00 00 03 00 00 00 ....n........... 0000 0083 : 58 94 04 08 58 04 00 00 | 08 00 00 00 00 00 00 00 X...X........... 0000 0084 : 00 00 00 00 04 00 00 00 | 00 00 00 00 75 00 00 00 ............u... 0000 0085 : 01 00 00 00 03 00 00 00 | 60 94 04 08 60 04 00 00 ........`...`... 0000 0086 : 14 00 00 00 00 00 00 00 | 00 00 00 00 04 00 00 00 ................ 0000 0087 : 04 00 00 00 7A 00 00 00 | 06 00 00 00 03 00 00 00 ....z........... 0000 0088 : 74 94 04 08 74 04 00 00 | 70 00 00 00 04 00 00 00 t...t...p....... 0000 0089 : 00 00 00 00 04 00 00 00 | 08 00 00 00 83 00 00 00 ................ 0000 008A : 08 00 00 00 03 00 00 00 | E4 94 04 08 E4 04 00 00 ................ 0000 008B : 04 00 00 00 00 00 00 00 | 00 00 00 00 04 00 00 00 ................ 0000 008C : 00 00 00 00 88 00 00 00 | 01 00 00 00 00 00 00 00 ................ 0000 008D : 00 00 00 00 E4 04 00 00 | 50 00 00 00 00 00 00 00 ........P....... 0000 008E : 00 00 00 00 01 00 00 00 | 00 00 00 00 91 00 00 00 ................ 0000 008F : 07 00 00 00 00 00 00 00 | 50 00 00 00 34 05 00 00 ........P...4... 0000 0090 : 50 00 00 00 00 00 00 00 | 00 00 00 00 01 00 00 00 P............... 0000 0091 : 00 00 00 00 11 00 00 00 | 03 00 00 00 00 00 00 00 ................ 0000 0092 : 00 00 00 00 84 05 00 00 | 97 00 00 00 00 00 00 00 ................ 0000 0093 : 00 00 00 00 01 00 00 00 | 00 00 00 00 ............ |
This is taken from version 3.1 of FreeBSD. In other versions the hex dump may be slightly different.
There seems to be a lot of unnecessary information. For example, the GCC (GNU) 2.7.2.1
string appears 4 times, so does the 01.01
string and the NUL
bytes that follow it. Moreover, it is dynamically linked with /usr/libexec/ld-elf.so.1 and libc.so.3.
Clearly, it does more work than is necessary: It sets up the environ
variable, it calls the atexit()
function, it sets the __progname
variable... All completely unnecessary.
Now let us write our own version, in assembly language.
section .text global _start _start: sub eax, eax push eax push eax inc eax int 80h |
Note that I did not bother to include a copyright notice: I think it would be ridiculous for something as simple as that.
Anyway, let us assemble and link it. Let us also create a list file so we can see how much of the executable is our code, and how much is the overhead of the ELF file format:
% nasm -f elf true.asm -l true.lst % ld -s -o true true.o % ./true % ls -la true -rwxr-xr-x 1 root wheel 356 Dec 13 19:52 true |
The file is 356 bytes long, as opposed to 2,364. Let us take a look at the listing:
% cat true.lst 1 section .text 2 global _start 3 _start: 4 00000000 29C0 sub eax, eax 5 00000002 50 push eax 6 00000003 50 push eax 7 00000004 40 inc eax 8 00000005 CD80 int 80h 9 |
Ah, yes, our code is a whopping 7 bytes in size. So, why is the file 356 bytes long? Part of it is the ELF structure, the rest of it is compliments of nasm:
0000 0000 : 7F 45 4C 46 01 01 01 00 | 46 72 65 65 42 53 44 00 .ELF....FreeBSD. 0000 0001 : 02 00 03 00 01 00 00 00 | 74 80 04 08 34 00 00 00 ........t...4... 0000 0002 : C4 00 00 00 00 00 00 00 | 34 00 20 00 01 00 28 00 ........4. ...(. 0000 0003 : 04 00 03 00 01 00 00 00 | 00 00 00 00 00 80 04 08 ................ 0000 0004 : 00 80 04 08 7B 00 00 00 | 7B 00 00 00 04 00 00 00 ....{...{....... 0000 0005 : 00 10 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 0006 : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 0007 : 00 00 00 00 29 C0 50 50 | 40 CD 80 00 54 68 65 20 ....).PP@...The 0000 0008 : 4E 65 74 77 69 64 65 20 | 41 73 73 65 6D 62 6C 65 Netwide Assemble 0000 0009 : 72 20 30 2E 39 38 00 00 | 2E 73 79 6D 74 61 62 00 r 0.98...symtab. 0000 000A : 2E 73 74 72 74 61 62 00 | 2E 73 68 73 74 72 74 61 .strtab..shstrta 0000 000B : 62 00 2E 63 6F 6D 6D 65 | 6E 74 00 2E 74 65 78 74 b..comment..text 0000 000C : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 000D : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 000E : 00 00 00 00 00 00 00 00 | 00 00 00 00 1B 00 00 00 ................ 0000 000F : 01 00 00 00 00 00 00 00 | 00 00 00 00 7B 00 00 00 ............{... 0000 0010 : 1C 00 00 00 00 00 00 00 | 00 00 00 00 01 00 00 00 ................ 0000 0011 : 00 00 00 00 24 00 00 00 | 01 00 00 00 02 00 00 00 ....$........... 0000 0012 : 74 80 04 08 74 00 00 00 | 07 00 00 00 00 00 00 00 t...t........... 0000 0013 : 00 00 00 00 01 00 00 00 | 00 00 00 00 11 00 00 00 ................ 0000 0014 : 03 00 00 00 00 00 00 00 | 00 00 00 00 97 00 00 00 ................ 0000 0015 : 2A 00 00 00 00 00 00 00 | 00 00 00 00 01 00 00 00 *............... 0000 0016 : 00 00 00 00 .... |
Ah, yes, the nasm comment is bigger than all of our code.
Luckily, we can get rid of it with strip:
% strip -R .comment true |
Now we are down to 276 bytes:
0000 0000 : 7F 45 4C 46 01 01 01 00 | 46 72 65 65 42 53 44 00 .ELF....FreeBSD. 0000 0001 : 02 00 03 00 01 00 00 00 | 74 80 04 08 34 00 00 00 ........t...4... 0000 0002 : 9C 00 00 00 00 00 00 00 | 34 00 20 00 01 00 28 00 ........4. ...(. 0000 0003 : 03 00 02 00 01 00 00 00 | 00 00 00 00 00 80 04 08 ................ 0000 0004 : 00 80 04 08 7B 00 00 00 | 7B 00 00 00 04 00 00 00 ....{...{....... 0000 0005 : 00 10 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 0006 : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 0007 : 00 00 00 00 29 C0 50 50 | 40 CD 80 00 2E 73 79 6D ....).PP@....sym 0000 0008 : 74 61 62 00 2E 73 74 72 | 74 61 62 00 2E 73 68 73 tab..strtab..shs 0000 0009 : 74 72 74 61 62 00 2E 74 | 65 78 74 00 00 00 00 00 trtab..text..... 0000 000A : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 000B : 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 ................ 0000 000C : 00 00 00 00 1B 00 00 00 | 01 00 00 00 02 00 00 00 ................ 0000 000D : 74 80 04 08 74 00 00 00 | 07 00 00 00 00 00 00 00 t...t........... 0000 000E : 00 00 00 00 01 00 00 00 | 00 00 00 00 11 00 00 00 ................ 0000 000F : 03 00 00 00 00 00 00 00 | 00 00 00 00 7B 00 00 00 ............{... 0000 0010 : 21 00 00 00 00 00 00 00 | 00 00 00 00 01 00 00 00 !............... 0000 0011 : 00 00 00 00 .... |
Incidentally, we can implement false with the same seven bytes: We just have to move the inc eax
two lines up:
section .text global _start _start: sub eax, eax inc eax push eax push eax int 80h |
If you wish, you can also get this code on a nice T-shirt. Not only will you get to wear it everywhere, you will also help support int80h.org.
Copyright © 2000 G. Adam Stanislav.
All rights reserved.