我有下面的代碼,我想將它翻譯成ASM,也可以在Delphi中使用。使用指針轉換代碼,以彙編在Pascal中 - Delphi
它的工作原理normaly,但是當我嘗試了大會版本:
function Function(parameter: Integer): Integer; cdecl;
asm
mov eax, FunctionAddressList
jmp dword ptr [eax + 5 * 4]
end;
它應該工作,因爲在C++中,它工作在兩個方面:
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);
}
但它在Delphi中不起作用。
在Assembly版本中,它將數組乘以4,因爲它是數組每個元素之間的偏移量,所以兩個版本都是等價的。
所以,我想知道爲什麼它不適用於Delphi。在Delphi中,數組中Integer值之間的偏移量大小與C++不同?
我已經嘗試了許多偏移量,例如1,2,4,6,8等。還有很多類型的Array(指針數組;僅指針;整數數組等等),並且我試過了許多調用約定,並且cdecl是唯一與非asm版本一起工作的,但對於ASM,所有測試都不起作用。
謝謝。
我現在沒有使用C++,但我認爲你的C++(我認爲你使用Visual C++)裸函數的代碼也假設棧上的參數。您必須自己編寫序言和epilog(以asm的形式)以使用cdecl調用約定的裸函數中的參數。你不這樣做,因爲你不需要這裏的參數,並把它傳遞給地址列表中的函數。 – kludg 2010-02-01 01:11:22