如何从 C# 编写汇编代码?

发布于 2024-10-05 03:50:49 字数 159 浏览 0 评论 0原文

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆沫 2024-10-12 03:50:49

我怀疑是否有一个 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.

白云不回头 2024-10-12 03:50:49

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 like xor ebp, ebp wouldn't work.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文