inject x86 code into x64 process
===

I am working on an x86 dll injector and i want to inject x86 code into a x64 process thread and execute it. First I was failing with calling *CreateRemoteThread* on x64 process which led to error code 5. Then I've found [this trick][1] and I was able to create remote thread with it. But when I try to *ResumeThread* and execute that x86 code inside x64 process, whole process crash.

Injecting x86 to x86 works well, problem is only with x86 to x64.

So, my question is -- is it somehow possible to emulate and run x86 code copied inside x64 process? I know one way to do this would be to have two versions of the same code and choose one depending on the architecture of the remote process, but I don't find this as the best way to do this.

Thanks.


  [1]: https://dev.metasploit.com/redmine/projects/framework/repository/revisions/master/entry/external/source/meterpreter/source/common/arch/win/i386/base_inject.c