Calling a procedure with a return address?
Posted: Sun Mar 14, 2021 2:24 am
I use madCodeHook for a number of uses, but I have a problem that is out of my experience. Does anyone know how I could call function from a DLL that is loaded by a program that can not pass function addresses or export functions due to limitations of the language?
The idea I have so far is to have the program's function (that I'm wanting to call later from the DLL) make an inital call to a function in the DLL to store address information (return address). Later, I call the saved return address in the DLL to return control to the same place as it did initally. It is unstable as it is, I assume the stack frame might be the issue? Is there a way to Hook it maybe? This is would be for use in my program only and would not be distibuted in any way, no black hat stuff!
Suggestions please.
TEST PROGRAM:
DLL ra_test.dll:
The idea I have so far is to have the program's function (that I'm wanting to call later from the DLL) make an inital call to a function in the DLL to store address information (return address). Later, I call the saved return address in the DLL to return control to the same place as it did initally. It is unstable as it is, I assume the stack frame might be the issue? Is there a way to Hook it maybe? This is would be for use in my program only and would not be distibuted in any way, no black hat stuff!
Suggestions please.

TEST PROGRAM:
Code: Select all
external: "ra_test.dll", INT, "Initial_Function_Save";
method void ReturnFunction() // * can not export this *
begin
Initial_Function_Save(); // calls function in DLL
// *** returns here, start execution here when call from the DLL later
Print("*RA - next line*");
...
end;
Code: Select all
var
ra: pointer;
ra_func: Tra_func;
function Initial_Function_Save: integer;
begin
ra := System.ReturnAddress;
result := 1;
end;
procedure Call_Program_Function;
begin
ra_func := Tra_func(ra);
ra_func;
end;
exports Initial_Function_Save,
Call_Program_Function;