카테고리 없음

ELF 프로그램 헤더

rmagur1203 2021. 6. 2. 05:14

프로그램 헤더

: 프로그램 로딩에 필요한 바이너리 세그먼트를 정의합니다.

 

세그먼트

: 디스크에 저장된 실행파일이 커널에 의해 로드되는 과정에서 어떤 메모리 구조로 매핑될 것인지

 

p_type(0x00~0x04)

세그먼트 유형을 식별합니다.

 

ISA
0x00 특정 명령어 세트 없음
0x01 AT & T WE 32100
0x02 SPARC
0x03 x86
0x04 Motorola 68000 (M68k)
0x05 Motorola 88000 (M88k)
0x06 인텔 MCU
0x07 인텔 80860
0x08 MIPS
0x09 IBM_System / 370
0x0A MIPS RS3000 리틀 엔디안
0x0B-0x0D 향후 사용을 위해 예약 됨
0x0E Hewlett-Packard PA-RISC
0x0F 향후 사용을 위해 예약 됨
0x13 인텔 80960
0x14 PowerPC
0x15 PowerPC (64 비트)
0x16 S390x를 포함한 S390
0x17 IBM SPU / SPC
0x18-0x23 향후 사용을 위해 예약 됨
0x24 NEC V800
0x25 Fujitsu FR20
0x26 TRW RH-32
0x27 Motorola RCE
0x28 ARM (최대 ARMv7 / Aarch32)
0x29 디지털 알파
0x2A SuperH
0x2B SPARC 버전 9
0x2C Siemens TriCore 임베디드 프로세서
0x2D Argonaut RISC 코어
0x2E 히타치 H8 / 300
0x2F 히타치 H8 / 300H
0x30 히타치 H8S
0x31 히타치 H8 / 500
0x32 IA-64
0x33 스탠포드 MIPS-X
0x34 Motorola ColdFire
0x35 Motorola M68HC12
0x36 Fujitsu MMA 멀티미디어 가속기
0x37 지멘스 PCP
0x38 소니 nCPU 임베디드 RISC 프로세서
0x39 Denso NDR1 마이크로 프로세서
0x3A Motorola Star * Core 프로세서
0x3B Toyota ME16 프로세서
0x3C STMicroelectronics ST100 프로세서
0x3D Advanced Logic Corp. TinyJ 임베디드 프로세서 제품군
0x3E AMD x86-64
0x8C TMS320C6000 제품군
0xB7 ARM 64 비트 (ARMv8 / Aarch64)
0xF3 RISC-V
0xF7 버클리 패킷 필터
0x101 WDC 65C816

p_flags(0x04~0x08)

세그먼트 종속 플래그 (64 비트 구조의 위치).

p_offset (0x04~0x08|0x08~0x10)

파일 이미지에서 세그먼트의 오프셋.

 

p_vaddr (0x08~0C|0x10~0x18)

메모리에있는 세그먼트의 가상 주소입니다.

 

p_paddr (0x0C~0x10|0x18~0x20)

물리적 주소가 관련된 시스템에서 세그먼트의 물리적 주소 용으로 예약되어 있습니다.

 

p_filesz (0x10~0x14|0x20~0x28)

파일 이미지에있는 세그먼트의 크기 (바이트)입니다. 0 일 수 있습니다.

 

p_memsz (0x14~0x18|0x28~0x30)

메모리에있는 세그먼트의 크기 (바이트)입니다. 0 일 수도 있습니다.

 

p_flags (0x18~0x1C)

세그먼트 종속 플래그 (32 비트 구조의 위치).

 

p_align (0x1C~0x20|0x30~0x38)

메모리 및 파일에서 세그먼트가 정렬되는 값

 

헤더의 끝(0x20|0x38)

 

PLT ( Procedure Linkage Table )

실제 호출 코드를 담고 있는 테이블로서, 해당 내용을 참조하여 "_dl_runtime_resolve"가 수행되고, 실제 시스템

라이브러리 호출이 이루어지게 된다.

 => 쉽게 말하면 외부 라이브러리를 "연결"해주는 함수

 => 실제 바이너리에서도  사용하고자 하는 함수/라이브러리 주소 대신 PLT를 호출

 

 

GOT ( Global Offset Table )

PLT가 참조하는 테이블로써 프로시져들의 주소가 있다. PLT가 어떤 외부 프로시져를 호출할 때 이 GOT를

참조해서 해당 주소로 분기된다.

 => PLT 함수들은 GOT 라는 테이블의 주소로 분기한다.

 => GOT는 외부 라이브러리의 함수/변수의 주소를 저장한다.

 

섹션헤더란?

: 각 섹션의 속성을 정의한 것

 

Offset Size (bytes) Field Purpose
32-bit 64-bit 32-bit 64-bit
0x00 4 sh_name An offset to a string in the .shstrtab section that represents the name of this section.
0x04 4 sh_type Identifies the type of this header.
Value Name Meaning
0x0 SHT_NULL Section header table entry unused
0x1 SHT_PROGBITS Program data
0x2 SHT_SYMTAB Symbol table
0x3 SHT_STRTAB String table
0x4 SHT_RELA Relocation entries with addends
0x5 SHT_HASH Symbol hash table
0x6 SHT_DYNAMIC Dynamic linking information
0x7 SHT_NOTE Notes
0x8 SHT_NOBITS Program space with no data (bss)
0x9 SHT_REL Relocation entries, no addends
0x0A SHT_SHLIB Reserved
0x0B SHT_DYNSYM Dynamic linker symbol table
0x0E SHT_INIT_ARRAY Array of constructors
0x0F SHT_FINI_ARRAY Array of destructors
0x10 SHT_PREINIT_ARRAY Array of pre-constructors
0x11 SHT_GROUP Section group
0x12 SHT_SYMTAB_SHNDX Extended section indices
0x13 SHT_NUM Number of defined types.
0x60000000 SHT_LOOS Start OS-specific.
... ... ...
0x08 4 8 sh_flags Identifies the attributes of the section.
Value Name Meaning
0x1 SHF_WRITE Writable
0x2 SHF_ALLOC Occupies memory during execution
0x4 SHF_EXECINSTR Executable
0x10 SHF_MERGE Might be merged
0x20 SHF_STRINGS Contains null-terminated strings
0x40 SHF_INFO_LINK 'sh_info' contains SHT index
0x80 SHF_LINK_ORDER Preserve order after combining
0x100 SHF_OS_NONCONFORMING Non-standard OS specific handling required
0x200 SHF_GROUP Section is member of a group
0x400 SHF_TLS Section hold thread-local data
0x0ff00000 SHF_MASKOS OS-specific
0xf0000000 SHF_MASKPROC Processor-specific
0x4000000 SHF_ORDERED Special ordering requirement (Solaris)
0x8000000 SHF_EXCLUDE Section is excluded unless referenced or allocated (Solaris)
0x0C 0x10 4 8 sh_addr Virtual address of the section in memory, for sections that are loaded.
0x10 0x18 4 8 sh_offset Offset of the section in the file image.
0x14 0x20 4 8 sh_size Size in bytes of the section in the file image. May be 0.
0x18 0x28 4 sh_link Contains the section index of an associated section. This field is used for several purposes, depending on the type of section.
0x1C 0x2C 4 sh_info Contains extra information about the section. This field is used for several purposes, depending on the type of section.
0x20 0x30 4 8 sh_addralign Contains the required alignment of the section. This field must be a power of two.
0x24 0x38 4 8 sh_entsize Contains the size, in bytes, of each entry, for sections that contain fixed-size entries. Otherwise, this field contains zero.
0x28 0x40 End of Section Header (size)
728x90