GithubHelp home page GithubHelp logo

badbit's Introduction

BadBit

BadBit is a lightweight single header library for PE binary parsing, the library also supports XOR (not necessarily needed, the lib handles that too) and will later on support enabling dynamically imported calls too.

Features

  • Write/Read Raw Data
  • Read Dos/Nt headers
  • Read all section headers
  • Get/Delete/Add sections (automatically fixes PE)
  • IAT/EAT Read & Hook (wip)
  • Save the modified buffer to a new file

Example deleting a section from a PE header

for this example i also use "lightlog" library from my repositories (https://github.com/veil3/lightlog). you can initialize it like this:

	Log::InitStdOutHandle();
	Log::SetTitle("title");

Here's a fully working example:

main.hpp

#include "include/lightlog.hpp"
#include "include/badbit.hpp"

using namespace badbit;

int main()
{
  // initialize std output handle (used for coloured output)
  Log::InitStdOutHandle();
  // change console title
  Log::SetTitle("BadBit");

  try
  {
    // initialize our "Binary" class from badbit library
    const auto binary = new Binary(L"C:\\BadBit\\test.exe");
		
    // use FindDosHeader to initialize DOS Header and check if its successful
    if (!binary->FindDosHeader())
    	throw std::runtime_error("invalid DOS header");

    // you can access dos header from the binary class
    Log::Ok("Found DOS header");
    Log::Info("DOS e_magic: 0x%x", binary->pDosHeader->e_magic);

    // use FindDosHeader to initialize DOS Header and check if its successful
    if (!binary->FindNtHeaders())
    	throw std::runtime_error("invalid NT headers");

    // you can access nt headers from the binary class
    Log::Ok("Found NT headers");
    Log::Info("NT Signature: 0x%x", binary->pNtHeaders->Signature);

    // use FindSections to initialize a std::vector of PIMAGE_SECTION_HEADER reading the binary's sections
    // sections are private and accessed only from class functions, to write raw bytes to the binary use WriteBuffer and ReadBuffer
    if (!binary->FindSections())
    	throw std::runtime_error("failed to find sections");

    Log::Ok("Found sections");

    // use DeleteSection to delete a section, both headers and raw data, fixing the PE too
    const auto sectionToDelete = ".text";
    if (!binary->DeleteSection(sectionToDelete))
    	throw std::runtime_error("failed to delete section");

    Log::Ok("Successfully deleted section: %s", sectionToDelete);

    // save the modified binary buffer to a new file
    const auto outputFileName = std::wstring(L"protected_").append(binary->FileName);
    if (!binary->Save(outputFileName))
    	throw std::runtime_error("failed to write output file");

    Log::Ok("File written to disk!");
  }
  catch (std::exception ex)
  {
     // catch exceptions thrown from both main.cpp and badbit.hpp
     Log::Err("Error: %s", ex.what());
  }
}

Now, the file "test.exe" has been successfully modified, deleting the .text section, to a new file protected_test.exe in the output path

badbit's People

Contributors

cenereh avatar duality1k avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.