Okay guys, here's the concept... Let's say we made this in C to make it a bit easier.
Suppose I have a full compiler, with a parser and whatnot.
We already have our PE header set up for our program we're making, but now it gets down to the nitty-gritty of the sections. Suppose we have two sections for our executable we are making, a CODE section and a DATA section. The CODE section lies at RVA 4096 and the DATA section at RVA 8192.
We then have some code in our compiler:
/* Global variables */
int* ret;
int* num1;
int* num2;
void addnumbers()
{
*ret = *num1 + *num2;
}
What we then do in our compiler code where it tells us to add the two numbers is set the addresses of the global variables we have there to our EXE's base address + their RVAs. Then we get the address of addnumbers, and copy that into our EXE at the desired place in code. What that should do then is copy the necessary code to run that portion.
What do you all think? Will it work?