For the question itself: you simply need to add the address in memory you loaded the binary to. I.e. if you loaded the binary to address myLoadAddress
just add that to myOffset
. This won't enable you to easily call the function, however. If you want to do that, you should treat it like a library file (and if it in fact is a library file check for a system function for loading libraries like LoadLibrary on Windows, then use GetProcAddress to retrieve a pointer to the function).
// create a type for your function signature
typedef void (*myFunc)(A *arg1, B arg2, C arg3);
// create a pointer to your function
myFunc myFuncPointer;
// set the address of the function in memory
myFuncPointer = myLoadAddress + myOffset;
// invoke function
myFuncPointer(A, B, C);
When loading a DLL you load it using LoadLibrary, then use GetProcAddress and typecast the address returned to your function pointer -- i.e. myFuncPointer = (myFunc)GetProcAddress(hmodule, "myFunc");
in the example.
On POSIX it works pretty much the same, but the functions are slightly different: use dlopen
to load the dynamic library, and dlsym
to retrieve the symbol. The Programming Library Howto describes this in more detail, or see the man pages for dlopen and dlsym. The basics are the same.