【发布时间】:2014-08-31 20:28:54
【问题描述】:
我想编写一个汇编程序,该程序一旦加载到内存中,就会在自身上写入新指令,但我不能 100% 确定如何进行,因为我对指令指针和其他汇编概念有一些疑问。我假设的方法:
_func:
push rip ; Not allowed to push RIP, how can I read from RIP?
jmp stage1
stage2:
mov eax, 0
ret
stage1:
pop rbx
; How many times should I increment rbx to point to ‘mov eax, 0’?
; Assuming this is done:
;Move opcodes for ‘mov eax, 1’ into memory where ‘mov eax, 0’ located
mov [rbx], 0xB8
mov [rbx+1], 0x01
mov [rbx+2], 0x00
mov [rbx+3], 0x00
mov [rbx+4], 0x00
jmp stage2
当它跳转到阶段 2 时,它会遇到操作码 'B8 01 00 00 00' 而不是 'mov eax, 0' 并解释 'mov eax, 1'。我的一般方法是否正确,有人可以填补代码中的空白吗?
其他困惑/问题
RBX 是指向指令行的第一个字节,还是“整个”行?上述方法是否正确,或者我应该写:
mov [rbx], B801000000h
操作系统: Mac OS X 10.9 汇编器: NASM
【问题讨论】:
-
我不会称之为“反射”——这个术语是指更高层次的概念。自修改代码更像它。 stackoverflow.com/questions/24676966/…
标签: assembly