简体   繁体   English

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

[英]how do i write assembly code from c#?

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. 我想在C#中编写一串汇编代码,并将其发送到某些win32 api进行编译和执行,并将结果返回。

example: 例:

string str = "MOV 1,2;XOR EBP,EBP"...

sounds like hard to do but any suggestion would be helpful. 听起来很难,但任何建议都会有所帮助。

I doubt there's a win API to compile & execute assembly. 我怀疑是否有用于编译和执行程序集的Win API。 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. 您可能要做的最好的事情就是编写一个文件,执行MASM(或如今所谓的任何事情),链接它,然后执行生成的程序。 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. 没有理由从.NET生成程序集。 You can use any suitable tool for this. 您可以为此使用任何合适的工具。 MASM, debug etc. MASM,调试等

AFAIK there is no assembler compiler available as a part of WinAPI. AFAIK没有汇编程序编译器可作为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. 但是,您可以使用ilasm ,它是.NET框架的一部分。 (Beware however that it's not an Intel32 compiler, its source is CIL code, so the instructions like xor ebp, ebp wouldn't work.) (但是请注意,它不是Intel32编译器,它的源代码是CIL代码,因此xor ebp, ebp类的指令将无效。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM