使用gcc修改内存中的下一条指令 [英] Modify next Instruction in memory with gcc

查看:58
本文介绍了使用gcc修改内存中的下一条指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在获取之前修改下一条指令,最佳答案是这个问题 * p 指向main函数中的下一条指令。我想修改 * p 指向的内容。例如,我想将下一条指令更改为跳转指令。我该怎么办呢?



I want to modify next instruction before it fetches, in best answer of this question in foo function, *p points to the next instruction in main function. I want to modify content of where *p points at. For example I want to change the next instruction to a jump instruction. How to I can do this?

void foo()
{
    void** p = search((void**)&p, __builtin_return_address(0));
    // modify content of where *p points at.
}

int main()
{

    foo();
    //next instruction. *p points here
    return 0;
}







我想用gcc编译器执行此操作,在intel Core-i7 3632QM处理器。




I want to do this with gcc compiler, on intel Core-i7 3632QM processor.

推荐答案

可能你不能:大多数代码驻留在标记为可执行或只读的内存段中并尝试改变它们通常会导致访问违规错误。



更重要的是,为什么?

自修改代码通常是你的标志已经做了非常非常错误的事情,并且经常会导致比解决更多的问题。
Probably, you can't: most code resides in memory segments marked as "executable" or "read only" and attempts to change them generally result in access violation errors.

And more to the point, why?
Self modifying code is often a sign that you have done something very, very wrong, and often causes more problems than it solves.


这篇关于使用gcc修改内存中的下一条指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆