PPK debuts the tiny programming challenge
kernelistic writes "Looks like the great folks at properkernel.com are running a developer challenge. They're looking for smallest executables that match the posted criteria. The rules look fairly straightforward. Anyone up for some fun?"
They don't say which platform it must run on. FreeBSD with Linux emulation? What architecture - i386? And are we writing for FreeBSD or Linux syscalls?
Looks like they want a binary similar to the one described in A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux , except it has to print text and not just return 42.
If only I had some spare time to play along at home...
Why is this challenge interesting?
Hang on a sec .. they say they'll accept Linux syscalls being used, but to call them you need to use the 'fastcall' approach, that is, put your arguments in the registers and run an interrupt (int 0x80 in Linux.)
But rule 3 states that you have to use a stack-based approach, no fastcall allowed! Wtf?
Just for comparison's sake, the quick'n'dirty approach:
main()
{
char *msg = "The deep gray mouse runs after the holy yellow cheese.\n";
write(1, msg, 56);
}
produces, stripped, a 3200 byte binary -- too big to qualify by 700 bytes.
-- Alastair
We're looking for the smallest binary that will accomplish the task at hand without causing any problems or crashes. We'll be testing the binary out on a FreeBSD machine using native FreeBSD, SVR4 and Linux ABI support. Entries using either Linux or FreeBSD syscalls will be accepted.
FreeBSD only runs on i386 and Alpha. FreeBSD's Linux ABI support only emulates i386. I think that narrows things down a little.
- 3. Uses a stack-based approach (ie. No fastcall binaries!).
has changed to:- 3. Uses a stack-based approach (ie. Preferably no fastcall binaries).
And: - ... as long as the output is a valid ELF image.
has changed to:- as long as the output is a valid x86 ELF image.
Also they added:- Hate bloatware? This is your chance to show it!
for some reason. Probably a slur against Microsoft, knowing what this lot is like.They dont say you can link to a library, so you make a big fat library and link to it.
The binayr is still elf etc etc.
The catch? I did it in 5,038 bytes, including a nifty color icon.
Beat that.
TANSTAAFI: There Ain't No Such Thing As A Free iPod.
Learn to spell, you pitiful excuse for a wankshaft monkey. It's "wasted", not "waisted".
For fuck's sake, can you not even get a first post right? Jesus fucking Christ! I pity you.
At least they've chosen a challenge with practical implications.
Submit a kernel patch that prints the stuff about the mouse on a certain syscall.
ASM
mov eax 0xbaadca11
syscall
ret
8 bytes. I win.
justin@joker:~/tmp[1]$ cat small.s
./small
:P
; Justin White
; http://properkernel.com/tiny/ entry
%define STDOUT 0
%define SYS_exit 1
%define SYS_write 4
section data
msg db "The deep gray mouse runs after the holy yellow cheese.", 0x0A
msg_size equ $-msg
section text
global _start
_start:
; write
push dword msg_size
push dword msg
push dword STDOUT
mov eax, SYS_write
push eax
int 0x80
; exit
push dword 0
mov eax, SYS_exit
push eax
int 0x80
; end _start
;EOF
justin@joker:~/tmp[0]$ nasm -f elf small.s
justin@joker:~/tmp[0]$ ld -x -s -o small -nostdlib --stats small.o
/usr/libexec/elf/ld: total time in link: 0.006606
/usr/libexec/elf/ld: data size 184328
justin@joker:~/tmp[0]$ ll small
-rwxrwxr-x 1 justin justin 516 Nov 25 03:22 small*
justin@joker:~/tmp[0]$
The deep gray mouse runs after the holy yellow cheese.
justin@joker:~/tmp[0]$
that's using FreeBSD kernel calls.
that's the smallest it'll be without doing ELF header tweaking like in that tiny binary tutorial.
actually, can save like 8 bytes by using just AL and not all of EAX to hold the syscall numbers.
now, if they said, do it without using the kernel, that would have been a challenge
--Justin
Smallest Possible ELF Executable?
The answer was 45 bytes, but probably don't fulfill the criterias set in this challenge.
Beware: In C++, your friends can see your privates!
I've managed to tweak a solution down to 99 bytes. Hows that?
I have just discovered a 35 byte solution.
Unfortunately, the source is too long to give here.
[krakrjak@krakrjak tinyASM]$ cat waaytiny.asm ./itstiny
; For entry in http://properkernel.com/tiny/entry
; Zac Slade
; waaaytiny.asm
BITS 32
org 00001000h
db 7Fh, 'ELF'
dd 1
dd 0
dd WW
dw 3
dd filesize
dd _start
dd 4
_start:
xor ebx, ebx
inc ebx
xor edx, edx
jmp short Contin
db 0
dw 34h
dw 20h
dw 1 PLEASELETMEPOSTMYCODE
dw 0 I'MASKINGNICELY
dw 0
dw 0
StrLen EQU 55
Strng db 'The deep gray mouse runs after the holy yellow cheese.', 0Ah
Contin: mov Dl, StrLen
xor eax, eax
xor al, 4
mov ecx, Strng
intsta: int 80h
xchg eax, ebx
jmp short intsta
filesize EQU W - WW
[krakrjak@krakrjak tinyASM]$ nasm -f bin -o itstiny waaytiny.asm
[krakrjak@krakrjak tinyASM]$ ll itstiny
-rw-rw-r-- 1 krakrjak krakrjak 123 Nov 27 10:58 itstiny
[krakrjak@krakrjak tinyASM]$ chmod +x itstiny
[krakrjak@krakrjak tinyASM]$
The deep gray mouse runs after the holy yellow cheese.
[krakrjak@krakrjak tinyASM]$
There's My entry. Maybe someone else's entry is better than that but I'm hard pressed to get any better than that. That is using fastcalls, but it get's the job done.
Stupid lameness filter.... I'll just ramble and see if it'll let me in...
Perhaps maybe the Dollar Signs. I'll replace those with the letter W. Now the compression Filter. That's okay another paragraph here outta do it. I've taken most tabs and also added some CAPS stuff to get through the Filter.
Has anyone heard of a better way for this one yet. Someone told me they had it smaller but they wouldn't show me how. Maybe if you can use some of the characters in the string as instructions then maybe it's possible to get some of it done that way. The only real problem is jumping into memory takes space too and doesn't save anything if you only execute one instruction.