具有字符串变量中的指令的C/C ++内联汇编器 [英] C/C++ inline assembler with instructions in string variables

查看:61
本文介绍了具有字符串变量中的指令的C/C ++内联汇编器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,正如您在C和C ++中所知道的,如果使用Visual-C,则可以在行中获得汇编指令,例如:

So as you know in C and C++ if using Visual-C you can have in line assembly instructions such as:

int main() {
    printf("Hello\n");
    __asm int 3
    printf("this will not be printed.\n");
    return 0;
}

将在可执行文件内创建一个断点.所以我的问题是,是否可以使用诸如char数组之类的变量来调用__asm的某种函数.我在想这样的事情:

Which will make a breakpoint inside of the executable. So my question is, is there somekind of function I can use to call __asm using a variable such as a char array. I was thinking something like this:

char instruction[100] = "int 3";
__asm instruction

但这似乎并没有真正起作用,因为它给出了无效的OP代码".因此,您可以为此提供帮助吗?还是根本不可能.

But that doesn't seem to really work since it gives 'Invalid OP code'. So can you help with this or it isn't possible at all.

推荐答案

程序的代码是由编译器在编译期间创建的.
您正在尝试在运行时-当程序已经在执行时为编译器提供输入.如果要即时编译",则必须编写一个增量编译器和链接器,以在执行代码时对其进行修改.

The code of your program is created by the compiler, during compilation.
You are trying to feed the compiler the input for that at run time - when the program is already executing. If you want ‘on-the-fly-compilation’, you will have to program an incremental compiler and linker that can modify the code while executing it.

请注意,即使您成功了,许多操作系统也会阻止这种执行,因为它违反了安全性.这将是构建病毒的好方法,因此通常被阻止.

Note that even if you would be successful, many OS would block such execution, as it violates security. It would be a great way to build viruses, and is therefore typically blocked.

这篇关于具有字符串变量中的指令的C/C ++内联汇编器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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