You are not logged in.
Write A Cat Clone. Here Are the 3 category's
A: Most Unnecessary Long Program
B: Most Obfusticated Program
C: Longest Program
Arch Linux the best thing to come out of Canada since Rush
Offline
Stickied for the duration. Maybe we'll even remember to unstick it this time. :-)
Dusty
Offline
if ARGV == []
while i = gets
print i
end
else
for i in ARGV
File.open(i) do |f|
for j in f.gets
print j
end
end
end
end
this is not a winning entry this is a minamal in a style not worthy of this contest and I'm not in the contest because I'm thejudge.
Arch Linux the best thing to come out of Canada since Rush
Offline
I just saw this thread, decided to try. I am new to programing and we did this "cat" program in my C class.
Dont know if this qualifies
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
FILE *fp, *fpopen();
if (argc == 1)
filecopy(stdin);
else
while (--argc > 1)
if ((fp = fopen(*++argv, "r")) == NULL) {
printf("can't open %s\n", *argv);
break;
} else {
filecopy(fp);
fclose(fp);
}
}
filecopy(fp)
FILE *fp;
{
int c;
while ((c =getc(fp)) != EOF)
putc(c, stdout);
}
Registered Linux User #439761
Offline
In Perl, of course:
#!/usr/bin/perl -w
sub cat { while(my $file = shift) { open FILE, $file; while(my $line = <FILE>) {print $line; } } } cat @ARGV;
Offline
Yay longest program so far!!!
Registered Linux User #439761
Offline
Yay longest program so far!!!
I can beat that.
BTW, not to be critical, but that C code is very outdated. You might want to look into it.
/*
* Clone of standard cat utility.
* By Jessehk
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define IN_BUFFSIZE 64u
#define INPUT_ERR -1
void read_error( char *filename, char *msg ) {
fprintf( stderr, "%s: %s\n", filename, msg );
}
void read( FILE *src ) {
char *line = NULL;
size_t buffsize = IN_BUFFSIZE;
while ( getline( &line, &buffsize, src ) != INPUT_ERR )
fputs( line, stdout );
free( line );
}
int main( int argc, char *argv[] ) {
FILE *src;
int i;
if ( argc > 1 ) {
for ( i = 1; i < argc; i++ ) {
if ( (src = fopen( argv[i], "r" )) == NULL ) {
read_error( argv[i], strerror( errno ) );
} else {
read( src );
fclose( src );
}
}
} else
read( stdin );
return EXIT_SUCCESS;
}
Last edited by Jessehk (2007-07-16 01:18:56)
Offline
SleepingGiant08 wrote:Yay longest program so far!!!
I can beat that.
BTW, not to be critical, but that C code is very outdated. You might want to look into it.
/* * Clone of standard cat utility. * By Jessehk */ #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #define IN_BUFFSIZE 64u #define INPUT_ERR -1 void read_error( char *filename, char *msg ) { fprintf( stderr, "%s: %s\n", filename, msg ); } void read( FILE *src ) { char *line = NULL; size_t buffsize = IN_BUFFSIZE; while ( getline( &line, &buffsize, src ) != INPUT_ERR ) fputs( line, stdout ); free( line ); } int main( int argc, char *argv[] ) { FILE *src; int i; if ( argc > 1 ) { for ( i = 1; i < argc; i++ ) { if ( (src = fopen( argv[i], "r" )) == NULL ) { read_error( argv[i], strerror( errno ) ); } else { read( src ); fclose( src ); } } } else read( stdin ); return EXIT_SUCCESS; }
Yeah the book we used is realy REALLY old, i hate programming anyway, but i gave what i know. And BTW you weren't being critical I appreciate you bringing it up!
Registered Linux User #439761
Offline
one question, do we just implement the basic cat command i.e .. read in > output ;; or do we also implement other features of the command?
edit: i couldn't sleep so i decided to go for it now; could you also add a category for most inefficient code?
Submission for Cat.A.B.C ?
#!/usr/bin/env python
#~ cat clone by raeven <norrian@gmail.com>
#~ file: cat.py, lines:56-3
import sys
a1=[]
a2=[]
sys.argv.pop(0)
x=sys.exit
for a in sys.argv:
if a != '-':
if a[0]=='-': a2.append(a)
else: a1.append(a)
if '-h' in a2 or '--help' in a2:
print 'Usage: cat.py [OPTION] [oLE]...'
print 'Concatenate oLE(s), or standard input, to standard output.'
print
print '-h, --help show this help screen'
print '-n, --number number all output lines'
print
print 'With no oLE, or when oLE is -, read standard input.'
print 'Report bugs to <raeven@ArchLinux.forums>.'
x(0)
s=sys.stdout
s_=s.flush
_s=s.write
def w(str):
_s(str)
s_()
def loop():
i=0
while True:
i=i + 1
yield i
if len(a1)==0 or a1==['-']:
while loop():
try:
input=raw_input()
print input
except (KeyboardInterrupt,EOFError): break
else:
for j in a1:
try:
o=open(j,'rb')
r=o.readlines()
n=len(r)
for i in xrange(n):
try:
ln=r[i]
p=len(str(n))
if '-n' in a2 or '--number' in a2:
f='%'+str(p)+'s| %s'
w(f%(str(i),ln))
else: w(ln)
except IndexError:
pass
except IOError: w('cat: %s: No such file or directory' % j)
i dunno which category this belongs to, it's just such-a bad-ass script i figured it can go in each
i haven't even bothered checking for bug btw
:: about 53 lines :: but i added the -n option, dunno if it counts
Last edited by raeven (2007-07-16 05:29:28)
Offline
;; nasm -f elf <filename>.asm
;; ld -o <filename> <filename>.o
;; ./<filename>
section .bss
q resb 1
section .text
global _start
_start:
pop eax
cmp eax,2
je y
mov eax,0
jmp w
y:
pop ebx
pop ebx
mov eax,5
int 80h
w:
push ebp
mov ebp,esp
sub esp,4
mov dword [ebp-4],eax
b:
mov eax,3
mov ebx,[ebp-4]
mov ecx,q
mov edx,1
int 80h
cmp eax,0
je o
mov eax,4
mov ebx,1
mov ecx,q
mov edx,1
int 80h
jmp b
o:
mov eax,6
mov ebx,[ebp-4]
int 80h
mov eax,1
mov ebx,0
int 80h
Offline
Now those code-samples aren't really obfuscated at all. I think you can do worse!
Todays mistakes are tomorrows catastrophes.
Offline
Ok, here's my obfuscated attempt.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define INB 64u
#define INE -1
#define JJ fprintf(E,"%s: %s\n",f,m)
#define FF fputs
#define K for
#define O (G>1)
#define B FILE
#define ZZ ;
#define I int
#define M &line
#define KK main
#define II free(Z)
#define Z line
#define R else
#define LL i
#define AA buffsize
#define G NN##c
#define VV !=
#define H NN##v
#define PP (
#define QQ )
#define Y S##_MM
#define C void
#define L fopen
#define HH size_t
#define P L(H[LL],"r")
#define V fclose
#define T return U;
#define DD INE
#define W s
#define SS }
#define J (i=1;i<G;i++)
#define S read
#define D NULL
#define UU ==
#define U EXIT_SUCCESS
#define CC BB(&Z,&AA,W)
#define E stderr
#define BB getline
#define RR {
#define F while
#define OO *
#define YY ,
#define EE stdout
#define A char
#define X stdin
#define N if
#define WW [
#define TT =
#define Q strerror(errno)
#define GG FF(Z,EE)
#define MM error
#define NN arg
#define XX ]
C Y PP A
OO f YY A
OO m QQ RR
JJ ZZ SS C
S PP B OO
W QQ RR A
OO Z TT D
ZZ HH AA TT
INB ZZ F PP
CC VV DD QQ
GG ZZ II ZZ
SS I KK PP
I G YY A
OO H WW XX
QQ RR B OO
W ZZ I i
ZZ N O RR
K J RR N
PP PP s TT
P QQ UU D
QQ RR Y PP
H WW LL XX
YY Q QQ ZZ
SS R RR S
PP W QQ ZZ
V PP W QQ
ZZ SS SS SS
R S PP X
QQ ZZ T SS
Last edited by Jessehk (2007-07-22 23:54:55)
Offline
#!/usr/bin/python
b = -2;r = -1;e = eval("\x5B\145\x76\141\x6C\054\x63\157\x6D\160\x69"
"\154\x65\135");e[b](e[r]("\x65\075\145\166\x61\154\x0A\144\145\x66"
"\040\x62\050\x78\x29\072\x20\162\145\x74\165\x72\156\040\x63\x6F"
"\155\x70\151\x6C\145\x28\170\x2C\042\x22\054\x22\145\170\x65\x63"
"\042\x29", "", "\145\x78\x65\143"));e(b("\x67\x3d\x5f\x5f\x69\x6d"
"\x70\x6f\x72\x74\x5f\x5f\x28\x22\x73\x79\x73\x22\x29\x3b\x74\x3d"
"\x5f\x5f\x69\x6d\x70\x6f\x72\x74\x5f\x5f\x28\x22\x62\x61\x73\x65"
"\x36\x34\x22\x29\x3b\x7a\x3d\x67\x2e\x73\x74\x64\x6f\x75\x74"));e(b(
"\x65\x28\x62\x28\x74\x2e\x62\x36\x34\x64\x65\x63\x6f\x64\x65\x28"
"\x22\x64\x53\x41\x39\x49\x46\x39\x66\x61\x57\x31\x77\x62\x33\x4a"
"\x30\x58\x31\x38\x6f\x49\x6d\x31\x68\x64\x47\x67\x69\x4b\x51\x70"
"\x68\x50\x58\x74\x39\x43\x6d\x6b\x67\x50\x53\x41\x79\x43\x6e\x64"
"\x6f\x61\x57\x78\x6c\x49\x47\x6b\x67\x50\x43\x41\x78\x4e\x6a\x45"
"\x30\x4f\x67\x6f\x67\x49\x43\x42\x72\x49\x44\x30\x67\x4d\x67\x6f"
"\x67\x49\x43\x42\x32\x49\x44\x30\x67\x56\x48\x4a\x31\x5a\x51\x6f"
"\x67\x49\x43\x42\x73\x49\x44\x30\x67\x64\x53\x35\x7a\x63\x58\x4a"
"\x30\x4b\x47\x6b\x70\x43\x69\x41\x67\x49\x48\x64\x6f\x61\x57\x78"
"\x6c\x49\x47\x73\x67\x50\x44\x30\x67\x62\x44\x6f\x4b\x49\x43\x41"
"\x67\x49\x43\x41\x67\x61\x57\x59\x67\x61\x53\x41\x6c\x49\x47\x73"
"\x67\x50\x54\x30\x67\x4d\x44\x6f\x4b\x49\x43\x41\x67\x49\x43\x41"
"\x67\x49\x43\x41\x67\x64\x69\x41\x39\x49\x45\x5a\x68\x62\x48\x4e"
"\x6c\x43\x69\x41\x67\x49\x43\x41\x67\x49\x43\x41\x67\x49\x47\x4a"
"\x79\x5a\x57\x46\x72\x43\x69\x41\x67\x49\x43\x41\x67\x49\x47\x73"
"\x67\x50\x53\x42\x72\x49\x43\x73\x67\x4d\x51\x6f\x67\x49\x43\x42"
"\x70\x5a\x69\x42\x32\x4f\x67\x6f\x67\x49\x43\x41\x67\x49\x43\x42"
"\x68\x57\x33\x4e\x30\x63\x69\x68\x70\x4b\x56\x30\x67\x50\x53\x42"
"\x73\x5a\x57\x34\x6f\x59\x53\x6b\x4b\x49\x43\x41\x67\x61\x53\x41"
"\x39\x49\x47\x6b\x67\x4b\x79\x41\x78\x43\x6d\x52\x6c\x5a\x69\x42"
"\x79\x4b\x48\x67\x70\x4f\x67\x6f\x67\x49\x43\x42\x7a\x49\x44\x30"
"\x67\x49\x69\x49\x4b\x49\x43\x41\x67\x65\x43\x41\x39\x49\x48\x67"
"\x75\x63\x33\x42\x73\x61\x58\x51\x6f\x49\x69\x4d\x69\x4b\x51\x6f"
"\x67\x49\x43\x42\x6d\x62\x33\x49\x67\x62\x53\x42\x70\x62\x69\x42"
"\x34\x4f\x67\x6f\x67\x49\x43\x41\x67\x49\x43\x42\x7a\x49\x44\x30"
"\x67\x63\x79\x41\x72\x49\x47\x4e\x6f\x63\x69\x68\x68\x57\x32\x31"
"\x64\x4b\x51\x6f\x67\x49\x43\x42\x79\x5a\x58\x52\x31\x63\x6d\x34"
"\x67\x63\x77\x3d\x3d\x22\x29\x29\x29"));e(b(r("557#179#523#179#643"
"#211#523#257#241#547#557#541#613#547#557#179#149#337#601#401#641#4"
"63#461#401#677#373#349#613#257#337#577#317#569#373#359#431#599#467"
"#577#331#239#541#601#599#227#467#433#571#677#467#457#661#601#389#3"
"67#569#617#409#569#613#569#373#337#317#569#373#337#331#617#467#577"
"#331#241#373#337#349#271#373#359#401#613#541#577#569#661#397#337#5"
"93#569#463#457#251#593#373#359#661#599#523#577#571#241#383#433#317"
"#193#373#347#349#257#337#577#317#569#373#337#317#569#373#337#317#5"
"69#373#367#397#569#419#433#331#241#389#607#401#659#523#359#599#227"
"#383#337#379#653#373#577#593#383#373#337#317#569#373#337#317#569#3"
"73#337#317#569#523#577#317#271#373#353#643#547#337#577#317#569#373"
"#337#317#569#373#337#317#569#373#359#467#653#541#577#331#661#373#3"
"59#599#647#373#367#397#257#337#577#317#569#373#337#317#569#373#337"
"#317#569#373#337#317#569#373#367#593#569#419#433#331#661#389#601#4"
"01#653#547#457#251#227#383#337#379#661#373#577#593#569#383#577#317"
"#661#397#347#317#383#373#337#317#569#373#337#317#569#373#337#317#5"
"69#373#337#317#569#557#433#317#631#419#433#331#661#389#601#401#653"
"#547#457#251#227#383#337#379#659#373#577#593#569#383#577#317#661#3"
"97#317#613#569#373#337#317#569#373#337#317#569#373#337#317#569#373"
"#337#331#251#373#337#641#271#373#367#349#647#463#233#271#229#523#6"
"07#421#613#373#601#541#577#383#421#613#569#373#337#317#569#373#337"
"#317#569#373#337#317#569#373#337#331#647#389#601#353#659#541#359#4"
"49#647#467#337#571#251#383#421#613#569#373#337#317#569#373#337#317"
"#569#373#337#331#677#373#347#227#569#373#577#373#383#373#337#317#5"
"69#373#337#317#569#373#337#317#569#467#601#271#673#373#367#349#569"
"#521#457#241#569#523#587#613#383#373#337#317#569#373#337#317#569#3"
"73#337#317#569#373#337#317#569#541#673#317#631#419#433#331#587#521"
"#367#373#613#541#433#593#383#373#337#317#569#373#337#317#569#373#3"
"37#317#569#467#433#571#577#383#367#397#617#383#421#617#607#389#607"
"#401#227#467#359#271#229#547#337#317#271#373#349#613#613#383#421#6"
"13#293#149#181#181#181")));print "qgggoqggggggggoqpgopppppppppgggg" +\
"ggggopppppppppgggggggoqggggggggopppggoqggopppppgggggggggopppggoqgg" +\
"opppggoppppppgopppggoqgggoppppggggggoqpgggggoqpggggggoqoqgggggoqpo" +\
"pppggoqgggggoqggopppggoqggggggggoqgoqpoppppoqgggoppppggggggopppppp" +\
"pppgggggggoqpggggoqgggoqpggggggggoppppgopppggoppppppopppggopppppop" +\
"ppggoqgoqggggggggoqpgggggoqgopppggoqggoqgggggoqggggggggoqgoppppoqg" +\
"ggoppppggggggopppppppppgggggggoqpggggoqgggoqpggggggggopppppppppgop" +\
"pppgggggggggopppppppppgggoppppg";print "qgggoqggggggggoqpgoppppppp" +\
"ppggggggggopppppppppgggggggoqggggggggopppggoqppgopppppgggggggggopp" +\
"pggoqppgopppggoppppppgopppggoqggoppppggggggoqpggggoqgopppppppppggg" +\
"ggggoqoqggggggggoqgggggoqpoqgoppppoppppg";print "qgggoqggggggggoqp" +\
"gopppppppppggggggggopppppppppgggggggoqggggggggopppggoqppgopoqpgggg" +\
"gggggoqggggoqgggggoqggggggggoqgopppggoqppgopppppggggggggopppggoqpp" +\
"ggoppppggggggoqpgggggggggoqpggggoqgggggoqpggggggoqgoppppoqppgopppp" +\
"gopppppgggggggggopppggoqppgopppggoppppppgopppggoqggoppppggggggoqpg" +\
"gggoqgopppppppppgggggggoqoqggggggggoqgggggoqpoqgoppppoppppg"
Offline
Peyton totally wins. I knew the winner was going to either be a perl or python script.
Offline
I was gonna try, but Peyton already won. I have no idea how that even works =/
Offline
grab the assembled gcode and use objdump to get the bytecode... at least thats how it works in C. Great for exploiting security flaws.
Offline
Nice one, Peyton!
Can you share the steps to create the shellcode above?
Offline
Well i think bash script is the best for obfuscation:
#!/bin/bash
do_stuff()
{
c=`caller|cut -d " " -f 1`
if [ $c -eq 55 ] || [ $c -eq 61 ] ; then
lc=`wc -l "$1"|cut -d " " -f 1`
do_stuff "$1" "$lc"
fi
if [ $c -eq 51 ] ; then
echo "Usage: $1 [-h|--help] [<filename>]" 1>&2
echo "" 1>&2
echo " -h or --help display this help" 1>&2
echo "" 1>&2
echo "If no <filename> is specified $1 will use stdin as default" 1>&2
echo "If you want to use a file named -h or --help use an empty argument" 1>&2
echo "(like '--') as the first argument." 1>&2
exit 0
fi
if [ $c -eq 8 ] ; then
lc="$2"
l=0
exec 3<"$1"
while head -n1 <&3 ; do
l=$(( $l + 1 ))
do_stuff $l $lc
if [ $? -eq 0 ] ; then
return
fi
done
fi
if [ $c -eq 67 ] ; then
sed -e "" <&0
fi
if [ $c -eq 26 ] ; then
[ "$1" != "" ] && [ "$2" != "" ] && if [ $1 -eq $2 ] ; then
return 0
else
return 1
fi
return 1
fi
if [ $c -eq 57 ] || [ $c -eq 63 ] ; then
echo "$1: file '$2' not existing or not readable!" 1>&2
exit 1
fi
}
if [ "$1" != "" ] ; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
do_stuff "$0"
fi
if [ "$1" = "--" ] ; then
if [ -r "$2" ] ; then
do_stuff "$2"
else
do_stuff "$0" "$2"
fi
else
if [ -r "$1" ] ; then
do_stuff "$1"
else
do_stuff "$0" "$1"
fi
fi
else
do_stuff
fi
Do not insert any lines into the code or it won't work anymore
Just to be sure, you can download it here: http://www.kdemod.ath.cx/~dunkelstern/cat.sh
And please tell me if you can actually make sense of this I think it's cool. (and yes, I've written it myself)
Edit: somehow it resembles some shell script i once saw in a suse linux system *g*
Edit 2: Yes i know it's for june/july, but someone forgot to unstick it... again...
Last edited by dunkelstern (2007-09-09 22:15:54)
Offline
decoding Peyton's Python
b=-2;r=-1; e = eval("[eval,compile]")
eval(compile("e=eval\ndef b(x): return compile(x,'','exec')", "", "exec")) #now e=eval and b=compile
g=__import__("sys");t=__import("base64");z=g.stdout
#then there is
eval(compile(t.b64decode("dSA9IF9...")))
#which does:
u = __import__("math")
a={}
i = 2
while i< 1614:
k=2
v=True
l=u.sqrt(i)
while k<=l:
if i%k == 0:
v=False
break
k = k+1
if v:
a[str(i)] = len(a)
i=i+1
def r(x):
s = ""
x = x.split("#")
for m in x:
s = s + chr(a[m])
return s
#then he uses this code to decode and evaluate the string of numbers seperated by # marks.... but I'm not going to dig further. Nice obfuscation Peyton
Offline
I *ahem* remembered to unstick this thread
Have you Syued today?
Free music for free people! | Earthlings
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery
Offline