IOCCC image by Matt Zucker

The International Obfuscated C Code Contest

2011/fredriksson - Most useful

Author:

To build:

    make

Bugs and (Mis)features:

The current status of this entry is:

STATUS: INABIAF - please DO NOT fix

For more detailed information see 2011/fredriksson in bugs.html.

To use:

    ./fredriksson [-icvtnk#] regexp < file

Try:

    ./try.sh

NOTE: you need to be allowed to change your stack size or else the last command in the script would likely cause the program to dump core, which is why the script checks the exit code of ulimit first.

Judges’ remarks:

The author of this entry was making sure that it does not win the “Best Short Program” award. On the outside, the program behaves as an approximate grep. On the inside, it is a Burrows-Wheeler transform decompressor that produces the source code of the actual obfuscated approximate grep program and calls it. As an exercise, try writing the compressor.

Author’s remarks:

Approximate grep

Implements a variant of grep.

Usage

To search regexp from file, do:

    ./fredriksson [-icvtnk#] regexp < file

Pipes might not work, see the section Limitations. The options -i, -c, -v and -n are the classic ones:

This version of grep recognizes two more options, not present in normal grep implementations:

Of course, one could construct a standard regexp that matches the same patterns, but the problem is that such a regexp grows exponentially in size when the number of allowed edit operations is increased.

This version does not recognize all regular expressions, but the following are allowed:

The special characters must be escaped, if they are to be taken literally (e.g. \. to match period). You might want to protect these with ', i.e. use 'foo\[bar' instead of foo\[bar. If you want to use the literal - in bracket expression, protect that too (\-), otherwise this is not needed. Note that the syntax differs from standard (?) grep a bit, i.e. in plain grep you can use ] and - in bracket expressions by putting ] as the first character, and putting - last.

Other uses

    ./fredriksson -k3 cat < file
    ./fredriksson -nk3 cat < file

Other features

Limitations and remarks

    ulimit -s unlimited

cross your fingers, hope it is enough, and try again.

NOTICE to those who wish for a greater challenge:

If you want a greater challenge, don’t read any further: just try to understand the program via the source.

If you get stuck, come back and read below for additional hints and information.

How this entry works:

    gcc -O3 ag.c -o ag

To change that you need to edit the char array p[] and (possibly) two specially encoded constants, -~('('*'(') and 'C'*' '-'-'. The extracted source (ag.c) is obfuscated as well.

(The original version also deleted the generated source and the corresponding binary after running it, but this feature was removed from the submitted entry.)

    ./fredriksson -ck0 [0-9] < fredriksson.c

This should print 1, as there is a number 3 in the char array (only). You can also try

    ./fredriksson -ck0 [0-9] < ag.c

after running fredriksson at least once (since this generates that ag.c file), and this should print 0.

Inventory for 2011/fredriksson

Primary files

Secondary files


Jump to: top