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

后端 未结 8 995
醉酒成梦
醉酒成梦 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:59

    Not directly from C# you can't. However, you could potentially write your own wrapper class that uses an external assembler to compile code. So, you would potentially write the assembly out to a file, use the .NET Framework to spin up a new process that executes the assembler program, and then use System.IO to open up the generated file by the assembler to pull out the byte stream.

    However, even if you do all that, I would be highly surprised if you don't then run into security issues. Injecting executable code into a completely different process is becoming less and less possible with each new OS. With Vista, I believe you would definitely get denied. And even in XP, I think you would get an access denied exception when trying to write into memory of another process.

    Of course, that raises the question of why you are needing to do this. Surely there's got to be a better way :).

    0 讨论(0)
  • 2020-12-14 10:04

    Take a look at Phoenix from Microsoft Research.

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