講師: ItisCaleb
思路->原始碼->成品
成品->原始碼->思路
不將程式跑起來,而直接從binary來分析
使用 Desassmbler(反組譯) 或是 Decompiler (反編譯) 來分析
將程式實際跑起來
透過 Debugger (除錯器)觀察他的行為(呼叫函式的參數、記憶體)
1 bit = 1/0
1 byte = 8 bits = 1 char
1 word = 2 bytes = 1 short
1 dword = 4 bytes = 1 int
1 qword = 8 bytes = 1 long int
1 bit = 1/0
1 byte = 8 bits
1 word = 4 bytes = 1 int
1 dword = 8 bytes = 1 long int
hello.c
hello.i
hello.s
hello.o
hello
*.obj
library
preprocessor
compiler
assembler
linker
hello
memory
loader
execute
find entrypoint
AH | AL | ||
BH | BL | ||
CH | CL | ||
DH | DL |
63 32 31 16 15 8 7 0
BP | ||
SP | ||
SI | ||
DI |
IP |
64 bits | 32 bits | 16 bits |
---|---|---|
RAX | EAX | AX |
RBX | EBX | BX |
RCX | ECX | CX |
RDX | EDX | DX |
RBP | EBP | BP |
RSP | ESP | SP |
RSI | ESI | SI |
RDI | EDI | DI |
RIP | EIP | IP |
General purpose
Stack pointer
Stack Base pointer
Program counter
Additional register r8 ~ r16 in x86-64
// move
mov rax, rbx // rax = rbx
mov rax, dword ptr [rbx] // int rax = *(int*)rbx
// load effective address
lea rax, [0xdeadbeef] // rax = 0xdeadbeef
lea rax, [rbx*4+0x10] // rax = rbx*4+0x10
// arithmetic
add rax, rbx // rax += rbx
sub rax, rbx // rax -= rbx
inc rax // rax++
dec rax // rax--
shr rax, 1 // rax = rax >> 1
shl rax, 1 // rax = rax << 1
// logic
and rax, rbx // rax &= rbx
or rax, rbx // rax |= rbx
xor rax, rbx // rax ^= rbx
not rax // rax = !rax
mov rax, 7
mov rbx, 6
sub rax, rbx // 7 - 6 ZF=0 CF=0
sub rax, rbx // 1 - 6 ZF=0 CF=1
mov rax, 5
sub rax, rax // 5 - 5 ZF=1 CF=0
// Intel
mov rax, 11
mov rax, rbx
add rax, rbx
sub rax, 12
// op <dst> <src>
// rax = 11
// AT&T
movl $11, %rax
mov %rbx, %rax
add %rbx, %rax
subl $12, %rax
// op <src> <dst>
// 11 -> rax
apt install gdb