Assembler library for .NET, assembling runtime-variable strings into machine code for injection

后端 未结 8 994
醉酒成梦
醉酒成梦 2020-12-14 09:23

Is there such a thing as an x86 assembler that I can call through C#? I want to be able to pass x86 instructions as a string and get a byte array back. If one doesn\'t exist

相关标签:
8条回答
  • 2020-12-14 09:37

    Cosmos also has some interesting support for generating x86 code:

    http://www.gocosmos.org/blog/20080428.en.aspx

    0 讨论(0)
  • 2020-12-14 09:39

    Take a look at this: CodeProject: Using unmanaged code and assembly in C#.

    0 讨论(0)
  • 2020-12-14 09:46

    As part of some early prototyping I did on a personal project, I wrote quite a bit of code to do something like this. It doesn't take strings -- x86 opcodes are methods on an X86Writer class. Its not documented at all, and has nowhere near complete coverage, but if it would be of interest, I would be willing to open-source it under the New BSD license.

    UPDATE: Ok, I've created that project -- Managed.X86

    0 讨论(0)
  • 2020-12-14 09:48

    I think you would be best off writing a native Win32 dll. You can then write a function in assembler that is exported from the dll. You can then use C# to dynamically link to the dll.

    This is not quite the same as passing in a string and returning a byte array. To do this you would need an x86 assembler component, or a wrapper around masm.exe.

    0 讨论(0)
  • 2020-12-14 09:50

    i don't know if this is how it works but you could just shellexecute an external compiler then loading the object generated in your byte array.

    0 讨论(0)
  • 2020-12-14 09:54

    See this project:

    https://github.com/ZenLulz/MemorySharp

    This project wraps the FASM assembler, which is written in assembly and as a compiled as Microsoft coff object, wrapped by a C++ project, and then again wrapped in C#. This can do exactly what you want: given a string of x86/x64 assembly, this will produce the bytes needed.

    If you require the opposite, there is a port of the Udis86 disassembler, fully ported to C#, here:

    https://github.com/spazzarama/SharpDisasm

    This will convert an array of bytes into the instruction strings for x86/x64

    0 讨论(0)
提交回复
热议问题