40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
#ifndef CustomElfW
|
|
#include <link.h>
|
|
#define CustomElfW(x) ElfW(x)
|
|
#endif
|
|
|
|
#include <elf.h>
|
|
|
|
#include "log.h"
|
|
#include "elf.h"
|
|
|
|
// Fix ELF Pointers
|
|
void CustomElfW(pad)(unsigned char *out, size_t padding) {
|
|
// Get ELF Header
|
|
CustomElfW(Ehdr) *elf_header = (CustomElfW(Ehdr) *) out;
|
|
|
|
// Fix ELF Program Header Offset
|
|
if (elf_header->e_phoff != 0) {
|
|
elf_header->e_phoff += padding;
|
|
|
|
// Fix ELF Program Headers
|
|
CustomElfW(Phdr) *elf_program_headers = (CustomElfW(Phdr) *) (out + elf_header->e_phoff);
|
|
int elf_program_header_count = elf_header->e_phnum;
|
|
for (int i = 0; i < elf_program_header_count; i++) {
|
|
elf_program_headers[i].p_offset += padding;
|
|
}
|
|
}
|
|
|
|
// Fix ELF Section Header
|
|
if (elf_header->e_shoff != 0) {
|
|
elf_header->e_shoff += padding;
|
|
|
|
// Fix ELF Section Headers
|
|
CustomElfW(Shdr) *elf_section_headers = (CustomElfW(Shdr) *) (out + elf_header->e_shoff);
|
|
int elf_section_header_count = elf_header->e_shnum;
|
|
for (int i = 0; i < elf_section_header_count; i++) {
|
|
elf_section_headers[i].sh_offset += padding;
|
|
}
|
|
}
|
|
}
|