Skip to content

LibObjectFile is a.NET library to read, manipulate and write linker and executable object files (e.g ELF, PE, DWARF, ar...)

License

Notifications You must be signed in to change notification settings

xoofx/LibObjectFile

Repository files navigation

LibObjectFileciNuGet

LibObjectFile is a.NET library to read, manipulate and write linker and executable object files (e.g ELF, ar, DWARF, PE...)

NOTE: Currently LibObjectFile supports the following file format:

  • PEimage file format (Portable Executable / DLL)
  • ELFobject-file format
  • DWARFdebugging format (version 4)
  • Archivearfile format (Common, GNU and BSD variants)

There is a longer term plan to support other file formats (e.g COFF, MACH-O,.lib) but as I don't have a need for them right now, it is left as an exercise for PR contributors!;)

Usage

// Reads an ELF file
usingvarinStream=File.OpenRead("helloworld");
varelf=ElfFile.Read(inStream);
foreach(varsectioninelf.Sections)
{
Console.WriteLine(section.Name);
}
// Print the content of the ELF as readelf output
elf.Print(Console.Out);
// Write the ElfFile to another file on the disk
usingvaroutStream=File.OpenWrite("helloworld2");
elf.Write(outStream);

Features

  • Full support ofArchivearfile formatincluding Common, GNU and BSD variants.
  • Full support for thePE file format
    • Support byte-to-byte roundtrip
    • Read and write from/to aSystem.IO.Stream
    • All PE Directories are supported
    • PEFile.Relocateto relocate the image base of a PE file
    • PEFile.Printto print the content of a PE file to a textual representation
    • Support for calculating the checksum of a PE file
  • Good support for theELF file format:
    • Support byte-to-byte roundtrip
    • Read and write from/to aSystem.IO.Stream
    • Handling of LSB/MSB
    • Support the following sections:
      • String Table
      • Symbol Table
      • Relocation Table: supported I386, X86_64, ARM and AARCH64 relocations (others can be exposed by adding some mappings)
      • Note Table
      • Other sections fallback toElfCustomSection
    • Program headers with or without sections
    • Print withreadelfsimilar output
  • Support forDWARF debugging format:
    • Partial support of Version 4 (currently still the default for GCC)
    • Support for the sections:.debug_info,.debug_line,.debug_aranges,.debug_abbrevand.debug_str
    • Support for Dwarf expressions
    • High level interface, automatic layout/offsets between sections.
    • Integration with ELF to support easy reading/writing back
    • Support for relocatable sections
  • Use of a Diagnostics API to validate file format (on read/before write)
  • Library requiringnet8.0
    • If you are looking fornetstandard2.1support you will need to use0.4.0version

Documentation

Thedoc/readme.mdexplains how the library is designed and can be used.

Download

LibObjectFile is available as a NuGet package:NuGet

Build

In order to build LibObjectFile, you need to have installed the.NET 8 SDK.

Running the tests require Ubuntu 22.04.dotnet testwill work on Windows (via WSL) and on that version of Ubuntu. If you're using macOS or another Linux, there's a Dockerfile and a helper script undersrcto run tests in the right OS version.

License

This software is released under theBSD-Clause 2 license.

Author

Alexandre MUTEL akaxoofx

Supporters

Supports this project with a monthly donation and help me continue improving it. [Become a supporter]

bruno-garcia

About

LibObjectFile is a.NET library to read, manipulate and write linker and executable object files (e.g ELF, PE, DWARF, ar...)

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages