• Stars
    star
    47
  • Rank 604,252 (Top 12 %)
  • Language
    C
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Libelf is a simple library to read ELF files.

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

More Repositories

1

plan9

Plan 9 History, from 2002-12-12 to 2015-01-10. A more complete version of this repository is available on https://github.com/plan9foundation/plan9
C
859
star
2

9hist

History of the Plan 9 kernel (1990 - 2003).
C
123
star
3

wmii

A small, scriptable window manager, with a 9P filesystem interface and an acme-like layout.
C
113
star
4

9legacy

Plan 9 from Bell Labs, with contributions.
C
81
star
5

libtask

Libtask is a simple coroutine library.
C
55
star
6

9-cc

Unix port of Plan 9 C compilers.
C
40
star
7

plan9-gpl

Plan 9 from Bell Labs, under GPL.
C
28
star
8

libixp

Portable, simple C-language 9P client and server libary.
C
27
star
9

pcap

A native pcap library written in Go.
Go
25
star
10

libregexp

Unix port of the Plan 9 regular expression library.
C
25
star
11

conterm

Drawterm without graphical user interface.
C
17
star
12

9k

History of the 9k (64-bit Plan 9) kernel (2011 - 2013).
Assembly
15
star
13

plan9port-extra

Port extra software to plan9port.
C
13
star
14

libbele

Libbele, a simple library to marshal an integer to or from little-endian or big-endian formats.
C
8
star
15

mipsregs

Decode MIPS32 and MIPS64 CP0 registers to an human-readable format.
C
7
star
16

plan9-patch

Plan 9 from Bell Labs, with patches.
C
6
star
17

plan9-mips

Plan 9 from Bell Labs on MIPS.
C
5
star
18

libsnoop

Libsnoop is a simple library to read and write pcap files.
C
4
star
19

ripple-keypairs

Generate Ripple key pairs.
Go
4
star
20

hare

Plan 9 BG/P kernel, from HARE project.
C
4
star
21

stellar-keypairs

Generate Stellar key pairs.
Go
3
star
22

uodemodat

A tool to decode the encrypted uodemo.dat file provided as part of the Ultima Online Demo.
C
3
star
23

mitchell_reeds

A pseudo-random number generator by Don P. Mitchell and James A. Reeds.
C
3
star
24

u-boot-ci20

Experimental U-Boot support for MIPS Creator CI20.
C
2
star
25

bitstamp

A client implementation of the Bitstamp HTTP API, written in Go.
Go
2
star
26

webrandom

Webrandom provides HTTP services analogous to /dev/null, /dev/random and /dev/zero.
Go
2
star
27

stuff

Random tools written in Go.
Go
1
star
28

talks

My talks.
1
star
29

gpxaltitude

Fix altitudes in GPS traces encoded in GPS Exchange Format.
Go
1
star