return 0;
}
-static int pakfire_elf_open_elf(struct pakfire_elf* self) {
+static int pakfire_elf_open_elf(pakfire_elf* self) {
GElf_Ehdr* ehdr = NULL;
int r;
return 0;
}
-static void pakfire_elf_free(struct pakfire_elf* self) {
+static void pakfire_elf_free(pakfire_elf* self) {
if (self->build_id)
free(self->build_id);
if (self->elf)
free(self);
}
-int pakfire_elf_open(struct pakfire_elf** elf,
+int pakfire_elf_open(pakfire_elf** elf,
pakfire_ctx* ctx, const char* path, int fd) {
- struct pakfire_elf* self = NULL;
+ pakfire_elf* self = NULL;
int r;
// Require a valid file descriptor
return r;
}
-int pakfire_elf_open_file(struct pakfire_elf** elf,
+int pakfire_elf_open_file(pakfire_elf** elf,
pakfire_ctx* ctx, struct pakfire_file* file) {
const char* path = NULL;
int fd = -EBADF;
return r;
}
-struct pakfire_elf* pakfire_elf_ref(struct pakfire_elf* self) {
+pakfire_elf* pakfire_elf_ref(pakfire_elf* self) {
self->nrefs++;
return self;
}
-struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self) {
+pakfire_elf* pakfire_elf_unref(pakfire_elf* self) {
if (--self->nrefs > 0)
return self;
return NULL;
}
-const char* pakfire_elf_path(struct pakfire_elf* self) {
+const char* pakfire_elf_path(pakfire_elf* self) {
return self->path;
}
-int pakfire_elf_type(struct pakfire_elf* self) {
+int pakfire_elf_type(pakfire_elf* self) {
return self->ehdr.e_type;
}
-int pakfire_elf_machine(struct pakfire_elf* self) {
+int pakfire_elf_machine(pakfire_elf* self) {
return self->ehdr.e_machine;
}
-int pakfire_elf_is_elf64(struct pakfire_elf* self) {
+int pakfire_elf_is_elf64(pakfire_elf* self) {
return self->ehdr.e_ident[EI_CLASS] = ELFCLASS64;
}
-int pakfire_elf_endianess(struct pakfire_elf* self) {
+int pakfire_elf_endianess(pakfire_elf* self) {
return self->ehdr.e_ident[EI_DATA];
}
-const char* pakfire_elf_build_id(struct pakfire_elf* self) {
+const char* pakfire_elf_build_id(pakfire_elf* self) {
const void* buffer = NULL;
ssize_t length;
return self->build_id;
}
-const char* pakfire_elf_debuglink(struct pakfire_elf* self) {
+const char* pakfire_elf_debuglink(pakfire_elf* self) {
GElf_Word crc32;
// Fetch the debug link
}
typedef int (*pakfire_elf_foreach_program_header_callback)
- (struct pakfire_elf* self, const GElf_Phdr* phdr, void* data);
+ (pakfire_elf* self, const GElf_Phdr* phdr, void* data);
-static int pakfire_elf_foreach_program_header(struct pakfire_elf* self,
+static int pakfire_elf_foreach_program_header(pakfire_elf* self,
pakfire_elf_foreach_program_header_callback callback, void* data) {
GElf_Phdr phdr = {};
int r = 0;
return r;
}
-static int pakfire_elf_get_section(struct pakfire_elf* self,
+static int pakfire_elf_get_section(pakfire_elf* self,
const Elf64_Word type, const char* name, Elf_Scn** section, GElf_Shdr* header, Elf_Data** data) {
const char* sname = NULL;
Elf_Scn* s = NULL;
return 1;
}
-typedef int (*pakfire_elf_foreach_section_callback)(struct pakfire_elf* self,
+typedef int (*pakfire_elf_foreach_section_callback)(pakfire_elf* self,
Elf_Scn* section, const GElf_Shdr* shdr, void* data);
-static int pakfire_elf_foreach_section(struct pakfire_elf* self,
+static int pakfire_elf_foreach_section(pakfire_elf* self,
const Elf64_Word type, pakfire_elf_foreach_section_callback callback, void* data) {
Elf_Scn* section = NULL;
GElf_Shdr shdr = {};
}
typedef int (*pakfire_elf_dyn_walk_callback)
- (struct pakfire_elf* self, const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data);
+ (pakfire_elf* self, const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data);
-static int pakfire_elf_dyn_walk(struct pakfire_elf* self,
+static int pakfire_elf_dyn_walk(pakfire_elf* self,
pakfire_elf_dyn_walk_callback callback, void* data) {
Elf_Scn* dynamic = NULL;
GElf_Shdr shdr;
}
static int pakfire_elf_fetch_interpreter(
- struct pakfire_elf* self, const GElf_Phdr* phdr, void* data) {
+ pakfire_elf* self, const GElf_Phdr* phdr, void* data) {
Elf_Data* chunk = NULL;
switch (phdr->p_type) {
return 0;
}
-const char* pakfire_elf_interpreter(struct pakfire_elf* self) {
+const char* pakfire_elf_interpreter(pakfire_elf* self) {
int r;
// Fetch the interpreter if not available
return self->interpreter;
}
-static int pakfire_elf_fetch_soname(struct pakfire_elf* self,
+static int pakfire_elf_fetch_soname(pakfire_elf* self,
const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data) {
switch (dyn->d_tag) {
case DT_SONAME:
return 0;
}
-const char* pakfire_elf_soname(struct pakfire_elf* self) {
+const char* pakfire_elf_soname(pakfire_elf* self) {
int r;
// Fetch the SONAME if not available
return self->soname;
}
-int pakfire_elf_is_pie(struct pakfire_elf* self) {
+int pakfire_elf_is_pie(pakfire_elf* self) {
switch (pakfire_elf_type(self)) {
// Shared Object files are good
case ET_DYN:
return 0;
}
-int pakfire_elf_has_ssp(struct pakfire_elf* self) {
+int pakfire_elf_has_ssp(pakfire_elf* self) {
GElf_Sym symbol = {};
int r;
}
static int pakfire_elf_check_execstack(
- struct pakfire_elf* self, const GElf_Phdr* phdr, void* data) {
+ pakfire_elf* self, const GElf_Phdr* phdr, void* data) {
switch (phdr->p_type) {
case PT_GNU_STACK:
DEBUG(self->ctx,
return 0;
}
-int pakfire_elf_has_execstack(struct pakfire_elf* self) {
+int pakfire_elf_has_execstack(pakfire_elf* self) {
return pakfire_elf_foreach_program_header(self, pakfire_elf_check_execstack, NULL);
}
-static int pakfire_elf_has_bind_now(struct pakfire_elf* self,
+static int pakfire_elf_has_bind_now(pakfire_elf* self,
const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data) {
switch (dyn->d_tag) {
case DT_BIND_NOW:
return 0;
}
-int pakfire_elf_is_fully_relro(struct pakfire_elf* self) {
+int pakfire_elf_is_fully_relro(pakfire_elf* self) {
return pakfire_elf_dyn_walk(self, pakfire_elf_has_bind_now, NULL);
}
-int pakfire_elf_is_partially_relro(struct pakfire_elf* self) {
+int pakfire_elf_is_partially_relro(pakfire_elf* self) {
GElf_Phdr phdr;
// Walk through all program headers
return bytes;
}
-static int pakfire_elf_check_cf_protection_aarch64(struct pakfire_elf* self,
+static int pakfire_elf_check_cf_protection_aarch64(pakfire_elf* self,
const int endianess, const uint32_t type, const char* payload) {
int flags = 0;
return flags;
}
-static int pakfire_elf_check_cf_protection_riscv64(struct pakfire_elf* self,
+static int pakfire_elf_check_cf_protection_riscv64(pakfire_elf* self,
const int endianess, const uint32_t type, const char* payload) {
// There is nothing to do here
return 0;
}
-static int pakfire_elf_check_cf_protection_x86_64(struct pakfire_elf* self,
+static int pakfire_elf_check_cf_protection_x86_64(pakfire_elf* self,
const int endianess, const uint32_t type, const char* payload) {
int flags = 0;
return flags;
}
-static int pakfire_elf_check_cf_protection(struct pakfire_elf* self,
+static int pakfire_elf_check_cf_protection(pakfire_elf* self,
Elf_Scn* section, const GElf_Shdr* shdr, void* data) {
GElf_Nhdr nhdr = {};
size_t offset = 0;
return 0;
}
-int pakfire_elf_has_cf_protection(struct pakfire_elf* self) {
+int pakfire_elf_has_cf_protection(pakfire_elf* self) {
return pakfire_elf_foreach_section(self, SHT_NOTE, pakfire_elf_check_cf_protection, NULL);
}
-static int pakfire_elf_check_runpath(struct pakfire_elf* self,
+static int pakfire_elf_check_runpath(pakfire_elf* self,
const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data) {
const char* runpath = NULL;
const char* value = NULL;
return r;
}
-int pakfire_elf_has_runpaths(struct pakfire_elf* self, char*** runpaths) {
+int pakfire_elf_has_runpaths(pakfire_elf* self, char*** runpaths) {
return pakfire_elf_dyn_walk(self, pakfire_elf_check_runpath, runpaths);
}
-static int __pakfire_elf_is_stripped(struct pakfire_elf* self,
+static int __pakfire_elf_is_stripped(pakfire_elf* self,
Elf_Scn* section, const Elf64_Shdr* shdr, void* data) {
// Fetch the section name
const char* name = elf_strptr(self->elf, self->shstrndx, shdr->sh_name);
return 0;
}
-int pakfire_elf_is_stripped(struct pakfire_elf* self) {
+int pakfire_elf_is_stripped(pakfire_elf* self) {
int r;
switch (pakfire_elf_type(self)) {
return 1;
}
-static int pakfire_elf_find_provides(struct pakfire_elf* self,
+static int pakfire_elf_find_provides(pakfire_elf* self,
Elf_Scn* section, const GElf_Shdr* shdr, void* data) {
GElf_Verdaux verdaux = {};
GElf_Verdef verdef = {};
return 0;
}
-int pakfire_elf_provides(struct pakfire_elf* self, char*** provides) {
+int pakfire_elf_provides(pakfire_elf* self, char*** provides) {
int r;
// Fetch the soname
return pakfire_elf_foreach_section(self, SHT_GNU_verdef, pakfire_elf_find_provides, provides);
}
-static int pakfire_elf_find_requires(struct pakfire_elf* self,
+static int pakfire_elf_find_requires(pakfire_elf* self,
Elf_Scn* section, const GElf_Shdr* shdr, void* data) {
GElf_Vernaux vernaux = {};
GElf_Verneed verneed = {};
return 0;
}
-int pakfire_elf_requires(struct pakfire_elf* self, char*** requires) {
+int pakfire_elf_requires(pakfire_elf* self, char*** requires) {
return pakfire_elf_foreach_section(self, SHT_NULL, pakfire_elf_find_requires, requires);
}
#define DWARF_E_NO_DWARF 6
#endif
-int pakfire_elf_foreach_source_file(struct pakfire_elf* self,
+int pakfire_elf_foreach_source_file(pakfire_elf* self,
pakfire_elf_foreach_source_file_callback callback, void* data) {
const char* filename = NULL;
char basename[PATH_MAX];
#ifndef PAKFIRE_ELF_H
#define PAKFIRE_ELF_H
-struct pakfire_elf;
+typedef struct pakfire_elf pakfire_elf;
#include <pakfire/ctx.h>
#include <pakfire/file.h>
-int pakfire_elf_open(struct pakfire_elf** elf,
+int pakfire_elf_open(pakfire_elf** elf,
pakfire_ctx* ctx, const char* path, int fd);
-int pakfire_elf_open_file(struct pakfire_elf** elf,
+int pakfire_elf_open_file(pakfire_elf** elf,
pakfire_ctx* ctx, struct pakfire_file* file);
-struct pakfire_elf* pakfire_elf_ref(struct pakfire_elf* self);
-struct pakfire_elf* pakfire_elf_unref(struct pakfire_elf* self);
+pakfire_elf* pakfire_elf_ref(pakfire_elf* self);
+pakfire_elf* pakfire_elf_unref(pakfire_elf* self);
-const char* pakfire_elf_path(struct pakfire_elf* self);
-int pakfire_elf_type(struct pakfire_elf* self);
-int pakfire_elf_machine(struct pakfire_elf* self);
-int pakfire_elf_is_elf64(struct pakfire_elf* self);
-int pakfire_elf_endianess(struct pakfire_elf* self);
-const char* pakfire_elf_build_id(struct pakfire_elf* self);
-const char* pakfire_elf_debuglink(struct pakfire_elf* self);
-const char* pakfire_elf_interpreter(struct pakfire_elf* elf);
-const char* pakfire_elf_soname(struct pakfire_elf* self);
+const char* pakfire_elf_path(pakfire_elf* self);
+int pakfire_elf_type(pakfire_elf* self);
+int pakfire_elf_machine(pakfire_elf* self);
+int pakfire_elf_is_elf64(pakfire_elf* self);
+int pakfire_elf_endianess(pakfire_elf* self);
+const char* pakfire_elf_build_id(pakfire_elf* self);
+const char* pakfire_elf_debuglink(pakfire_elf* self);
+const char* pakfire_elf_interpreter(pakfire_elf* elf);
+const char* pakfire_elf_soname(pakfire_elf* self);
-int pakfire_elf_is_pie(struct pakfire_elf* self);
-int pakfire_elf_has_ssp(struct pakfire_elf* self);
-int pakfire_elf_has_execstack(struct pakfire_elf* self);
-int pakfire_elf_is_fully_relro(struct pakfire_elf* self);
-int pakfire_elf_is_partially_relro(struct pakfire_elf* self);
-int pakfire_elf_has_cf_protection(struct pakfire_elf* self);
-int pakfire_elf_has_runpaths(struct pakfire_elf* self, char*** runpaths);
-int pakfire_elf_is_stripped(struct pakfire_elf* self);
+int pakfire_elf_is_pie(pakfire_elf* self);
+int pakfire_elf_has_ssp(pakfire_elf* self);
+int pakfire_elf_has_execstack(pakfire_elf* self);
+int pakfire_elf_is_fully_relro(pakfire_elf* self);
+int pakfire_elf_is_partially_relro(pakfire_elf* self);
+int pakfire_elf_has_cf_protection(pakfire_elf* self);
+int pakfire_elf_has_runpaths(pakfire_elf* self, char*** runpaths);
+int pakfire_elf_is_stripped(pakfire_elf* self);
// Return bitmap for pakfire_elf_has_cf_protection()
enum {
};
// Dependencies
-int pakfire_elf_provides(struct pakfire_elf* self, char*** provides);
-int pakfire_elf_requires(struct pakfire_elf* self, char*** requires);
+int pakfire_elf_provides(pakfire_elf* self, char*** provides);
+int pakfire_elf_requires(pakfire_elf* self, char*** requires);
// Source Files
typedef int (*pakfire_elf_foreach_source_file_callback)
- (pakfire_ctx* ctx, struct pakfire_elf* elf, const char* filename, void* data);
+ (pakfire_ctx* ctx, pakfire_elf* elf, const char* filename, void* data);
-int pakfire_elf_foreach_source_file(struct pakfire_elf* self,
+int pakfire_elf_foreach_source_file(pakfire_elf* self,
pakfire_elf_foreach_source_file_callback callback, void* data);
#endif /* PAKFIRE_ELF_H */