I have this code below and I want to translate it to ASM to use it in Delphi.
var
FunctionAddressList: Array of Integer;
type TFunction = function(parameter: Integer): Integer; cdecl;
function Function(parameter: Integer): Integer;
var
ExternFunction: TFunction;
begin
ExternFunction := TFunction(FunctionAddressList[5]);
Result := ExternFunction(parameter);
end;
It works fine, but when I try to execute its build version:
function Function(parameter: Integer): Integer; cdecl;
asm
mov eax, FunctionAddressList
jmp dword ptr [eax + 5 * 4]
end;
It should work because in C ++ it works in both directions:
void *FunctionAddressList;
_declspec(naked) int Function(int parameter)
{
_asm mov eax, FunctionAddressList;
_asm jmp dword ptr [eax + 5 * 4];
}
typedef int (*TFunction)(int parameter);
int Function(int parameter)
{
TFunction ExternFunction = ((TFunction *)FunctionAddressList)[5];
return ExternFunction(parameter);
}
But this does not work in Delphi.
In the Assembly version, it multiplies the array by 4, since this is the size of the offset between each element of the array, so both versions are equivalent.
So, I want to know why it does not work with Delphi. In Delphi, is the offset size between the Integer values in the array different from C ++?
, 1, 2, 4, 6, 8 .. Array (Array of Pointer, , Integer ..), cdecl , non-asm, ASM .
.