I am doing some weird stuff. I duplicate functions and modify them in a portable way. One problem I have is that I cannot get data in a relative way to be able to access attached functional data.

Here is an kinda of thought example,

void base(int a, int b, int c)
{
    ...
}

This function is duplicated byte wise using memcpy. Extra information is added to the these bytes that I would like to access in base, but no absolute addresses can be used and portability must be maintained. One can imagine the data attached to the start or end of the function.

Using assembly, it is relatively easy. Just get eip at start of function, get the length of the function, then access the data like mov eax, [eip+length]. This is not portable though.

The function signature cannot change either or, it too, would be easy as I could just pass the offsets. I have no control over the calling mechanism. I can only create a functional template then copy that and attach data that it can use. I have seen some methods to do this but they all are unsafe as they might create undefined behavior in specific instances.

Do I have any options?
Thanks.











Reply via email to