• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

rodionovd/rd_route: Function hooking for macOS

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

rodionovd/rd_route

开源软件地址(OpenSource Url):

https://github.com/rodionovd/rd_route

开源编程语言(OpenSource Language):

C 93.6%

开源软件介绍(OpenSource 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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap