106 MARCH 2007 | LINUX FOR YOU | www.
linuxforu.
com
C M Y K
CCCCC
ompile this program and run it by giving your name
as the argument.
Now find out how the program
works:
main(int i, char*a[]){char b[]={0x48,0x61,0x70,0x70,0x79,0x20,...
More
106 MARCH 2007 | LINUX FOR YOU | www.
linuxforu.
com
C M Y K
CCCCC
ompile this program and run it by giving your name
as the argument.
Now find out how the program
works:
main(int i, char*a[]){char b[]={0x48,0x61,0x70,0x70,0x79,0x20,
0x62,0x69,0x72,0x74,0x68,0x64,0x61,0x79,0x20,0x74,0x6f,0x20,0x79,0x6f,
0x75,0x0a};while(i+2) printf((!i—)?”%.
15sdear %s\n”:”%s”,b,1[a]);}
Given your name, say, Bala, it wishes you happy birthday:
Happy birthday to you
Happy birthday to you
Happy birthday, dear Bala
Happy birthday to you
That’s nice, isn’t it!
Instead of starting by dissecting the given obfuscated
program, let me start from the original program and
explain how one can arrive at the obfuscated code
(because that’s the way almost all obfuscated programs are
written).
Here is the original program:
const char * str = “Happy birthday to you\n”;
int main(){
const char name[50];
gets (name);
printf(“ %s %s %.
15s%s %s”, str, str, str, name, str);
}
The idea is to print the string “Happy birthda
Less