#!/usr/bin/perl
#
#	'False True' -- An Example of How Not To Write Code
#
#	(c) 1998 Martin Mares <mj@ucw.cz>, GPL'ed
#
# This is an attempt to write a shortest possible program which is still
# useful. I decided to make a replacement for `true' (anyway, `false' would
# fit in the same space as well). It is _NOT_ a correct ELF program (the
# headers are a bit messy and we have non-zero values in reserved fields
# and certain mandatory parts are missing), but `file' still recognizes
# it as ELF (although `objdump' doesn't) and, which is much more important,
# Linux kernel still runs it. Share and enjoy...
#

open X, ">true" or die "No write access, no truth";
while (<DATA>) {
	s/#.*$//; s/\b(\w{4})(\w{4})\b/$2 $1/g; s/\b(\w\w)(\w\w)\b/$2 $1/g;
	foreach $a (split /\s+/) { print X pack("c",hex $a); }
} chmod 0755, "true" or die "Executables aren't";

__END__

7f 45 4c 46			# Identification
01				# We're 32-bit
01				# Little endian
01				# Header version
# Next 9 bytes are ELF header padding and RFU, but we dare to put
# our code into them.
31 c0				# xor eax,eax (offset 9)
40				# inc eax
31 db				# xor ebx,ebx
cd 80				# int 0x80
4d 4a				# Author's Signature :-)
0002				# Type: Executable File
0003				# Machine: i386
00000001			# Version: Current :)
10000007			# Entry point
0000002c			# PH offset
00000000			# SH offset
00000000			# Machine-specific flags
0034				# EH size
0020				# Size of single PH entry
0001				# Number of PH entries
0000				# Size of single SH entry
0000				# Number of SH entries
0000				# String table offset

# Offset 2C: Program Header

# These two entries are overlaid with the ELF header
#00000001			# Type: Loadable
#00000000			# Offset of section start
10000000			# Virtual address
10000000			# Physical address: ignored
0000004c			# File image size
0000004c			# Memory image size
00000007			# Flags: rwx
# Linux doesn't use alignment, so we can omit it. The kernel will try
# to read the full header size and get 4 bytes less, but it won't
# complain and it will use whatever was left in the memory. Ugly.
#00001000			# Align to page size
