merces / libpe

The PE library used by @merces/pev
http://pev.sf.net
GNU Lesser General Public License v3.0
115 stars 40 forks source link

libpe

:warning: libpe has moved under @mentebinaria/readpe. :warning:

LGPLv3 C/C++ CI

The PE library used by pev - the PE file toolkit purely written in C and available to many platforms.

Features

How to get the source code

git clone https://github.com/merces/libpe.git

How to build on Linux

cd libpe
make

NOTE: You may need to install OpenSSL using your package manager. Examples:

apt install libssl-dev
yum install openssl-devel

How to build on macOS

cd libpe
CFLAGS="-I/usr/local/opt/openssl/include/" LDFLAGS="-L/usr/local/opt/openssl/lib/" make

NOTE: You may need to install OpenSSL and PCRE via Homebrew:

brew update
brew install openssl

Usage example

#include <stdio.h>
#include "../include/libpe/pe.h"

int main(int argc, char *argv[]) {

    if (argc < 2)
        return 1;

    pe_ctx_t ctx;
    pe_err_e err = pe_load_file(&ctx, argv[1]);

    if (err != LIBPE_E_OK) {
        pe_error_print(stderr, err);
        return 1;
    }

    err = pe_parse(&ctx);
    if (err != LIBPE_E_OK) {
        pe_error_print(stderr, err);
        return 1;
    }

    if (!pe_is_pe(&ctx))
        return 1;

    printf("Entrypoint: %#llx\n", ctx.pe.entrypoint);

    return 0;
}

Compile with:

cc -o example example.c -lpe

Troubleshooting