GitXplorerGitXplorer
0

libelf

public
48 stars
12 forks
0 issues

Commits

List of commits on branch main.
Unverified
93999bc9585941411cbd5113a62ac8a6eb8cb8c4

move from Travis CI to GitHub Actions

00intro committed 3 years ago
Unverified
86484cad93800305965391a7a2713a0fee7ef09d

handle ET_DYN and ET_CORE object file types

00intro committed 7 years ago
Unverified
341f974f7a9ce695c679db26aae034c9fde2c15f

fix overflowed return value

00intro committed 7 years ago
Unverified
868203893399b28887978a73065136199717a577

fix unintended sign extension

00intro committed 7 years ago
Unverified
8151723a1520a885091a9c9c9f85abf654b8c6aa

add Coverity Scan to Travis CI

00intro committed 7 years ago
Unverified
5c2bbfe59890ef7486f9234a5f1fd2044873aed1

check fseek return value

00intro committed 7 years ago

README

The README file for this repository.

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 Identification */
	uint8_t		class;		/* File class */
	uint8_t		data;		/* Data encoding */
	uint8_t		elfversion;	/* File version */
	uint8_t		osabi;		/* Operating system/ABI identification */
	uint8_t		abiversion;	/* ABI version */

	/* ELF Header */
	uint16_t	type;
	uint16_t	machine;
	uint32_t	version;
	uint64_t	entry;
	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

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

/* Print */
void printelfhdr(Fhdr *fp);

/* String */
char* elfclass(uint8_t class);
char* elfdata(uint8_t data);
char* elfosabi(uint8_t osabi);
char* elftype(uint16_t type);
char* elfmachine(uint16_t machine);
char* elfversion(uint8_t version);

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);