Browse files

Added a new 64 bit specific op-code buffer in inception.h for the mor…

…ph to work as the 32 bit emulation mode int 0x80 call doesnt work with the opcode translation with x86_64 opcode buffers. So introduced a new one that represents the use of syscall instruction for x86_64. The assembly for that is also encoded in the comments in inception.h . Now a run for 64 bit would also dump Fischers thought in the last line as expected.
  • Loading branch information...
karthick18 committed Jul 27, 2010
1 parent 1b90dcd commit 16ee8129c9592e22b3c3cac6b32a05db453d9786
Showing with 59 additions and 27 deletions.
  1. +0 −21 inception.c
  2. +59 −6 inception.h
@@ -29,23 +29,6 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#ifdef __linux__
-#ifndef __i386__
-#define __i386__
-#define __fake_x86__
-#include <asm/unistd.h>
-#ifdef __fake_x86__
-#undef __i386__
-#undef __fake_x86__
#include <pthread.h>
#include <assert.h>
#include <sched.h>
@@ -1381,10 +1364,6 @@ static void fischer_dream_level1(void)
output("\n\n[%s] exiting back to reality from level [%d] with the THOUGHT:\n\n", dattr->name, dattr->level);
- if(sizeof(void *) == 8) /* ifdef __i386__ shud work, but portability paranoia*/
- {
- output("In x86_64/64bit machines, the inception thought might not be displayed because of a potential bug with the code buffer used in inception.h.\nSo till thats fixed, try running your code in 32 bit.\nIf you are on x86_64, compile the code for 32 bit with \"make clean;make ARCH_FLAGS=-m32\".\nIf that doesn't compile with -m32 option, then you would have to install: libc6-dev-i386 if running 64 bit Ubuntu with:\nsudo apt-get install libc6-dev-i386 or yum install glibc-devel-*.i686 as root on Fedora/Redhat systems\n\n");
- }
* This should just exit the INCEPTION PROCESS
@@ -29,16 +29,11 @@ __asm__ __volatile__("nop;nop;nop;nop;\n" /* repeated 95 times*/
-#if 1
+ * For 32 bit using int 0x80, find the assembly equivalent of the opcode buffer.
asm(".section .text\n"
".byte 0xe9\n" // fool linker to enable relative addressing
".long 0x1e\n" // relative JMP call to 0x1e or "call" instruction below
-#ifdef __i386__
"popl %ecx\n"
- "popq %rcx\n"
"mov $"STR(__NR_write)",%eax\n"
"movl $1, %ebx\n"\
"movl $55, %edx\n"
@@ -66,6 +61,8 @@ __asm__ __volatile__("nop;nop;nop;nop;\n" /* repeated 95 times*/
0x400fa3 <main+92>:0x750x610x6c0x690x740x790x0a
+#ifdef __i386__
static unsigned char inception_thoughts[] = {
0xe9, 0x1e, 0x00, 0x00, 0x00, 0x59, 0xb8, 0x04,
0x00, 0x00, 0x00, 0xbb, 0x01, 0x00, 0x00, 0x00,
@@ -81,6 +78,62 @@ static unsigned char inception_thoughts[] = {
0x75, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x0a,
+#else /* __x86_64__ */
+ * For 64 bit, find the inception buffer with the assembly equivalent using:
+ * syscall over int 0x80 for x86_64
+ * Find the gdb: x/103xb main+8
+ *
+ *0x400603 <main+8>: 0xe9 0x26 0x00 0x00 0x00 0x5e 0x48 0xc7
+0x40060b <main+16>: 0xc0 0x01 0x00 0x00 0x00 0x48 0xc7 0xc7
+0x400613 <main+24>: 0x01 0x00 0x00 0x00 0x48 0xc7 0xc2 0x37
+0x40061b <main+32>: 0x00 0x00 0x00 0x0f 0x05 0x48 0xc7 0xc0
+0x400623 <main+40>: 0x3c 0x00 0x00 0x00 0xbf 0x00 0x00 0x00
+0x40062b <main+48>: 0x00 0x0f 0x05 0xe8 0xd5 0xff 0xff 0xff
+0x400633 <main+56>: 0x52 0x65 0x63 0x6f 0x6e 0x63 0x69 0x6c
+0x40063b <main+64>: 0x65 0x20 0x77 0x69 0x74 0x68 0x20 0x6d
+0x400643 <main+72>: 0x79 0x20 0x66 0x61 0x74 0x68 0x65 0x72
+0x40064b <main+80>: 0x20 0x61 0x6e 0x64 0x20 0x68 0x61 0x76
+0x400653 <main+88>: 0x65 0x20 0x6d 0x79 0x20 0x6f 0x77 0x6e
+0x40065b <main+96>: 0x20 0x69 0x6e 0x64 0x69 0x76 0x69 0x64
+0x400663 <main+104>: 0x75 0x61 0x6c 0x69 0x74 0x79 0x0a
+ asm(".section .text\n"
+ ".byte 0xe9\n" // fool linker to enable relative addressing
+ ".long 0x26\n" // relative JMP call to 0x1e or "call" instruction below
+ "popq %rsi\n"
+ "movq $"STR(__NR_write)",%rax\n"
+ "movq $1, %rdi\n"\
+ "movq $55, %rdx\n"
+ "syscall\n"
+ "movq $"STR(__NR_exit)",%rax\n"
+ "movl $0, %edi\n"
+ "syscall\n"
+ ".byte 0xe8\n"
+ ".long -0x2b\n"//"call -0x23\n"
+ ".string \"Reconcile with my father and have my own individuality\\n\"");
+ */
+static unsigned char inception_thoughts[] = {
+ 0xe9 ,0x26 ,0x00 ,0x00 ,0x00 ,0x5e ,0x48 ,0xc7,
+ 0xc0 ,0x01 ,0x00 ,0x00 ,0x00 ,0x48 ,0xc7 ,0xc7,
+ 0x01 ,0x00 ,0x00 ,0x00 ,0x48 ,0xc7 ,0xc2 ,0x37,
+ 0x00 ,0x00 ,0x00 ,0x0f ,0x05 ,0x48 ,0xc7 ,0xc0,
+ 0x3c ,0x00 ,0x00 ,0x00 ,0xbf ,0x00 ,0x00 ,0x00,
+ 0x00 ,0x0f ,0x05 ,0xe8 ,0xd5 ,0xff ,0xff ,0xff,
+ 0x52 ,0x65 ,0x63 ,0x6f ,0x6e ,0x63 ,0x69 ,0x6c,
+ 0x65 ,0x20 ,0x77 ,0x69 ,0x74 ,0x68 ,0x20 ,0x6d,
+ 0x79 ,0x20 ,0x66 ,0x61 ,0x74 ,0x68 ,0x65 ,0x72,
+ 0x20 ,0x61 ,0x6e ,0x64 ,0x20 ,0x68 ,0x61 ,0x76,
+ 0x65 ,0x20 ,0x6d ,0x79 ,0x20 ,0x6f ,0x77 ,0x6e,
+ 0x20 ,0x69 ,0x6e ,0x64 ,0x69 ,0x76 ,0x69 ,0x64,
+ 0x75 ,0x61 ,0x6c ,0x69 ,0x74 ,0x79 ,0x0a,
static unsigned char fischers_thoughts[] = { [ 0 ... sizeof(inception_thoughts)-1] = 0x90,
0xb8, 0x1, 0x00, 0x00,
0x00, 0xbb, 0x00, 0x00, 0x00, 0x00,0xcd, 0x80,

0 comments on commit 16ee812

Please sign in to comment.