问题描述
正如您在 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
");
__asm int 3
printf("this will not be printed.
");
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++ 内联汇编器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!