0
我想雙轉換爲字符串在棧上從x86_64的彙編代碼:如何從x86_64程序集調用sprintf?
bs.code += isa.movsd(registers.xmm0, MemRef(registers.rsp))
bs.code += isa.pop(registers.rax)
bs.code += isa.push(registers.rbp)
bs.code += isa.mov(registers.rbp, registers.rsp)
bs.code += isa.sub(registers.rsp, 100)
bs.code += isa.and_(registers.rsp, -16)
bs.code += isa.mov(registers.rdi, registers.rsp)
bs.code += isa.mov(registers.rsi, <address of "%i\0">)
bs.code += isa.mov(registers.rax, <address of sprintf in libc>)
bs.code += isa.call(registers.rax)
在call(rax)
程序段錯誤與
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a2919b in *__GI___overflow (f=0x7fffffffb5d0, ch=9698128) at genops.c:248
warning: Source file is more recent than executable.
248 return _IO_OVERFLOW (f, ch);
我認爲sprintf
必須要特別,因爲它叫使用可變參數,所以任何人都可以建議正確的方式從彙編做到這一點?
我試過這個,但必須做-fno-stack-protector才能得到簡單的代碼。 – 2010-08-20 22:41:48