Chinaunix首页 | 论坛 | 博客
  • 博客访问: 556838
  • 博文数量: 99
  • 博客积分: 5015
  • 博客等级: 大校
  • 技术积分: 1209
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-28 23:08
文章存档

2011年(7)

2010年(6)

2009年(86)

我的朋友

分类: C/C++

2009-11-09 11:43:36

下面的六个程序片段主要完成这些事情:(来源:)

  1. 输出Hello, World
  2. 混乱C语言的源代码

下面的所有程序都可以在GCC下编译通过,只有最后一个需要动用C++的编译器g++才能编程通过。

hello1.c

01.    #define _________ }

02.    #define ________ putchar
03.    #define _______ main
04.    #define _(a) ________(a);
05.    #define ______ _______(){
06.    #define __ ______ _(0x48)_(0x65)_(0x6C)_(0x6C)
07.    #define ___ _(0x6F)_(0x2C)_(0x20)_(0x77)_(0x6F)
08.    #define ____ _(0x72)_(0x6C)_(0x64)_(0x21)
09.    #define _____ __ ___ ____ _________
10.    #include
11.    _____
 

hello2.c 

01.    #include
02.    main(){
03.      int x=0,y[14],*z=&y;*(z++)=0x48;*(z++)=y[x++]+0x1D;
04.      *(z++)=y[x++]+0x07;*(z++)=y[x++]+0x00;*(z++)=y[x++]+0x03;
05.      *(z++)=y[x++]-0x43;*(z++)=y[x++]-0x0C;*(z++)=y[x++]+0x57;
06.      *(z++)=y[x++]-0x08;*(z++)=y[x++]+0x03;*(z++)=y[x++]-0x06;
07.      *(z++)=y[x++]-0x08;*(z++)=y[x++]-0x43;*(z++)=y[x]-0x21;
08.      x=*(--z);while(y[x]!=NULL)putchar(y[x++]);
09.    }

hello3.c

01.    #include
02.    #define __(a) goto a;
03.    #define ___(a) putchar(a);
04.    #define _(a,b) ___(a) __(b);
05.    main()
06.    { _:__(t)a:_('r',g)b:_('$',p)
07.      c:_('l',f)d:_(' ',s)e:_('a',s)
08.      f:_('o',q)g:_('l',h)h:_('d',n)
09.      i:_('e',w)j:_('e',x)k:_('\n',z)
10.      l:_('H',l)m:_('X',i)n:_('!',k)
11.      o:_('z',q)p:_('q',b)q:_(',',d)
12.      r:_('i',l)s:_('w',v)t:_('H',j)
13.      u:_('a',a)v:_('o',a)w:_(')',k)
14.      x:_('l',c)y:_('\t',g)z:___(0x0)}

hello4.c

01.    int n[]={0x48,
02.    0x65,0x6C,0x6C,
03.    0x6F,0x2C,0x20,
04.    0x77,0x6F,0x72,
05.    0x6C,0x64,0x21,
06.    0x0A,0x00},*m=n;
07.    main(n){putchar
08.    (*m)!='\0'?main
09.    (m++):exit(n++);}

hello5.c

01.    main(){int i,n[]={(((1<<1)<<(1<<1)<<(1<<
02.    1)<<(1<<(1>>1)))+((1<<1)<<(1<<1))), (((1
03.    <<1)<<(1<<1)<<(1<<1)<<(1<<1))-((1<<1)<<(
04.    1<<1)<<(1<<1))+((1<<1)<<(1<<(1>>1)))+ (1
05.    <<(1>>1))),(((1<<1)<<(1<<1)<<(1<<1)<< (1
06.    <<1))-((1<<1)<<(1<<1)<<(1<<(1>>1)))- ((1
07.    <<1)<<(1<<(1>>1)))),(((1<<1)<<(1<<1)<<(1
08.    <<1)<<(1<<1))-((1<<1)<<(1<<1)<<(1<<(1>>1
09.    )))-((1<<1)<<(1<<(1>>1)))),(((1<<1)<< (1
10.    <<1)<<(1<<1)<<(1<<1))-((1<<1)<<(1<<1)<<(
11.    1<<(1>>1)))-(1<<(1>>1))),(((1<<1)<<(1<<1
12.    )<<(1<<1))+((1<<1)<<(1<<1)<<(1<<(1>>1)))
13.    -((1<<1)<<(1<<(1>>1)))),((1<<1)<< (1<<1)
14.    <<(1<<1)),(((1<<1)<<(1<<1)<<(1<<1)<<(1<<
15.    1))-((1<<1)<<(1<<1))-(1<<(1>>1))),(((1<<
16.    1)<<(1<<1)<<(1<<1)<<(1<<1))-((1<<1)<< (1
17.    <<1)<<(1<<(1>>1)))-(1<<(1>>1))), (((1<<1
18.    )<<(1<<1)<<(1<<1)<<(1<<1))- ((1<<1)<< (1
19.    <<1)<<(1<<(1>>1)))+(1<<1)), (((1<<1)<< (
20.    1<<1)<<(1<<1)<< (1<<1))-((1<<1)<< (1<<1)
21.    <<(1<<(1>>1)))-((1<<1) <<(1<< (1>>1)))),
22.    (((1<<1)<< (1<<1)<<(1<<1)<< (1<<1))- ((1
23.    <<1)<<(1<<1)<<(1<<1))+((1<<1)<< (1<<(1>>
24.    1)))), (((1<<1)<<(1<<1) <<(1<<1))+(1<<(1
25.    >>1))),(((1<<1)<<(1<<1))+((1<<1)<< (1<<(
26.    1>>1))) + (1<< (1>>1)))}; for(i=(1>>1);i
27.    <(((1<<1) <<(1<<1))+((1 <<1)<< (1<<(1>>1
28.    ))) + (1<<1)); i++) printf("%c",n[i]); }

hello6.cpp

下面的程序只能由C++的编译器编译(比如:g++)

01.    #include
02.    #define _(_) putchar(_);
03.    int main(void){int i = 0;_(
04.    ++++++++++++++++++++++++++++
05.    ++++++++++++++++++++++++++++
06.    ++++++++++++++++++++++++++++
07.    ++++++++++++++++++++++++++++
08.    ++++++++++++++++++++++++++++
09.    ++++i)_(++++++++++++++++++++
10.    ++++++++++++++++++++++++++++
11.    ++++++++++i)_(++++++++++++++
12.    i)_(--++i)_(++++++i)_(------
13.    ----------------------------
14.    ----------------------------
15.    ----------------------------
16.    ----------------------------
17.    ----------------i)_(--------
18.    ----------------i)_(++++++++
19.    ++++++++++++++++++++++++++++
20.    ++++++++++++++++++++++++++++
21.    ++++++++++++++++++++++++++++
22.    ++++++++++++++++++++++++++++
23.    ++++++++++++++++++++++++++++
24.    ++++++++++++++++++++++++++i)
25.    _(----------------i)_(++++++
26.    i)_(------------i)_(--------
27.    --------i)_(----------------
28.    ----------------------------
29.    ----------------------------
30.    ----------------------------
31.    ----------------------------
32.    ------i)_(------------------
33.    ----------------------------
34.    i)return i;}
下面是直接用机器码写的hello world,没看对应的汇编,写完再反汇编验证(作者:过儿,):
 
下面是具体的步骤:

1、先crack ELF可执行文件的格式,这个我已经做过了,以前还写过一篇文章专门分析ELF可执行文件的格式,

精确到每一个bit位,把这些写到一个二进制数据文件里去

2、查看根据write系统调用对应的汇编代码,查出来对应的机器指令,然后追加到前面那个二进制文件里面去

3、执行文件,就可以将hello world输出到屏幕上了。代码如下:

C/C++ code
0000000: 7f45 4c46 0101 0100 0000 0000 0000 0000 .ELF............ 0000010: 0200 0300 0100 0000 7480 0408 3400 0000 ........t...4... 0000020: 6401 0000 0000 0000 3400 2000 0200 2800 d.......4. ...(. 0000030: 0900 0600 0100 0000 0000 0000 0080 0408 ................ 0000040: 0080 0408 9600 0000 9600 0000 0500 0000 ................ 0000050: 0010 0000 0100 0000 9800 0000 9890 0408 ................ 0000060: 9890 0408 1000 0000 1000 0000 0600 0000 ................ 0000070: 0010 0000 ba10 0000 00b9 9890 0408 bb01 ................ 0000080: 0000 00b8 0400 0000 cd80 bb00 0000 00b8 ................ 0000090: 0100 0000 cd80 0000 4865 6c6c 6f2c 2077 ........Hello, w 00000a0: 6f72 6c64 215c 6e00 0100 0000 0000 0900 orld!\n......... 00000b0: 0900 0000 0100 0000 6400 0000 7480 0408 ........d...t... 00000c0: 0000 0000 4400 0800 7480 0408 0000 0000 ....D...t....... 00000d0: 4400 0900 7980 0408 0000 0000 4400 0a00 D...y.......D... 00000e0: 7e80 0408 0000 0000 4400 0b00 8380 0408 ~.......D....... 00000f0: 0000 0000 4400 0c00 8880 0408 0000 0000 ....D........... 0000100: 4400 0f00 8a80 0408 0000 0000 4400 1000 D...........D... 0000110: 8f80 0408 0000 0000 4400 1100 9480 0408 ........D....... 0000120: 0068 656c 6c6f 2e73 0000 2e73 796d 7461 .hello.s...symta 0000130: 6200 2e73 7472 7461 6200 2e73 6873 7472 b..strtab..shstr 0000140: 7461 6200 2e74 6578 7400 2e64 6174 6100 tab..text..data. 0000150: 2e62 7373 002e 7374 6162 002e 7374 6162 .bss..stab..stab 0000160: 7374 7200 0000 0000 0000 0000 0000 0000 str............. 0000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000180: 0000 0000 0000 0000 0000 0000 1b00 0000 ................ 0000190: 0100 0000 0600 0000 7480 0408 7400 0000 ........t...t... 00001a0: 2200 0000 0000 0000 0000 0000 0400 0000 "............... 00001b0: 0000 0000 2100 0000 0100 0000 0300 0000 ....!........... 00001c0: 9890 0408 9800 0000 1000 0000 0000 0000 ................ 00001d0: 0000 0000 0400 0000 0000 0000 2700 0000 ............'... 00001e0: 0800 0000 0300 0000 a890 0408 a800 0000 ................ 00001f0: 0000 0000 0000 0000 0000 0000 0400 0000 ................ 0000200: 0000 0000 2c00 0000 0100 0000 0000 0000 ....,........... 0000210: 0000 0000 a800 0000 7800 0000 0500 0000 ........x....... 0000220: 0000 0000 0400 0000 0c00 0000 3200 0000 ............2... 0000230: 0300 0000 0000 0000 0000 0000 2001 0000 ............ ... 0000240: 0900 0000 0000 0000 0000 0000 0100 0000 ................ 0000250: 0000 0000 1100 0000 0300 0000 0000 0000 ................ 0000260: 0000 0000 2901 0000 3b00 0000 0000 0000 ....)...;....... 0000270: 0000 0000 0100 0000 0000 0000 0100 0000 ................ 0000280: 0200 0000 0000 0000 0000 0000 cc02 0000 ................ 0000290: f000 0000 0800 0000 0b00 0000 0400 0000 ................ 00002a0: 1000 0000 0900 0000 0300 0000 0000 0000 ................ 00002b0: 0000 0000 bc03 0000 2800 0000 0000 0000 ........(....... 00002c0: 0000 0000 0100 0000 0000 0000 0000 0000 ................ 00002d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 00002e0: 7480 0408 0000 0000 0300 0100 0000 0000 t............... 00002f0: 9890 0408 0000 0000 0300 0200 0000 0000 ................

这个就是最终的二进制码流了,反汇编能看到对应的汇编代码如下:
0x08048074 <_start+0>:  mov    $0x10,%edx
0x08048079 <_start+5>:  mov    $0x8049098,%ecx
0x0804807e <_start+10>: mov    $0x1,%ebx
0x08048083 <_start+15>: mov    $0x4,%eax
0x08048088 <_start+20>: int    $0x80
0x0804808a <_start+22>: mov    $0x0,%ebx
0x0804808f <_start+27>: mov    $0x1,%eax
0x08048094 <_start+32>: int    $0x80
阅读(6534) | 评论(0) | 转发(1) |
0

上一篇:vim使用

下一篇:如何加密/弄乱C源代码

给主人留下些什么吧!~~