View Full Version : اجرای تابع با داشتن ادرس ان
amir_civil
جمعه 16 بهمن 1388, 16:25 عصر
با سلام
دوستان میدونند که چه جوری میشه یه تابع رو فقط با داشتن ادرس اون اجرا کرد؟(مثلا یه تابع api()(در سی++)
(با اشاره گرها میشه؟ پارامترهای اون تابع رو چه جوری باید بهش بدیم؟ ممنون)
clover
جمعه 16 بهمن 1388, 18:20 عصر
در تکمیل صحبت های دوست عزیز CppBuilder2006 (http://barnamenevis.org/forum/member.php?u=96122) این را هم ذکر کنم که :
اشاره گر به یک تابع باید دارای نوع بازگشتی و لیست پارامتر های یکسان با تابع مورد نظر باشد. به عنوان نمونه به کد زیر دقت کنید:
int iadd_func(int x, int y)
{
return x + y;
}
int main()
{
int n;
int (*ifunc_ptr)(int, int);
ifunc_ptr = iadd_func;
n = ifunc_ptr(5, 8);
return 0;
}
البته همیشه به این اندازه ساده نیست.
amir_civil
جمعه 16 بهمن 1388, 20:53 عصر
با سلام
فکر کنم سوالم روخوب مطرح نکردم
فرض کنید که 0xcf ادرس یه تابع درون یه dll هست حالا چه جوری میشه اون رو اجرا کرد؟
sh4mid
شنبه 17 بهمن 1388, 00:50 صبح
// A simple program that uses LoadLibrary and
// GetProcAddress to access myPuts from Myputs.dll.
#include <windows.h>
#include <stdio.h>
typedef int (__cdecl *MYPROC)(LPWSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("myputs"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
}
amir_civil
یک شنبه 18 بهمن 1388, 14:21 عصر
// A simple program that uses LoadLibrary and
// GetProcAddress to access myPuts from Myputs.dll.
#include <windows.h>
#include <stdio.h>
typedef int (__cdecl *MYPROC)(LPWSTR);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("myputs"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
}
دوست من
من که نگفتم چه جوری ادرس رو میشه پیدا کرد
من چیزه دیگه ای پرسیدم
یه چیزی مثل این:
mov eax,0xcd
call eax
hoax3r
یک شنبه 18 بهمن 1388, 15:05 عصر
این مثال رو برای MessageBoxA ببین
#include <windows.h>
#define MessageBox_RVA 0x000407EA
#define MessageBox_VA 0x7E4507EA
int main()
{
DWORD hDll = (DWORD) LoadLibrary("user32.dll");
// Method 1
// RVA + ImageBase -> VA of MessageBoxA
//DWORD lpMessage = (DWORD) MessageBox_RVA;
//lpMessage += ((DWORD) hDll);
// Method 2
// VA of MessageBoxA
DWORD lpMessage = (DWORD) MessageBox_VA;
((FARPROC) lpMessage)(NULL, "Hello", "MsG", MB_OK);
FreeLibrary((HMODULE)hDll);
return 0;
}
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.