Linux x86程序集打印问题
我写这篇文章是为了在x86中打印Linux x86程序集打印问题,linux,assembly,x86,Linux,Assembly,X86,我写这篇文章是为了在x86中打印argv[0]: .section .data newline: .int 0xa, 0 .section .text .globl _start _start: sub %al, %al movl 4(%esp), %edi /* Pointer to argv[0]. */ sub %ecx, %ecx /* Set %ecx to 0.*/ not %ecx
argv[0]
:
.section .data
newline: .int 0xa, 0
.section .text
.globl _start
_start:
sub %al, %al
movl 4(%esp), %edi /* Pointer to argv[0]. */
sub %ecx, %ecx /* Set %ecx to 0.*/
not %ecx /* Set %ecx to -1.*/
repne scasb /* Search for %al over and over.*/
not %ecx /* Set %ecx to |%ecx| - 1.*/
dec %ecx
movl %ecx, %edx /* Move the strlen of argv[0] into %edx.*/
movl $4, %eax
movl $1, %ebx
movl 4(%esp), %ecx
int $0x80
movl $newline, %ecx
movl $1, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
当我运行此文件(“打印”)时,输出如下:
[08:27 assembly]$ ./print test
./print[08:30 assembly]$
test
[08:33 assembly]$
当我通过gdb运行这个时,edx中保存的实际字符串长度是27,它检查的字符串是“/home/robert/assembly/print”,而不是“/print”。因此,我将%esp
偏移量更改为8,以检查argv[1]
。使用与前面相同的命令,输出如下:
[08:27 assembly]$ ./print test
./print[08:30 assembly]$
test
[08:33 assembly]$
为什么检查argv[0]
会导致奇怪的输出,而argv[1]
却如预期的那样?我认为gdb通过添加到argv[0]
的完整路径来“帮助”您。打印后,%eax
保存打印的字符数,因此您需要再次为系统重新加载%eax以打印$newline
(%ebx
应该还可以)-幸运的是,“test”是正确的长度。天知道你用那根更长的绳子得到了什么样的系统调用
我得说你做得很好!(在您尝试打印它之前,最好先检查一下argc
以确保argv[1]
在那里)。啊,我想知道调用sys\u write
后,%eax
是否被修改了,但我不确定该在哪里查找此类内容。不过,在重新加载后,它可以正常工作!