기본 개념
VA & RVA
- VA(Virtual Address): 가상 메모리 내 절대 주소
- RVA(Relative Virtual Address): 가상 메모리 내 ImageBase로부터의 상대 주소
<aside>
💡 VA = ImageBase + RVA
</aside>
- 위치 표현
- File 상태일 때: offset
- 메모리 적재된 상태일 때: VA
PE Loader
- PE 파일을 실행하기 위한 작업을 하는 모듈
- 역할
- 프로세스 생성 후 파일을 메모리에 로딩
- EIP 레지스터 값을 ImageBase + AddressOfEntryPoint 값으로 설정
- 파일 실행에 필요한 dll 파일을 메모리에 로딩 (+ DLL Relocation)
- IAT에 라이브러리 내 함수의 실제 메모리 상 주소 기입
DLL Relocation
- 로딩하고자 하는 위치의 메모리 공간이 사용 중일 때 다른 위치에 로드되도록 하는 것
- DLL 파일은 DLL Relocation 때문에 파일 내 기재된 ImageBase와 다른 위치에 로드될 수 있다.
- 일반적인 DLL 파일에서 많이 발생한다.
- Windows 시스템 DLL 파일(kernel32, user32, gdi32 등)은 자신만의 고유한 ImageBase를 가지고 있어 DLL Relocation이 발생하지 않는다.
- EXE 파일은 자신만의 가상 메모리 공간을 가지기 때문에 파일 내 기재된 ImageBase에 정확히 로드된다.