Search code examples
c++runtimereflection.emitassembly

Is there kind of runtime C++ assembler library around?


For my small hobby project I need to emit machine code from C++ program in runtime. I have base address 0xDEADBEEF and want to write something like this:

Assembler a((void*)0xDEADBEEF);
a.Emit() << 
  Push(Reg::Eax) <<
  Push(Reg::Ebx) <<
  Jmp(0xFEFEFEFE);

Inline assembler isn't my choice because generated machine code is dependent of the program state.

Does anybody know any existing library for doing this? If no, would it be a good idea to develop one from scratch and make it open source? (I mean, will anybody ever use this library if it existed?)


Solution

  • You could use Nicolas Capen's softwire. Its really not supported any more as he now works on a similar product at Transgaming called SoftAsm. Still it kinda does what you want.

    Edit June 2014: - It appears the sourceforge link above has been removed but it appears to be available under an LGPL license here.