Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    [+++]xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   [+++]x80485e0   0x0804843c <+16>:    push   [+++]x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   [+++]x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov [+++]x404040,%r8 0x0000000000401596 <+22>: mov [+++]x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 10, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   [+++]x80485e0   0x0804843c <+16>:    push   [+++]x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   [+++]x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov [+++]x404040,%r8 0x0000000000401596 <+22>: mov [+++]x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 11, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   [+++]x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   [+++]x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov [+++]x404040,%r8 0x0000000000401596 <+22>: mov [+++]x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 12, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   [+++]x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov [+++]x404040,%r8 0x0000000000401596 <+22>: mov [+++]x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 13, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov [+++]x404040,%r8 0x0000000000401596 <+22>: mov [+++]x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 14, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov [+++]x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 15, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov [+++]x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 16, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

[+++]

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 17, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

示例会话

[+++]

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 18, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

示例会话

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

[+++]

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 19, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

示例会话

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

cmdline.gdb

[+++]

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 20, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

示例会话

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

cmdline.gdb

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

[+++]

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 21, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

示例会话

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

cmdline.gdb

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

[+++] 总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
x86 Linux汇编程序从_start获取程序参数_系统运维_内存溢出

x86 Linux汇编程序从_start获取程序参数

x86 Linux汇编程序从_start获取程序参数,第1张

概述我正在尝试创建一个程序来在屏幕上编写参数. 我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序. 有没有办法只使用汇编程序获取程序参数 EX: ./Program "text" 我正在使用(Gnu Assembler) 通常我会使用这些参数 [esp+4] 因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数. 有没有办法做到这一点? 我用Google搜索,但我 我正在尝试创建一个程序来在屏幕上编写参数.
我创建了一些程序来获取C函数参数,或者我使用C将参数发送到我的asm程序.
有没有办法只使用汇编程序获取程序参数

EX:

./Program "text"

我正在使用(Gnu Assembler)

通常我会使用这些参数

[esp+4]

因为esp是程序/函数调用指针,但在纯asm中它没有得到命令行参数.

有没有办法做到这一点?

我用Google搜索,但我无法找到更多信息

解决方法 在linux上,来自C的熟悉的argc和argv变量总是由内核传递到堆栈中,甚至可用于完全独立的汇编程序,也不与C库中的启动代码链接.这在 i386 System V ABI中有记录,以及进程启动环境的其他详细信息(寄存器值,堆栈对齐).

在x86 linux可执行文件的ELF入口点(a.k.a._start):

> ESP指向argc
> ESP 4指向argv [0],数组的开始.即你应该传递给main的值为char ** argv是lea eax,[esp 4],而不是mov eax,[esp 4])

最小装配程序如何获得argc和argv

我将展示如何在GDB中读取argv和argc [0].

CMDliNE-x86.S

#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdline-x86run# We'll regain control here after the breakpoint trapprintf "argc: %d\n",*(int*)$espprintf "argv[0]: %s\n",((char**)($esp + 4))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%eax mov
$cc -nostdlib -g3 -m32 cmdline-x86.S -o cmdline-x86$gdb -q -x cmdline-x86.gdb cmdline-x86<...>  Program received signal SIGTRAP,Trace/breakpoint trap._start () at cmdline-x86.S:88   mov $SYS_exit_group,%eaxargc: 1argv[0]: /home/scottt/DropBox/stackoverflow/cmdline-x86
,%ebx int
#include <sys/syscall.h>    .global _start_start:    /* Cause a breakpoint trap */    int 
set confirm offfile cmdlinerunprintf "argc: %d\n",*(int*)$rspprintf "argv[0]: %s\n",((char**)($rsp + 8))[0]quit
x03 /* exit_group(0) */ mov $SYS_exit_group,%rax mov
$gdb -q /bin/trueReading symbols from /usr/bin/true...Reading symbols from /usr/lib/deBUG/usr/bin/true.deBUG...done.done.(gdb) disassemble _startDump of assembler code for function _start:   0x0000000000401580 <+0>: xor    %ebp,%ebp   0x0000000000401582 <+2>: mov    %rdx,%r9   0x0000000000401585 <+5>: pop    %rsi   0x0000000000401586 <+6>: mov    %rsp,%rdx   0x0000000000401589 <+9>: and    
Dump of assembler code for function _start:   0x0804842c <+0>: xor    %ebp,%ebp   0x0804842e <+2>: pop    %esi   0x0804842f <+3>: mov    %esp,%ecx   0x08048431 <+5>: and    xfffffff0,%esp   0x08048434 <+8>: push   %eax   0x08048435 <+9>: push   %esp   0x08048436 <+10>:    push   %edx   0x08048437 <+11>:    push   x80485e0   0x0804843c <+16>:    push   x8048570   0x08048441 <+21>:    push   %ecx   0x08048442 <+22>:    push   %esi   0x08048443 <+23>:    push   x80483d0   0x08048448 <+28>:    call   0x80483b0 <__libc_start_main@plt>   0x0804844d <+33>:    hlt       0x0804844e <+34>:    xchg   %ax,%axEnd of assembler dump.
xfffffffffffffff0,%rsp 0x000000000040158d <+13>: push %rax 0x000000000040158e <+14>: push %rsp 0x000000000040158f <+15>: mov x404040,%r8 0x0000000000401596 <+22>: mov x403fb0,%rcx 0x000000000040159d <+29>: mov x4014c0,%rdi 0x00000000004015a4 <+36>: callq 0x401310 <__libc_start_main@plt> 0x00000000004015a9 <+41>: hlt 0x00000000004015aa <+42>: xchg %ax,%ax 0x00000000004015ac <+44>: nopl 0x0(%rax)
,%rdi syscall
x80

CMDliNE-x86.gdb

示例会话

说明

>我放置了一个软件断点(int $0x03),使程序在ELF入口点(_start)之后立即陷入调试器.
>然后我在GDB脚本中使用printf进行打印

>带有表达式*(int *)$esp的argc
>带表达式的argv((char **)($esp 4))[0]

x86-64版本

差异很小:

>用RSP替换ESP
>将地址大小从4更改为8
>当我们调用exit_group(0)来正确终止进程时,遵守不同的linux系统调用约定

cmdline.S

cmdline.gdb

常规C程序如何获得argc和argv

您可以从常规C程序中反汇编_start,以查看它是如何从堆栈中获取argc和argv并在调用__libc_start_main时传递它们的.以我的x86-64机器上的/ bin / true程序为例:

__libc_start_main()的前三个参数是:

> RDI:指向main()的指针
> RSI:argc,你可以看到它是如何从堆栈d出的第一件事
> RDX:argv,d出argc后RSP的值. (GliBC源代码中的ubp_av)

x86 _start非常相似:

总结

以上是内存溢出为你收集整理的x86 Linux汇编程序从_start获取程序参数全部内容,希望文章能够帮你解决x86 Linux汇编程序从_start获取程序参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1027889.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存