iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 25
2
自我挑戰組

到處挖坑,現在該來還(填)願(坑)ㄌ !!!系列 第 25

『 Day 25』拜託別 Pwn 我啦! - Register & Assembly

Register 暫存器

https://ithelp.ithome.com.tw/upload/images/20191011/20115060fRCILivUjX.png

以 AX Register 來舉例,在不同位元下的 AX

一般用途暫存區(General Purpose Register ; GPR),可分為 RAX、RBX、RCX、RDX、R8~R15。

稍微來介紹一下常見的暫存器(64位元):

  • RAX 特殊用途:存放運算結果,執行乘法及除法指令時,會自動使用
  • RBX 特殊用途:基底定址法的基底暫存器
  • RCX 特殊用途:做迴圈的計數器
  • RDX 特殊用途:資料暫存器
  • 堆疊指位器 RSP:指向 Stack 的頂端(Point to the top of stack)
  • 基底指位器 RBP:指向 Stack 的底部(Point to the bottom of stack)
  • 索引指位器 RSI、RDI
  • 程式指位器 RIP:主掌CPU動向的暫存器(放下一個指令位址)

Assembly 組合語言

這邊簡單舉幾個常見的 Assembly 的 OP Code(Operation Code)

             Assembly                               C 語言
----------------------------------- -----------------------------------
push  rbp                           push(rbp);
mov   rbp,rsp                       rbp = rsp;
sub   rsp,0x20                      rsp -= 0x20;
call  401710                        f_401710();
lea   rcx,[rip+0x2a8c]              rcx = rip + 0x2a8c;
call  402c40                        f_402c40();
mov   eax,0x0                       eax = 0;
add   rsp,0x20                      rsp += 0x20;
pop   rbp                           pop(&rbp);
ret                                 return;

順帶一提,X86 架構的組語表式方式,其實分為「Intel 格式」和「AT&T 格式」這兩種。

  • Intel 格式
OpCode | Opearand
-------|---------
mov    | eax,0xA
push   | 0x0
pop    | rax
  • AT&T 格式
OpCode | Opearand
-------|---------
mov    | $0xA,%eax
push   | $0x0
pop    | %rax

上一篇
『 Day 24』拜託別 Pwn 我啦! - 介紹 & ELF
下一篇
『 Day 26』拜託別 Pwn 我啦! - 常見的工具 (上)
系列文
到處挖坑,現在該來還(填)願(坑)ㄌ !!!30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言