advanced-microcode-patching / shiva

A custom ELF linker/loader for installing ET_REL binary patches at runtime
Other
152 stars 13 forks source link

Create SHIVA_HELPER_CALL_ORIGINAL macro #15

Closed elfmaster closed 1 year ago

elfmaster commented 1 year ago

We need a macro that allows a new version of a function to call back to the original version of the function.

Consider the following; a new version of foo() that performs a new check on int v and then calls the original foo() to get the return value. However this would be recursive and call the patch version of foo()

int foo(int v)
{
        if (v < 0)
                return -1;
        int r = foo(v); // This wouldn't call back to the original foo(), it would be recursive
        return r;
}

We must create something like this:

int foo(int v)
{
        ...
        int r = SHIVA_HELPER_CALL_ORIGINAL(foo(v));
        return r;
}

This macro would create a call __shiva_helper_o_func_foo()

Shiva would then look to see if there are any functions in the patch object who's name is preceding with "shiva_helper_ofunc". It would find shiva_helper_o_func_foo, and therefore know to link this relocation to the foo() from the original binary instead of the patch code.

We can create macros in the future to address specific symbol versions, as things may need to in the future at times.

elfmaster commented 1 year ago

branch shiva_helpers is underway

elfmaster commented 1 year ago

Feature added successfully.