libPeConv

一个用于加载、操作和转储 PE 文件的库。「A library to load, manipulate, dump PE files.」

Github星跟踪图

libPeConv

Build status
Codacy Badge
Commit activity
Last Commit

License
Platform Badge

A library to load and manipulate PE files.

Objectives

The goal of libPEConv was to create a "swiss army knife" for custom loading of PE files. It gathers various helper functions that you can quickly integrate in your own loader. For example: remapping sections, applying relocations, loading imports, parsing resources.

Not only it allows for loading PE files, but also for customizing of some steps, i.e. IAT hooking (by providing custom IAT resolvers), and functions redirection. Yet, it is NOT focused on inline hooking and should not be confused with libraries such as MS Detours or MinHook.

LibPeConv can be used for creating PE binders, as it allows to load a PE directly from the resource, and integrate it as if it was a local code.

As well it can help you in dumping PEs from the memory, and rebuilding their IATs.

WARNING: applications that use MUI are not supported.

Basic example

The simplest usecase: use libPeConv to manually load and run an EXE of you choice.

#include <Windows.h>
#include <iostream>

#include <peconv.h> // include libPeConv header

int main(int argc, char *argv[])
{
    if (argc < 2) {
        std::cout << "Args: <path to the exe>" << std::endl;
        return 0;
    }
    LPCSTR pe_path = argv[1];

    // manually load the PE file using libPeConv:
    size_t v_size = 0;
#ifdef LOAD_FROM_PATH
    //if the PE is dropped on the disk, you can load it from the file:
    BYTE* my_pe = peconv::load_pe_executable(pe_path, v_size);
#else
    size_t bufsize = 0;
    BYTE *buffer = peconv::load_file(pe_path, bufsize);

    // if the file is NOT dropped on the disk, you can load it directly from a memory buffer:
    BYTE* my_pe = peconv::load_pe_executable(buffer, bufsize, v_size);
#endif
    if (!my_pe) {
        return -1;
    }
	
    // if the loaded PE needs to access resources, you may need to connect it to the PEB:
    peconv::set_main_module_in_peb((HMODULE)my_pe);
    
    // load delayed imports (if present):
    const ULONGLONG load_base = (ULONGLONG)my_pe;
    peconv::load_delayed_imports(my_pe, load_base);
  
    // if needed, you can run TLS callbacks before the Entry Point:
    peconv::run_tls_callbacks(my_pe, v_size);
	
    //calculate the Entry Point of the manually loaded module
    DWORD ep_rva = peconv::get_entry_point_rva(my_pe);
    if (!ep_rva) {
        return -2;
    }
    ULONG_PTR ep_va = ep_rva + (ULONG_PTR) my_pe;
    //assuming that the payload is an EXE file (not DLL) this will be the simplest prototype of the main:
    int (*new_main)() = (int(*)())ep_va;

    //call the Entry Point of the manually loaded PE:
    return new_main();
}

See also: https://github.com/hasherezade/libpeconv_tpl/blob/master/project_template/main.cpp

Read more

主要指标

概览
名称与所有者hasherezade/libpeconv
主编程语言C++
编程语言CMake (语言数: 3)
平台
许可证BSD 2-Clause "Simplified" License
所有者活动
创建于2017-11-15 01:19:14
推送于2025-05-25 19:12:47
最后一次提交2025-05-25 21:11:57
发布数0
用户参与
星数1.2k
关注者数34
派生数190
提交数711
已启用问题?
问题数45
打开的问题数15
拉请求数15
打开的拉请求数0
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?