如何从 C# 编写汇编代码?
我想用 C# 编写一串汇编代码,并将其发送到一些 win32 api 来编译和执行它并获取结果。
示例:
string str = "MOV 1,2;XOR EBP,EBP"...
听起来很难做到,但任何建议都会有帮助。
i want to write a string of assembly code in c# and have it sent to some win32 api to compile and execute it and get the results back.
example:
string str = "MOV 1,2;XOR EBP,EBP"...
sounds like hard to do but any suggestion would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑是否有一个 win API 可以编译&执行装配。
也许您能做的最好的事情就是编写一个文件,执行 MASM(或现在所谓的任何名称),链接它,然后执行生成的程序。
我无法想象你想做什么,但这几乎是我尝试解决几乎任何问题的最后一种方法!
如果你想比较原生和托管代码,只需编写两个执行或多或少相同操作的程序即可。没有理由从 .NET 生成程序集。您可以为此使用任何合适的工具。 MASM、调试等
I doubt there's a win API to compile & execute assembly.
Probably the best you could do is write a file, execute MASM (or whatever it's called these days), link it then execute the resulting program.
I can't imagine what you are trying to do but this would be pretty much the last way I would try to solve almost any problem!
If you want to compare native & managed code, just write two programs that do more or less the same thing. There is no reason to generate the assembly from .NET. You can use any suitable tool for this. MASM, debug etc.
AFAIK 没有可用的汇编编译器作为 WinAPI 的一部分。您将必须使用一些第三方编译器(并且您的程序需要重新分发它)。
但是,您可以使用 ilasm,它是 .NET 框架的一部分。 (但请注意,它不是 Intel32 编译器,其来源是 CIL 代码,因此指令如下 < code>xor ebp, ebp 不起作用。)
AFAIK there is no assembler compiler available as a part of WinAPI. You would have to use some of the 3rd party compilers (and your program would need to redistribute it).
However, you can use
ilasm
which is a part of .NET framework. (Beware however that it's not an Intel32 compiler, its source is CIL code, so the instructions likexor ebp, ebp
wouldn't work.)