Git Product home page Git Product logo

selfmodifyingc's Introduction

Self Modifying C

This was an experiment I did on Ubuntu which allowed you to change the code that ran at runtime when a function was called. It is definitely not portable in any regard, and may not even work on the same system with different compilers, or different systems with the same compiler.

Theory

What the code does is this:

  • Every function that is told to be modifiable replaces the first few bytes of its code with something that "calls" a function I set up
  • Every function that is told to be modifiable is also put into a table of values, where its address maps to what region of memory should be called
  • This region of memory is allocated at run time, and Linux is told to set it as executable
  • So, when a function is called, it actually jumps to that block of memory, which can be modified at runtime

The main function provided takes in a Hello World function, changes the address of a string that is pushed when puts is called to another string, and lets the function run on. The result is that another string is printed, without having to do anything sophisticated to call the original function.

selfmodifyingc's People

Contributors

catgirllunya avatar

Stargazers

 avatar

Watchers

 avatar  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.