สแตกและรูปแบบการเรียกใช้
เจาะลึกวิธีที่ฟังก์ชันส่งอาร์กิวเมนต์ ส่งคืนค่า และจัดการเฟรมสแตก ซึ่งเป็นความรู้ที่ช่วยให้อ่านโค้ดที่แยกกลับจากไบนารีได้
สแตกและรูปแบบการเรียกใช้ เป็นบทเรียน Reverse Engineering & Binary Analysis Basics ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Reverse Engineering & Binary Analysis Basics และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Reverse Engineering & Binary Analysis Basics มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Beyond a Single Call
You can read basic x86/x64 instructions and follow control flow. To truly understand function calls you must know the stack and calling conventions.
These rules govern how arguments arrive and how cleanup happens.
What the Stack Is
The stack is a region of memory that grows downward (toward lower addresses). It stores return addresses, saved registers, and local variables.
pushdecrements RSP and writespopreads and increments RSP
push rax ; rsp -= 8, [rsp] = rax
pop rbx ; rbx = [rsp], rsp += 8RSP and RBP
Two registers track the stack:
- RSP (stack pointer) points to the current top
- RBP (base pointer) anchors the current frame
Locals are addressed relative to RBP, like [rbp-8].
The Function Prologue
Most functions begin with a prologue that sets up the frame: save the old base pointer, then point RBP at the new frame.
push rbp
mov rbp, rsp
sub rsp, 0x20 ; reserve 32 bytes for localsThe Function Epilogue
The epilogue reverses the prologue, restoring the caller's frame before returning.
mov rsp, rbp
pop rbp
retCalling Conventions
A calling convention is the contract for passing arguments and returning values.
- Where arguments go (registers or stack)
- Who cleans up the stack
- Which registers must be preserved
System V AMD64 (Linux x64)
On Linux x64 the first six integer arguments go in registers: rdi, rsi, rdx, rcx, r8, r9. The return value comes back in rax.
Extra arguments spill onto the stack.
; foo(1, 2, 3)
mov edi, 1
mov esi, 2
mov edx, 3
call fooMicrosoft x64 Convention
Windows x64 uses different registers: the first four arguments go in rcx, rdx, r8, r9, and the caller reserves 32 bytes of shadow space.
Recognizing the OS tells you which mapping to apply when reading arguments.
; Windows: bar(a, b)
mov rcx, a
mov rdx, b
sub rsp, 0x28 ; shadow space + alignment
call barCaller-Saved vs Callee-Saved
Some registers may be clobbered by a call (caller-saved), others must be preserved (callee-saved).
Seeing a function push rbx, rbp, and r12-r15 in its prologue is a strong hint about which registers it intends to use.
Reading Arguments in Practice
When you land in a function, mapping registers to arguments lets you label them. If the code reads rdi first on Linux, that is argument one.
This is how raw disassembly becomes readable pseudocode like send(sock, buf, len).
Stack-Passed Arguments
When a function has more arguments than the convention allows in registers, the extras are pushed onto the stack by the caller. The callee reads them at positive offsets from RBP, like [rbp+0x10].
Spotting these accesses helps you recover the full argument list.
; 7th System V argument
mov rax, [rbp+0x10]Quick Check
Under the System V AMD64 convention, which register holds the FIRST integer argument?
Recap
You can now decode function calls at the metal level:
- Stack grows down; RSP tops it, RBP anchors the frame
- Prologue/epilogue set up and tear down frames
- Calling conventions map registers to arguments (System V vs Microsoft x64)
This turns opaque disassembly into recognizable function signatures.
คำถามที่พบบ่อย
บทเรียน “สแตกและรูปแบบการเรียกใช้” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “สแตกและรูปแบบการเรียกใช้” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Reverse Engineering & Binary Analysis Basics ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Reverse Engineering & Binary Analysis Basics มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “สแตกและรูปแบบการเรียกใช้”
เจาะลึกวิธีที่ฟังก์ชันส่งอาร์กิวเมนต์ ส่งคืนค่า และจัดการเฟรมสแตก ซึ่งเป็นความรู้ที่ช่วยให้อ่านโค้ดที่แยกกลับจากไบนารีได้ คุณปฏิบัติ Reverse Engineering & Binary Analysis Basics ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Reverse Engineering & Binary Analysis Basics หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Reverse Engineering & Binary Analysis Basics บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “สแตกและรูปแบบการเรียกใช้” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Reverse Engineering & Binary Analysis Basics นี้ได้ไหม
ได้ บทเรียน Reverse Engineering & Binary Analysis Basics ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- พื้นฐานภาษาแอสเซมบลี x86/x64
- รีจิสเตอร์และการดำเนินการกับหน่วยความจำ
- การควบคุมลำดับการทำงานและการเรียกฟังก์ชัน
- สแตกและรูปแบบการเรียกใช้