Explanation:
I am using GDB to disassembly my self-written ELF64 executables which are assembled using NASM.
When I try to disassemble using disassemble main
, I only get the following output:
Dump of assembler code for function main:
0x0000000000401110 <+0>: mov rbp,rsp
0x0000000000401113 <+3>: mov ebx,0x400
End of assembler dump.
GDB obviously only gives me the first two lines, the ones before the loop whose start is indicated with .loop_clear
begins.
When I try to specify lines like disassemble 0x0000000000401116, 0x0000000000401119
, I get the following output:
0x0000000000401116 <main+6>: add BYTE PTR [rax],al
0x0000000000401118 <main.loop_clear+0>: cmp rbx,0x0
As can be seen, there are lines that aren't shown in the first dump.
In the next try, I try to explicitely disassemble main.loop_clear
by calling disassemble main.loop_clear
but am left with Attempt to extract a component of a value that is not a structure.
Obviously the commands I am using or the syntax is wrong, but I couldn't find useful information during my research in order to fix this issue.
Question: Hence my question: How is it possible to create a complete and coherent dump of the disassembled executable if the function that is being disassembled contains labels/loops? Furthermore, is it possible to disassemble the loop for itself?
Source:
global main
section .text
main:
;initialize base pointer (rbp)
mov rbp, rsp
;set stack frame size and clear
mov rbx, 0x400
.loop_clear:
cmp rbx, 0x0
je .exit_clear
mov byte [rsp], 0x0
dec rsp
dec rbx
jmp .loop_clear
.exit_clear:
;prepare array index pointer
mov rcx, rsp
;transpiled brainfuck source
mov bl, [rcx]
add bl, 65
mov [rcx], bl
mov rsi, rcx
mov rdx, 0x1
mov rdi, 0x1
mov rax, 0x1
syscall ; write(fd=1, buf, size=1 byte)
;exit gracefully
mov rax, 0x3
mov rdi, 0x0
syscall ; close(0)
ret