/main-as-an-array

Simple utility for creating an obfuscated .c-file that prints stuff to stdout

Primary LanguageC

main-as-an-array

Simple utility for creating an obfuscated .c-file that prints stuff to stdout which works by replacing main() with an array of inline assembly calls (mainly to write()).

http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function.html

Usage

$ gcc -Wall main.c -o main
$ ./main "Hello World" > test.c
$ gcc -Wall test.c && ./a.out
test.c:1:12: warning: 'main' is usually a function [-Wmain]
Hello World

Example output

const char main[] = {
  0x55, 0x48, 0x89, 0xE5,
  0xB8, 0x01, 0x00, 0x00,
  0x00, 0xBB, 0x01, 0x00,
  0x00, 0x00, 0x67, 0x8D,
  0x35, 0x10, 0x00, 0x00,
  0x00, 0xBA, 0x1E, 0x00,
  0x00, 0x00, 0x0F, 0x05,
  0xB8, 0x3C, 0x00, 0x00,
  0x00, 0x31, 0xDB, 0x0F,
  0x05, 0x48, 0x65, 0x6C,
  0x6C, 0x6F, 0x20, 0x57,
  0x6F, 0x72, 0x6C, 0x64,
  0x0A, 0x53, 0x53, 0x48,
  0x5F, 0x41, 0x47, 0x45,
  0x4E, 0x65, 0x5F, 0x50,
  0x49, 0x44, 0x3D, 0x31,
  0x34, 0x32, 0x39, 0x05,
  0x0A, 0x5D, 0xCD
};