elf.h

// http://en.wikipedia.org/wiki/Executable_and_Linkable_Format
// http://www.ouah.org/RevEng/x430.htm

// Format of an ELF executable file

#define ELF_MAGIC 0x464C457FU  // "\x7FELF" in little endian

// File header
struct elfhdr {
  uint magic;  // must equal ELF_MAGIC
  uchar elf[12];
  ushort type;  // 1, 2, 3, 4 specify whether the object is relocatable, executable, shared, or core, respectively
  ushort machine;  // Specifies target instruction set architecture.
  uint version;  // Set to 1 for the original version of ELF
  uint entry;  // This is the memory address of the entry point from where the process starts executing. This field is either 32 or 64 bits long depending on the format defined earlier
  uint phoff;  // Points to the start of the program header table. It usually follows the file header immediately making the offset 0x40 for 64-bit ELF executables
  uint shoff;  // Points to the start of the section header table
  uint flags;  // Interpretation of this field depends on the target architecture
  ushort ehsize;  // Contains the size of this header, normally 64 bytes for 64-bit and 52 for 32-bit format
  ushort phentsize;  // Contains the size of a program header table entry
  ushort phnum;  // Contains the number of entries in the program header table
  ushort shentsize;  // Contains the size of a section header table entry
  ushort shnum;  // Contains the number of entries in the section header table
  ushort shstrndx;  // Contains index of the section header table entry that contains the section names
};

//  應該是program segment header,不知爲什麼寫得是program section header? 

// Program section header
struct proghdr {
  uint type;  // Segment type
  uint off;  // Segment file offset
  uint vaddr;  // Segment virtual address
  uint paddr;  // Segment physical address
  uint filesz;  // Segment size in file
  uint memsz;  // Segment size in memory
  uint flags;  // Segment flags
  uint align;  // Segment alignment
};

// Values for Proghdr type
#define ELF_PROG_LOAD           1

// Flag bits for Proghdr flags
#define ELF_PROG_FLAG_EXEC      1
#define ELF_PROG_FLAG_WRITE     2
#define ELF_PROG_FLAG_READ      4

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章