Skip to content

Commit

Permalink
elf: Add phdr permission dump
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Nov 24, 2023
1 parent 5efeb05 commit 1bb0745
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 23 deletions.
16 changes: 12 additions & 4 deletions app/dump/elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,21 @@ void dump_elf_phdr(adbg_object_t *o) {
Elf32_Phdr *phdr = adbg_object_elf_phdr32(o, i);
with (phdr) {
dprint_u32("p_type", p_type, adbg_object_elf_pt_string(p_type));
dprint_x32("p_flags", p_flags);
dprint_x32("p_offset", p_offset);
dprint_x32("p_vaddr", p_vaddr);
dprint_x32("p_paddr", p_paddr);
dprint_x32("p_filesz", p_filesz);
dprint_x32("p_memsz", p_memsz);
dprint_flags32("p_flags", p_flags,
"PF_R".ptr, ELF_PF_R,
"PF_W".ptr, ELF_PF_W,
"PF_X".ptr, ELF_PF_X,
null);
dprint_x32("p_align", p_align);
}

//TODO: coredump
// if (p_type == ELF_PT_NOTE)
// if (p_type == ELF_PT_NOTE && p_pflags == 0)
// Elf32_Nhdr (like NT_X86_XSTATE)
}
break;
Expand All @@ -170,7 +174,11 @@ void dump_elf_phdr(adbg_object_t *o) {
Elf64_Phdr *phdr = adbg_object_elf_phdr64(o, i);
with (phdr) {
dprint_u32("p_type", p_type, adbg_object_elf_pt_string(p_type));
dprint_x32("p_flags", p_flags);
dprint_flags32("p_flags", p_flags,
"PF_R".ptr, ELF_PF_R,
"PF_W".ptr, ELF_PF_W,
"PF_X".ptr, ELF_PF_X,
null);
dprint_x64("p_offset", p_offset);
dprint_x64("p_vaddr", p_vaddr);
dprint_x64("p_paddr", p_paddr);
Expand All @@ -180,7 +188,7 @@ void dump_elf_phdr(adbg_object_t *o) {
}

//TODO: coredump
// if (p_type == ELF_PT_NOTE)
// if (p_type == ELF_PT_NOTE && p_pflags == 0)
// Elf32_Nhdr (like NT_X86_XSTATE)
}
break;
Expand Down
74 changes: 55 additions & 19 deletions src/adbg/v2/object/format/elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,6 @@ enum ELF_ET_HIOS = 0xFEFF; /// OS-specific
enum ELF_ET_LOPROC = 0xFF00; /// Processor-specific
enum ELF_ET_HIPROC = 0xFFFF; /// Processor-specific

// Program segment header values

enum ELF_PT_NULL = 0;
enum ELF_PT_LOAD = 1;
enum ELF_PT_DYNAMIC = 2;
enum ELF_PT_INTERP = 3;
enum ELF_PT_NOTE = 4;
enum ELF_PT_SHLIB = 5;
enum ELF_PT_PHDR = 6;
enum ELF_PT_TLS = 7; /// Thread local storage segment
enum ELF_PT_LOOS = 0x60000000; /// OS-specific
enum ELF_PT_HIOS = 0x6fffffff; /// OS-specific
enum ELF_PT_LOPROC = 0x70000000;
enum ELF_PT_HIPROC = 0x7fffffff;
enum ELF_PT_GNU_EH_FRAME = (ELF_PT_LOOS + 0x474e550);
enum ELF_PT_GNU_STACK = (ELF_PT_LOOS + 0x474e551);
enum ELF_PT_GNU_RELRO = (ELF_PT_LOOS + 0x474e552);
enum ELF_PT_GNU_PROPERTY = (ELF_PT_LOOS + 0x474e553);

// ELF Machine values
// FatELF also uses this
Expand Down Expand Up @@ -351,6 +333,60 @@ enum ELF_EF_SPARCV9_TSO = 0x0; /// Total Store Ordering
enum ELF_EF_SPARCV9_PSO = 0x1; /// Partial Store Ordering
enum ELF_EF_SPARCV9_RMO = 0x2; /// Relaxed Memory Ordering

// Program segment header values

enum ELF_PT_NULL = 0;
enum ELF_PT_LOAD = 1;
enum ELF_PT_DYNAMIC = 2;
enum ELF_PT_INTERP = 3;
enum ELF_PT_NOTE = 4;
enum ELF_PT_SHLIB = 5;
enum ELF_PT_PHDR = 6;
enum ELF_PT_TLS = 7; /// Thread local storage segment
enum ELF_PT_LOOS = 0x60000000; /// OS-specific
enum ELF_PT_HIOS = 0x6fffffff; /// OS-specific
enum ELF_PT_LOPROC = 0x70000000;
enum ELF_PT_HIPROC = 0x7fffffff;
enum ELF_PT_GNU_EH_FRAME = (ELF_PT_LOOS + 0x474e550);
enum ELF_PT_GNU_STACK = (ELF_PT_LOOS + 0x474e551);
enum ELF_PT_GNU_RELRO = (ELF_PT_LOOS + 0x474e552);
enum ELF_PT_GNU_PROPERTY = (ELF_PT_LOOS + 0x474e553);

enum ELF_PF_R = 4; /// p_flags value for Read permission
enum ELF_PF_W = 2; /// p_flags value for Write permission
enum ELF_PF_X = 1; /// p_flags value for Execute permission

// ELF Relocation types
enum R_386_NONE = 0;
enum R_386_32 = 1;
enum R_386_PC32 = 2;
enum R_386_GOT32 = 3;
enum R_386_PLT32 = 4;
enum R_386_COPY = 5;
enum R_386_GLOB_DAT = 6;
enum R_386_JMP_SLOT = 7;
enum R_386_RELATIVE = 8;
enum R_386_GOTOFF = 9;
enum R_386_GOTPC = 10;
enum R_386_NUM = 11;
enum R_X86_64_NONE = 0; /// No reloc
enum R_X86_64_64 = 1; /// Direct 64 bit
enum R_X86_64_PC32 = 2; /// PC relative 32 bit signed
enum R_X86_64_GOT32 = 3; /// 32 bit GOT entry
enum R_X86_64_PLT32 = 4; /// 32 bit PLT address
enum R_X86_64_COPY = 5; /// Copy symbol at runtime
enum R_X86_64_GLOB_DAT = 6; /// Create GOT entry
enum R_X86_64_JUMP_SLOT = 7; /// Create PLT entry
enum R_X86_64_RELATIVE = 8; /// Adjust by program base
enum R_X86_64_GOTPCREL = 9; /// 32 bit signed pc relative offset to GOT
enum R_X86_64_32 = 10; /// Direct 32 bit zero extended
enum R_X86_64_32S = 11; /// Direct 32 bit sign extended
enum R_X86_64_16 = 12; /// Direct 16 bit zero extended
enum R_X86_64_PC16 = 13; /// 16 bit sign extended pc relative
enum R_X86_64_8 = 14; /// Direct 8 bit sign extended
enum R_X86_64_PC8 = 15; /// 8 bit sign extended pc relative
enum R_X86_64_PC64 = 24; /// Place relative 64-bit signed

// Section type values

enum ELF_SHT_NULL = 0; /// Inactive
Expand Down Expand Up @@ -508,7 +544,7 @@ struct Elf32_Phdr {
Elf32_Addr p_paddr; /// Segment physical address
Elf32_Word p_filesz; /// Segment size in file
Elf32_Word p_memsz; /// Segment size in memory
Elf32_Word p_flags;
Elf32_Word p_flags; /// Segment flags
Elf32_Word p_align; /// Segment alignment, file & memory
}

Expand Down

0 comments on commit 1bb0745

Please sign in to comment.