Is there kind of runtime C++ assembler library aro

2019-01-24 12:34发布

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?)

3条回答
啃猪蹄的小仙女
2楼-- · 2019-01-24 12:44

This might be a overkill, because it supports many platforms, has its own intermediate language, does optimizations, etc, but the http://llvm.org/ seems to be a god try.

查看更多
Fickle 薄情
3楼-- · 2019-01-24 12:58

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.

查看更多
ら.Afraid
4楼-- · 2019-01-24 13:01

Check out Asmjit. It seems to be the thing you're looking for.

查看更多
登录 后发表回答