LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 658|回复: 3

内联汇编

[复制链接]
发表于 2005-5-4 11:42:31 | 显示全部楼层 |阅读模式
/*
*code0.s
*/   
  1.             
  2.        jmp   0x0804948c\
  3.       popl   %esi\
  4.       movl   %esi,   0x8(%esi)\
  5.       xorl   %eax,   %eax\
  6.       movb   %al,   0x7(%esi)\
  7.       movl   %eax,   0xc(%esi)\
  8.       movb   $0xb,   %al\
  9.       movl   %esi,   %ebx\
  10.       leal   0x8(%esi),   %ecx\
  11.       xorl   %edx,   %edx\
  12.       int   $0x80\
  13.       call   0x08049475\
  14.       .string   "/bin/sh"\
复制代码


code0.s能够正确运行
 楼主| 发表于 2005-5-4 11:43:36 | 显示全部楼层
/*
*code1.c
*/

  1. int main()
  2. {
  3.    __asm__
  4.       ("\
  5.       jmp   0x0804948c\
  6.       popl   %esi\
  7.       movl   %esi,   0x8(%esi)\
  8.       xorl   %eax,   %eax\
  9.       movb   %al,   0x7(%esi)\
  10.       movl   %eax,   0xc(%esi)\
  11.       movb   $0xb,   %al\
  12.       movl   %esi,   %ebx\
  13.       leal   0x8(%esi),   %ecx\
  14.       xorl   %edx,   %edx\
  15.       int   $0x80\
  16.       call   0x08049475\
  17.       .string   "/bin/sh"\
  18.       ");
  19. }
复制代码

$gcc code1.c
/tmp/ccPcT2ae.s: Assembler messages:
/tmp/ccPcT2ae.s:13: Error: junk `popl %esi movl %esi' after expression
/tmp/ccPcT2ae.s:13: Error: too many memory references for `jmp'

那位碰到过这种问题,是怎样解决的
thanks
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-4 11:44:43 | 显示全部楼层
付code1.s


  1.    .file   "code1.c"
  2.    .text
  3. .globl main
  4.    .type   main, @function
  5. main:
  6.    pushl   %ebp
  7.    movl   %esp, %ebp
  8.    subl   $8, %esp
  9.    andl   $-16, %esp
  10.    movl   $0, %eax
  11.    subl   %eax, %esp
  12. #APP
  13.          jmp   0x0804948c      popl   %esi      movl   %esi,   0x8(%esi)      xorl   %eax,   %eax      movb   %al,   0x7(%esi)      movl   %eax,   0xc(%esi)      movb   $0xb,   %al      movl   %esi,   %ebx      leal   0x8(%esi),   %ecx      xorl   %edx,   %edx      int   $0x80      call   0x08049475      .string   "/bin/sh"      
  14. #NO_APP
  15.    leave
  16.    ret
  17.    .size   main, .-main
  18.    .section   .note.GNU-stack,"",@progbits
  19.    .ident   "GCC: (GNU) 3.3.4 (Debian 1:3.3.4-6sarge1)"
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-5-4 12:21:00 | 显示全部楼层
我faint. 你看看gcc内联汇编的格式先。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表