GithubHelp home page GithubHelp logo

827992983 / peparser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redchards/peparser

0.0 0.0 0.0 84 KB

C++11 parser for PE files (windows executable format) which focus on correctness.

License: MIT License

C++ 97.27% C 2.73%

peparser's Introduction

PeParser

Parser for PE files (windows executable format) which focus on correctness.

Brief

Focus on correctness mean of course reduced performance sometimes. Also, for the sake of simpicity, when parsing headers we will use simple std::filebuf objects, as they are not meant to be accessed a lot in a short period of time. But unless you need to access the data in a near realtime fashion, this "slowness" should be absolutely no trouble. This library is a collection of parser rather than a single parser, each with different goals. Right now, we have 4 differents parser available :

  • The COFF header parser : will parse only informations present in the COFF part of the PE header.
  • The PE header parser : an extension of the PE parser, it will parse information in both COFF and PE headers (along with data table informations).
  • The section header parser : will parse informations about section headers.
  • The section data parser : a bit of a misnomer as it does not parser anything, but will extract data from sections.

Data layout of each header is described in the file HeaderLayout.h

State

The library is considered in an "usable but highly incomplete" state right now. Some work is still required to be able to develop application like .NET obfuscator or disassembler for examples.

WARNING : Right now, the library is only able to parse standard PE files (ignoring the Rich header), and the COFF file. I also want to support "import objects" and "anonymous objects", but I lack informations on these right now (even the winnt.h structures seems to be not correct ...)

How to use

Using the library is actually pretty simple. Here is an example of accessing the number of section and the file characteristics from a COFF header parser :

#include <iostream>

#include <COFFHeaderParser.h>

int main()
{
  COFFHeaderParser parser("pathToYourFile");
  std::cout << "Number of sections : " << parser.getNumberOfSections() << std::endl;
  // Alternatively, you can do :
  // parser.retrieveFieldValue(COFFHeaderField::NumberOfSections)
  
  std::cout << "Now displaying file characteristics :" << std::endl;
  for(auto characteristic : parser.getCharacteristicsAsString())
  {
    std::cout << "- " << characteristic;
  }
  std::cout << std::endl;
  
  return 0;
}

For a x64 dll file with 6 sections :

Number of sections : 6
Now displaying file characteristics :
- Large address aware
- DLL

Also note that there's multiple ways to access the data. The most versatile way is using the "retrieveFieldValue" of each parsers, and using the enums defined in HeaderLayout.h.

More examples to come ...

Building

To build the project, you'll need Visual Studio 2015 RC1. There's no linux port for the good reason that PE files on linux are pretty rare (they do not exist at all in fact), so this would be a pointless effort. Simply opening the solution and building should do the trick. Resulting files will then be outputed to :

$(Solution)\$(Configuration)\$(Platform)\PeParser.dll

For example, if your project root directory is "D:\MyProject", the configuration "Debug" and the platform "x64", resulting file will be outputed to

D:\MyProject\Debug\x64\PeParser.dll

License

The project is under the MIT license (see the LICENSE.md for more informations)

peparser's People

Contributors

redchards avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.