美文网首页
访问自身Mach-O、调用函数等

访问自身Mach-O、调用函数等

作者: 介和 | 来源:发表于2019-01-26 20:49 被阅读2次

转自: https://www.dllhook.com/post/249.html

内嵌汇编的一些黑科技:访问自身Mach-O、调用函数等

从dyld里面学来的

获取代码段的起始、结束位置

可以用来做代码段校验

typedef void (*Initializer);

extern const Initializer  inits_start  __asm("section$start$__TEXT$__text");

extern const Initializer  inits_end    __asm("section$end$__TEXT$__text");

NSLog(@"inits_start:%p", &inits_start);

NSLog(@"inits_end:%p", &inits_end);

调用构造函数

__attribute__((constructor)) void init_funcs()

{

    printf("--------init funcs.--------\n");

    printf("--------init done--------\n");

}

__attribute__((constructor)) void init_funcs2()

{

    printf("--------init funcs2.--------\n");

    printf("--------init done2--------\n");

}

typedef void (*Initializer)(int argc, const char* argv[], const char* envp[], const char* apple[]);

extern const Initializer  inits_start  __asm("section$start$__DATA$__mod_init_func");

extern const Initializer  inits_end    __asm("section$end$__DATA$__mod_init_func");

NSLog(@"inits_start:%p", &inits_start);

NSLog(@"inits_end:%p", &inits_end);

for (const Initializer* p = &inits_start; p < &inits_end; ++p) {

    (*p)(argc, argv, NULL, NULL);

}

获取函数地址并调用

不仅能获取节的数据,还能获取函数地址并调用。

int Func(int a, int b) {

    return a + b;

}

int myFunc(int a, int b) __asm("_Func");

int myprintf(const char * __restrict, ...) __asm("_printf");

myprintf("%s", "www.dlllhook.com");

NSLog(@"ret=%d", myFunc(1, 2));

相关文章

  • 访问自身Mach-O、调用函数等

    转自:https://www.dllhook.com/post/249.html 内嵌汇编的一些黑科技:访问自身M...

  • 函数的递归(1)

    函数内部自身调用自身的编程技巧 就叫递归一. 递归函数的特点 一个函数 内部 自己调用自己-- 函数内部可以调用其...

  • 【javascript】Function类型的七点总结

    一。不带圆括号的函数名访问的是函数指针,而非调用函数 //不带圆括号的函数名访问的是函数指针,而非调用函数 fun...

  • js 创建函数的方式

    一 函数声明 二 函数表达式 函数的特殊使用方式 1.递归函数函数调用自身例如: 2.闭包闭包是指有权访问另一个函...

  • Python 递归

    递归:函数对自身定义的引用。 每次函数调用时,针对这个调用的新命名空间会被创建,意味着当函数调用“自身”时,实际上...

  • 递归

    递归 概念 递归就是函数调用自身,直到达到某种状态。调用自身的函数就是我们在同一个函数内调用自己。达到某种状态就...

  • 尾递归

    函数调用自身,称为『递归』;函数尾调用自身,称为『尾递归』 由于递归需要保存大量调用帧,很消耗内存,容易发生 st...

  • JS自身函数调用

    使用arguments.callee 不使用arguments.callee的情况下 给函数添加个名字,并进行调用

  • this的指向

    this永远指向最后调用他的那个对象。 构造函数本身是无法访问自身函数的,只有实例化才可以 求数组的最大值let ...

  • 函数的递归

    函数调用自身的 编程技巧 称为递归 1.1 递归函数的特点 特点 一个函数 内部 调用自己函数内部可以调用其他函数...

网友评论

      本文标题:访问自身Mach-O、调用函数等

      本文链接:https://www.haomeiwen.com/subject/oohwjqtx.html