2011-06-29 224 views
1

我有這個掛鉤函數可以在x86上正常工作。感謝Bo Persson。移植C++ __fastcall從x86掛鉤到x64

void __fastcall Hook(Class* ThisInECX, int UnknownEDX, OtherClass* P1, void* P2, void* P3) 
{ 
    static void* OriginalFunctionPointer = GetProcAddress(GetModuleHandleA("Some.dll"), "[...]"); 
    static auto OriginalFunction = ((void(__fastcall*)(Class* ThisInECX, int UnknownEDX, OtherClass* P1, void* P2, void* P3))OriginalFunctionPointer); 

    OriginalFunction(ThisInECX, UnknownEDX, P1, P2, P3); 
} 

現在我試圖將其移植到x64。我從幾個片段中發現並理解的是: 我在前面有另一個變量「int UnknownRDX」,但沒有它,至少在正確調用OriginalFunction時至少沒有它。 我的實際變量(P1等)似乎被抵消了(或者我的問題是不同的)。 我其實需要知道這個聲明是否正確,所以我可以在更糟糕的位置尋找問題。

void Hook(Class* This, int Unknown0, int Unknown1, OtherClass* P1, void* P2, void* P3) 
{ 
    static void* OriginalFunctionPointer = GetProcAddress(GetModuleHandleA("Some64.dll"), "[...]"); 
    static auto OriginalFunction = ((void(*)(Class* This, int Unknown0, int Unknown1, OtherClass* P1, void* P2, void* P3))OriginalFunctionPointer); 

    // Using P1 here is fine on x86 but not on x64 

    OriginalFunction(This, Unknown0, Unknown1, P1, P2, P3) 
} 
+0

請不要在標題中加任何標籤。 Mkay,這將是偉大的,謝謝。 – 2011-06-29 13:09:07

+0

只是一個建議......在x86和x64中使用'size_t UnknownEDX'。 – Raiv

+0

可能是因爲x64的簽名是無效的(Class *,int64_t,OtherClass *,void *,void *)而不是void(Class *,int,int,OtherClass *,void *,void *)? – Tomek

回答

1

在x64上只有一個調用約定,所以你可以從簽名中剔除它。可能出現的問題是您嘗試從x64函數加載x86版本的過程。

編輯:哦,等一下,你之前發佈了關於x86/x64掛鉤的問題吧?我很有信心,這不是問題。

我想說的是,以前,您的代碼依賴於調用約定特定的hack,但在x64上只有一個調用約定。

http://msdn.microsoft.com/en-us/library/ms235286.aspx

+0

這是我從中加載的x64庫。 – zEh

+0

@zEh:檢查我的編輯。 – Puppy

+0

有關調用約定的更多信息:http://msdn.microsoft.com/en-us/library/ms235286.aspx – ALOToverflow