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++ 内联汇编器
基础教程推荐
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01