Hi :)
I'm developing a simple JIT Assembly system in C++, but, I whant to call C functions in this jit system, so, what I have thinked... I need the pointer of the command... but, I don't know how I can get this...
That is my code
#include <cstdio>
#include <vector>
#include <windows.h>
int Execute(std::vector<unsigned char> code)
{
int eaxRegister;
unsigned char* func = (unsigned char*)VirtualAlloc( 0, code.size() + 1, 0x1000, 0x40 );
memcpy( func, code.data(), code.size() );
func[code.size()] = 0xC3;
CallWindowProc( (WNDPROC)func, 0, 0, 0, 0 );
_asm mov eaxRegister, eax;
VirtualFree( func, code.size() + 1, 0x4000 );
return eaxRegister;
}
int main()
{
std::vector<unsigned char> code;
code.push_back( 0xc7 );
code.push_back( 0xc0 );
code.push_back( 0xa );
code.push_back( 0x0 );
code.push_back( 0x0 );
code.push_back( 0x0 );
code.push_back( 0xc7 );
code.push_back( 0xc1 );
code.push_back( 0xa );
code.push_back( 0x0 );
code.push_back( 0x0 );
code.push_back( 0x0 );
code.push_back( 0x3 );
code.push_back( 0xc1 );
const char* ohi = "HI";
code.push_back( 0x69 );
code.push_back( *ohi );
code.push_back( 0xe8 );
code.push_back( 0xfff ) ;
code.push_back( 0x83 );
code.push_back( 0xc4 );
code.push_back( 0x04 );
code.push_back( 0x0 );
code.push_back( 0x0 );
code.push_back( 0x0 );
int exec = Execute( code );
printf("SUM = %d", exec);
return 0;
}
So, my problem is, how I can get the offset of printf command to use in JIT, or, how I can use the C function using the JIT ???
Thanks
Alexandre