你所不知道的C語言:函式呼叫篇 === ###### 2019.08.15 *Copyright © 2019 by srhuang*  [影片](https://youtu.be/X5hOAFCxOTA) [講義](http://hackfoldr.org/dykc/https%253A%252F%252Fhackmd.io%252Fs%252FSJ6hRj-zg) Original by [jserv](http://wiki.csie.ncku.edu.tw/User/jserv) --- ## Programming Language * C 語言的發展:https://youtu.be/X5hOAFCxOTA?t=22 * 早期 C 語言 (1972-1973) -> K&R C (1976-1979) -> ANSI C (1983-1989) -> ISO。 * History of C:https://youtu.be/X5hOAFCxOTA?t=238 * nested function:https://youtu.be/X5hOAFCxOTA?t=405 * C 語言不允許這樣的 nested function,nested function 是編譯器的擴展。 * 應用:callback function。 * uplevel reference。 ## 再論 Function * 数学定义的 Function:https://youtu.be/X5hOAFCxOTA?t=792 * C--:https://youtu.be/X5hOAFCxOTA?t=1104 * 通常來開發 C語言編譯器。 * C is a poor choice for functional languages. ## Process 和 C 程式的關聯 * 前言介紹:https://youtu.be/X5hOAFCxOTA?t=1332 * 從執行時期來觀察 function call。 * MMIO (memory mapped I/O):將I/O的port或memory 映射(mapping)到記憶體位址(memory address)上。 * The Internals of “Hello World” Program:https://youtu.be/X5hOAFCxOTA?t=1666 * Computer Architecture. * SMP and Multi-core Processor. * Software Architecture. * Memory Management Unit. * Paging. * Address Space Isolation. * Symbol Address. * Relocation. * Creation of Process. * Program Memory Layout. * Stack Frame. * 簡單複習:https://youtu.be/X5hOAFCxOTA?t=3035 * sbrk:change the location of the program break, which defines the end of the process's data segment. * 觀察 Process 的記憶體分佈:https://youtu.be/X5hOAFCxOTA?t=3660 * sudo cat /proc/1/maps ## 從遞迴學習 function call * infinite.c:https://youtu.be/X5hOAFCxOTA?t=4087 * [Function calls in C: a practical example](http://gghh.name/dibtp/2015/11/11/function-calls-in-c-practical-example.html):https://youtu.be/X5hOAFCxOTA?t=4667 * Stack Frame Layout. * Our sample program: Greatest Common Divisor. * ROP (Return Oriented Programming):https://youtu.be/X5hOAFCxOTA?t=5373 * Just-in-Time Compiler. * 執行時期進行修補。 * Stack Pointer and Frame Pointer:https://youtu.be/X5hOAFCxOTA?t=5684 * return value 通常放在暫存器中。 ## stack-based buffer overflow * CVE:https://youtu.be/X5hOAFCxOTA?t=5822 * 弱點分析資料庫。 * Critical glibc Flaw Puts Linux Machines and Apps at Risk:https://youtu.be/X5hOAFCxOTA?t=5964 * gdb-example.c:https://youtu.be/X5hOAFCxOTA?t=6246 ## 藏在 Heap 裡的細節 * Free 詳細分析:https://youtu.be/X5hOAFCxOTA?t=6573 * double free. * man free:If ptr is NULL, no operation is performed. * 為什麼 glibc 可以偵測出上述程式的 “double free or corruption” 呢?:https://hackmd.io/@ofAlpaca/r1SEboxKX?type=view * malloc/free:https://youtu.be/X5hOAFCxOTA?t=7284 * gdb -q `which gdb` * malloc_stats() 和 malloc_info() 這兩個函式,可顯示 process 的 heap 資訊。 * malloc_trim():release free memory from the heap。 * malloc 閒談:https://youtu.be/X5hOAFCxOTA?t=7617 ## 快速回顧:https://youtu.be/X5hOAFCxOTA?t=7856 * 執行 gcd 程式。 ## 參考資料:https://youtu.be/X5hOAFCxOTA?t=8514 ## Q&A:https://youtu.be/X5hOAFCxOTA?t=8694 * RAII (Resource acquisition is initialization) ## 總結:https://youtu.be/X5hOAFCxOTA?t=9063
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up