x86
字数:189 | 预计阅读时间:2分钟
Basic
构建可执行程序
参数调用顺序
栈(stack)
Address | Contents
+---------------------------+
| rsp | value 0 | <-- the argument count
+---------------------------+
| rsp+8 | value 1 | <-- the address of program name
+---------------------------+
| rsp+16 | value 2 | <-- the address of the first argument
+---------------------------+
| ... | ... |
+---------------------------+
常用调试指令
objdump -d -M intel /tmp/your-program ; dissemble programs
strace /tmp/your-program ; to see the system call,parameter
gdb调试
quit/q
#to quit gdb
starti
#start the program at first command
disassemble
#disassemble program
stepi
#step one instruction forward
print $rdi
#read register value
x $rsp
#read the contents of memory
x/a $rsp+16
#a means address
x/s 0x7ffc001c4750
#s means string
run
#run the whole program until break
File Descriptors (FDs).
- FD 0: Standard Input is the channel through which the process takes input. For example, your shell uses Standard Input to read the commands that you input.
- FD 1: Standard Output is the channel through which processes output normal data, such as the flag when it is printed to you in previous challenges or the output of utilities such as
ls. - FD 2: Standard Error is the channel through which processes output error details. For example, if you mistype a command, the shell will output, over standard error, that this command does not exist.
linux x86
instruction
mov a, b
mov rdi, rsp
move second value to the first value
if there is [rsp], it means move the value which address rsp point to
pop a
pop rdi
does two things:
Reads the value at [rsp] into rdi (just like mov rdi, [rsp]).
Adds 8 to rsp, advancing the stack pointer to the next value.
int3
cmp a,b
setz dil
jne fail
add,sub,xor
div
mul,imul
shl,shr
movzx
syscall
exit(exit code), 60
write(fd, memory_address, number_write) , 1
read(fd, memory_address, number_read) , 0
open(filename_address, flags), 2
flags:0 (read only), 1 (only write), 2 (read and write), 65 (create and write)
return : rax = fd number