#include <pakfire/ctx.h>
#include <pakfire/elf.h>
#include <pakfire/file.h>
+#include <pakfire/hex.h>
+#include <pakfire/logging.h>
#include <pakfire/string.h>
// libelf
// ELF Header
GElf_Ehdr ehdr;
+
+ // GNU Build ID
+ char* build_id;
};
static int pakfire_elf_init_libelf(struct pakfire_ctx* ctx) {
}
static void pakfire_elf_free(struct pakfire_elf* self) {
+ if (self->build_id)
+ free(self->build_id);
if (self->elf)
elf_end(self->elf);
if (self->fd >= 0)
int pakfire_elf_type(struct pakfire_elf* self) {
return self->ehdr.e_type;
}
+
+const char* pakfire_elf_build_id(struct pakfire_elf* self) {
+ const void* buffer = NULL;
+ ssize_t length;
+
+ if (!self->build_id) {
+ // Extract the GNU Build ID
+ length = dwelf_elf_gnu_build_id(self->elf, &buffer);
+ if (length < 0) {
+ ERROR(self->ctx, "Could not read the GNU Build ID from %s: %s\n",
+ self->path, elf_errmsg(-1));
+ return NULL;
+ }
+
+ // Convert the Build ID to hex
+ self->build_id = __pakfire_hexlify(buffer, length);
+ if (!self->build_id) {
+ ERROR(self->ctx, "Could not convert the Build ID into hex format: %m\n");
+ return NULL;
+ }
+
+ DEBUG(self->ctx, "%s has Build ID %s\n", self->path, self->build_id);
+ }
+
+ return self->build_id;
+}