Last active
December 10, 2020 15:24
-
-
Save dbwodlf3/c9aab0b3baa00bee4a4d0d2a9f8c3393 to your computer and use it in GitHub Desktop.
SMC Codes in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =============================================================================== | |
| SMC Codes in C | |
| =============================================================================== | |
| C언어를 통하여 만들 수 있는 SMC 코드. | |
| =============================================================================== | |
| 1. 코드 영역을 수정하는 경우. | |
| =============================================================================== | |
| 1.1. PIE 코드의 경우. | |
| address가 결정되지 않았으므로, direct하게 명시하여 메모리를 수정할 수 없다. | |
| 변수(함수, 전역변수, 로컬변수)를 offset으로 활용하여 작성한다. | |
| write_address = offset(변수) + integerValue 으로 나타난다. | |
| 예: (memcpy(main+107, SMC_CODE, 26)); | |
| 1.2. NO-PIE 코드의 경우. | |
| address가 고정적이므로 direct하게 명시하여 메모리를 수정할 수 있다. | |
| write_address = offset + integerValue | |
| write_address = integerValue | |
| 두가지의 경우가 나타날 수 있다. | |
| 예: memcpy(main+107, SMC_CODE, 26); | |
| 예: memcpy(0x4005af, SMC_CODE, 26); | |
| 전자를 PIC SMC 코드라고 하자. => memcpy(main+107, SMC_CODE, 26); | |
| 후자를 NO-PIC SMC 코드라고 하자. => memcpy(0x4005af, SMC_CODE, 26); | |
| =============================================================================== | |
| 2. 데이터를 만들고, 해당 데이터의 주소로 실행흐름이 넘어가는 경우. | |
| =============================================================================== | |
| 주의 1. 컴파일러 키워드가 아니면 C언어에서 Direct하게 jump 명령어를 사용할 수 없다. | |
| 주의 2. 이 때에 C언어에서 PIE 코드와 NO-PIE 코드 여부를 고려할 필요없이 전부 정상적 | |
| 으로 실행된다. | |
| 예: (void(*)()SMC_CODE)(); | |
| 해당 Data를 함수형 포인터로 형변환하여 호출하여 실행한다. | |
| SMC_CODE의 값이 함수 scope에 있다면 stack으로 실행흐름이 넘어간다. | |
| SMC_CODE의 값이 글로벌 scope에 있다면 .data(initalized data) 영역으로 실행흐름이 | |
| 넘어간다. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment