.text
읽기 전용 이므로 어셈블리에서 자체 수정 코드가 가능한지 확인하고 싶었 습니다. .data
대신 코드를 넣을 수 있다고 생각 했기 때문에 아래 코드를 시도했습니다.
section .text
global _start ;must be declared for linker (ld)
_start: ;tell linker entry point
mov al,3
mov rbx,cont1 ;store label cont1 in rbx so we can continue there
mov cl,byte [dec_op] ;put the opcode of the dec instruction in cl
mov byte [code],cl ;replace the inc instruction with a dec instruction
jmp code ;run the modified code
cont1:
mov byte [dat1],al ;store away the changed value
add byte [dat1],0x30 ;turn the internal numeric value into an ascii digit
mov eax,4 ;system call number (sys_write)
mov ebx,1 ;stdout
mov ecx,dat1 ;location of data
mov edx,2 ;length of data
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
dat1 db 0,0xa ;location to store output
dec_op dec al ;the dec instruction
code inc al ;code to modify
jmp rbx
위의 출력은
4
내가 예상했지만 2
, 자체 수정 후 증가 명령 대신 감소 명령이 있어야합니다. 내가 무엇을 잘못하고 있지?
데비안 sid 64 비트를 실행하고 있으며 다음과 같이 컴파일하고 있습니다.
nasm -f elf64 sm.s
ld -s -o sm sm.o
DEC AL
2 바이트가 필요 하기 때문입니다.
nasm에 의해 생성 된 "listfile"에서 (열이 약간 압축 됨) :
26 00000000 000A dat1 db 0,0xa ;location to store output
27 00000002 FEC8 dec_op dec al ;the dec instruction
28 00000004 FEC0 code inc al ;code to modify
29 00000006 FFE3 jmp rbx
두 연산 코드의 첫 번째 바이트가 동일하므로 혼동이 있음을 알 수 있습니다.
그리고 이것은 수정입니다.
mov cx,word [dec_op] ;put the opcode of the dec instruction in cl
mov word [code],cx ;replace the inc instruction with a dec instruction
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다