Code Monkey home page Code Monkey logo

rd_route's Introduction

rd_route

Build Status
Replace (aka «hook» or «override» or «route») implementation of any C function in runtime. Works on OS X with Mach–O binaries.

Do not use this code. It can destroy everthing. But if you do, I wish you a luck.

NOTE: rd_route won't work on iOS. You should take a look at libevil instead.
Aaand it won't work for you too if you're targeting ARM64. Unfortunately I don't have a modern iOS device and thus unable to look into it, but maybe you do?

Usage

#include <assert.h>
#include "rd_route.h"


static char* my_strerror(int err)
{
  return "It's OK";
}

int main (void)
{

    void *(*original)(int) = NULL;
    int err = 2;

    printf("Error(%d): %s", err, strerror(err));
    // >> No such file or directory

    rd_route(strerror, my_strerror, (void **)&original);
    
    // See if the patch works
    assert(0 == strcmp("It's OK", strerror(err)));
    // See if an original implementation is still available
    assert(0 == strcmp("No such file or directory", original(err)));

    return 0;
}

Integration

Using git submodules

$ cd /your/project/path
$ git submodule add https://github.com/rodionovd/rd_route

Not using git submodules

Just copy rd_route.h and rd_route.c files into your project's directory.


But wait, we already have mach_override for this stuff

I've created this library because mach_override requires an external disassembler in order to work properly. For those of us who don't want another few thousands of lines of foreign code in their projects, the only option is to hard-code every function prologue they know in order to patch it correctly — which isn't a great alternative to have, to be honest.

Credits

  • The source code is based on Landon Fuller's (@landonf) gorgeous libevil library.

  • I'm also glade we have Jonathan 'Wolf' Rentzsch out there with his classy mach_override 👍


If you found any bug(s) or something, please open an issue or a pull request — I'd appreciate your help! (^,,^)


Dmitry Rodionov, 2014-2015
[email protected]

rd_route's People

Contributors

rodionovd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rd_route's Issues

Swift property routing support?

In obj-c properties are syntactic sugar over setFoo: getFoo methods, but in Swift they are closer to ivars (at least from my knowledge). Is there any way to route them as well?

Crash when calling reentry/original function (latest Yosemite GM, 10.9.5)

Hi!

Thank you so much for this project! I was previously using mach_override, but since I found rd_route, I have switched!

I noticed that at some point (OS X 10.10 DP5 or DP6), calling the reentry function crashes the application. One quick and dirty workaround I found, was to change the _remap_image() function, changing the existing x86_64 hack:
err = mach_vm_allocate(mach_task_self(), new_location, image_size*3, VM_FLAGS_ANYWHERE); mach_vm_size_t lefover = image_size * 2;
to:
err = mach_vm_allocate(mach_task_self(), new_location, image_size*4, VM_FLAGS_ANYWHERE); mach_vm_size_t lefover = image_size * 3;

That (apparently) fixed, but it looks like apps still crash after some time.
One thing that may or not be related, if I injected myself on Quicktime Player (OSX 10.10 too), app crashes immediately when calling rd_route() (at _patch_memory + 178 (rd_route.c:306)).

Hope this helps!

Thank you,
Nuno

Support for arm64

Apple doesn't make x86_64 machines anymore, it would be nice, if we could update this code for Apple Silicon. Thx!

Go to CocoaPods

Should be nice to have this library available through the CocoaPods dependency manager.

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.