Libelf.js

Access ELF objects with libelf, using JavaScript.

Download » Github » Libelf »

Information

Libelf.js is a port of the libelf library for JavaScript, done with Emscripten. It's released as a 500 KB JavaScript file. Follow the Readme to build Libelf.js manually.

Libelf is a lightweight library originally developed by http://www.mr511.de/ and released under LGPLv2.

Installation

To use the Libelf.js in your web application, download and include it with:

<script src="libelf.min.js"></script>

or install it through the Bower command:

bower install libelf

Tutorial

Please refer to the original libelf documentation for usage information as libelf.js offers the same interface in an object-oriented style.

// var buffer = new Uint8Array([0x7F, 0x45, 0x4C, 0x46, ...]);
var elf = new Elf(buffer);
if (elf.kind() != "elf") {
    throw "Not an ELF file";
}

var ehdr = elf.getehdr();

// Handle segments
for (var i = 0; i < ehdr.phnum; i++) {
    var phdr = elf.getphdr(i);
}
// Handle sections
for (var i = 0; i < ehdr.shnum; i++) {
    var scn = elf.getscn(i);
    var shdr = elf.getshdr(scn);
    var name = elf.strptr(
        ehdr.e_shstrndx.num(),
        shdr.sh_name.num());
}

Demo

Demos are worth a thousand words: simply load any ELF file to see Libelf.js in action. Everything will be processed locally.