Go to file
David du Colombier b409e482cf add missing space 2017-07-27 23:13:22 +02:00
.travis.yml move from Drone to Travis CI 2017-03-31 11:13:22 +02:00
LICENSE initial commit 2016-11-21 22:11:53 +01:00
Makefile rename machines.c to str.c 2017-07-27 23:00:42 +02:00
README.md move from Drone to Travis CI 2017-03-31 11:13:22 +02:00
dat.h add missing space 2017-07-27 23:13:22 +02:00
elf.c remove debug prints 2017-07-27 01:32:13 +02:00
elf.h initial commit 2016-11-21 22:11:53 +01:00
fns.h initial commit 2016-11-21 22:11:53 +01:00
print.c add elfmachine function 2017-07-27 23:11:43 +02:00
str.c add elfmachine function 2017-07-27 23:11:43 +02:00

README.md

Build Status Coverity Scan Build Status

libelf

Libelf is a simple library which provides functions to read ELF files.

Headers

#include <stdint.h>
#include <elf.h>

Structures

typedef struct Fhdr Fhdr;

/*
 * Portable ELF file header
 */
struct Fhdr {
	/* Private */
	...

	/* ELF Header */
	uint64_t	phoff;
	uint64_t	shoff;
	uint16_t	ehsize;		/* ELF Header size */
	uint16_t	phentsize;	/* Section Header size */
	uint16_t	phnum;
	uint16_t	shentsize;	/* Program Header size */
	uint16_t	shnum;
	uint16_t	shstrndx;

	/* Section Header */
	uint32_t	name;
	uint64_t	offset;
	uint64_t	size;

	/* String Table */
	uint32_t	strndxsize;	/* String Table Size */
	uint8_t		*strndx;	/* Copy of String Table */
};

Functions

int readelf(FILE *f, Fhdr *fp);
uint8_t* readelfsection(FILE *f, char *name, uint64_t *size, Fhdr *fp);
void freeelf(Fhdr *fp);

Example

Fhdr fhdr;
FILE *f;
uint8_t *buf;
uint64_t len;

f = fopen("/bin/ls", "rb");
if (f == NULL)
	return -1;

buf = readelfsection(f, ".text", &len, &fhdr);
if (buf == NULL)
	return -1;

// ...

freeelf(&fhdr);