I'm trying to get the address of a member function. Basically I'm trying to get the offset between a windows api function loaded in memory and my function.
This is what I've tried to get the address:
NTSTATUS (NTAPI myntquerydirectoryfile)(
HANDLE hFile,
HANDLE hEvent,
PVOID pApcRoutine,
PVOID pApcContext,
IO_STATUS_BLOCK* ioStatus,
PVOID pBuffer,
ULONG bufferSize,
FILE_INFORMATION_CLASS infoClass,
BOOLEAN singleEntry,
PUNICODE_STRING pFileName,
BOOLEAN restart
)
{
cout << "my func" << endl;
};
typedef NTSTATUS (*pmyhook)(HANDLE hFile,
HANDLE hEvent,
PVOID pApcRoutine,
PVOID pApcContext,
IO_STATUS_BLOCK* ioStatus,
PVOID pBuffer,
ULONG bufferSize,
FILE_INFORMATION_CLASS infoClass,
BOOLEAN singleEntry,
PUNICODE_STRING pFileName,
BOOLEAN restart);
pmyhook = &myntquerydirectoryfile;
This code snap shows how to get address of class member functions:
#include <stdio.h>
class A
{
public:
void test()
{
// Address of member function test(), is the value of &A::test
printf("Address of function is: 0x%X\n", &A::test);
}
};
int main()
{
A a;
a.test();
}
In general, it's not allowed and not recommended.
void (Class_Name::* FuncPointer)() = &Class_Name::Func_Name;
FuncPointer
will point to the class method.
Better use static function or the lambda feature in C++ 11.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.