Code Monkey home page Code Monkey logo

elfedit2's Introduction

elfedit (2)

A way to directly change values on an ELF file

This tool (named elfedit2 to not collied with binutil's elfedit), allows for someone to change the value of a (global) constant on an elf file.

Considering you have a const variable:

// `volatile` to avoid optimizations
const volative int CONFIG_INT = 6;
// ...

You can edit it's value with

elfedit2 <your-elf-file> CONFIG_INT=7

In effect setting its value to 7.

(See test.c for an example)

Strings

Parsing the arguments, if the value is not a valid integer, it is assumed to be a string.

To update/set/override strings, you need to define the space for it:

const char CONFIG_STR[] = "placeholder";
// or set the size
const char CONFIG_STR[32];
// or set size and default value
const char CONFIG_STR[32] = "/tmp";

// can't do pointers tho...

And the command interface is the same

elfedit2 <your-elf-file> CONFIG_STR=/tmp/my-program

The tool will complain if the provided string would not fit (including null terminator) and will also pad the remaining of the space with zeroes.

(See test-string.c/sh for examples)

Why ??

In one of my projects, being developed in C, I found myself needing to have some configuration values coming from the outside,

As per usual, I didn't settle for the "normal" way (command line argument or environment variable) as the need to parse that way would be ... something I'd rather not do.

So I came up with this tool.

You create a "placeholder" for the configuration value/constant, and override it externally.

Build

Simply run gcc elfedit2.c -o elfedit and copy/move it wherever you want (no need for makefiles or cmakes)

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.