C/C++ inline assembler with instructions in string variables(带有字符串变量指令的 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
");
__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++ 内联汇编器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有字符串变量指令的 C/C++ 内联汇编器


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01