![]() |
#2
wangboa1232011-06-28 21:24
|
我基础学得不好,所以,才来问这种小问题,希望各位大侠抽点时间帮忙解决,在此谢过了!!!!
下面说一下我的程序,我写了一个类,类里面封装了几个函数,函数的参数都是指针类型的,我想在函数里得到的指针值再把它赋给参数带回主函数,可是应该要怎么操作才能达到我的要求呢?下面把我写的代码贴出来,请各位大哥帮忙看下。

#include <Windows.h>
class PEinfo
{
public:
PEinfo();
~PEinfo();
BOOL GetDosHeader(IMAGE_DOS_HEADER *pDosHeader);//获取PE头指针
BOOL GetNtHeader(IMAGE_NT_HEADERS *pNtHeader);
BOOL GetSection(IMAGE_SECTION_HEADER *pSectionHeader);
BOOL GetFilePath();//加载文件
private:
DWORD pBuffer;
IMAGE_DOS_HEADER *m_DosHeader ;
IMAGE_NT_HEADERS *m_NtHeader ;
IMAGE_SECTION_HEADER *m_SectionHeader ;
};
PEinfo::PEinfo()
{
pBuffer = NULL;
m_DosHeader = NULL;
m_NtHeader = NULL;
m_SectionHeader = NULL;
}
BOOL PEinfo::GetFilePath()
{
pBuffer = (DWORD)LoadLibraryA("C:\\Documents and Settings\\Administrator\\桌面\\MyDll\\Debug\\Mydll.dll");
if (pBuffer == NULL)
{
return FALSE;
}
return TRUE;
}
BOOL PEinfo::GetDosHeader(IMAGE_DOS_HEADER *pDosHeader)
{
m_DosHeader = (IMAGE_DOS_HEADER *)pBuffer;
if (m_DosHeader == NULL)
{
return FALSE;
}
pDosHeader = m_DosHeader;
return TRUE;
}
BOOL PEinfo::GetNtHeader(IMAGE_NT_HEADERS *pNtHeader)
{
m_NtHeader = (IMAGE_NT_HEADERS *)(pBuffer+m_DosHeader->e_lfanew);
if (m_NtHeader == NULL)
{
return FALSE;
}
pNtHeader = m_NtHeader;
return TRUE;
}
PEinfo::~PEinfo()
{
};
BOOL PEinfo::GetSection(IMAGE_SECTION_HEADER *pSectionHeader)
{
m_SectionHeader = (IMAGE_SECTION_HEADER *)(pBuffer+m_DosHeader->e_lfanew+sizeof(IMAGE_NT_HEADERS));
if (m_SectionHeader == NULL)
{
return FALSE;
}
pSectionHeader = m_SectionHeader;
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
IMAGE_DOS_HEADER *MyDosHeader = NULL;
IMAGE_NT_HEADERS *MyNtHeader = NULL;
IMAGE_SECTION_HEADER *MySection = NULL;
PEinfo Mypeinfo;
Mypeinfo.GetFilePath();
Mypeinfo.GetDosHeader(MyDosHeader);//重点是这里,我想在这里获取函数里面的PE头指针,可是这样貌似不行哦。请各位大侠指点一下,谢啦。
system("pause");
return 0;
}
以上程序有哪些错误不不足之处,望各位大侠指出,再次感谢。class PEinfo
{
public:
PEinfo();
~PEinfo();
BOOL GetDosHeader(IMAGE_DOS_HEADER *pDosHeader);//获取PE头指针
BOOL GetNtHeader(IMAGE_NT_HEADERS *pNtHeader);
BOOL GetSection(IMAGE_SECTION_HEADER *pSectionHeader);
BOOL GetFilePath();//加载文件
private:
DWORD pBuffer;
IMAGE_DOS_HEADER *m_DosHeader ;
IMAGE_NT_HEADERS *m_NtHeader ;
IMAGE_SECTION_HEADER *m_SectionHeader ;
};
PEinfo::PEinfo()
{
pBuffer = NULL;
m_DosHeader = NULL;
m_NtHeader = NULL;
m_SectionHeader = NULL;
}
BOOL PEinfo::GetFilePath()
{
pBuffer = (DWORD)LoadLibraryA("C:\\Documents and Settings\\Administrator\\桌面\\MyDll\\Debug\\Mydll.dll");
if (pBuffer == NULL)
{
return FALSE;
}
return TRUE;
}
BOOL PEinfo::GetDosHeader(IMAGE_DOS_HEADER *pDosHeader)
{
m_DosHeader = (IMAGE_DOS_HEADER *)pBuffer;
if (m_DosHeader == NULL)
{
return FALSE;
}
pDosHeader = m_DosHeader;
return TRUE;
}
BOOL PEinfo::GetNtHeader(IMAGE_NT_HEADERS *pNtHeader)
{
m_NtHeader = (IMAGE_NT_HEADERS *)(pBuffer+m_DosHeader->e_lfanew);
if (m_NtHeader == NULL)
{
return FALSE;
}
pNtHeader = m_NtHeader;
return TRUE;
}
PEinfo::~PEinfo()
{
};
BOOL PEinfo::GetSection(IMAGE_SECTION_HEADER *pSectionHeader)
{
m_SectionHeader = (IMAGE_SECTION_HEADER *)(pBuffer+m_DosHeader->e_lfanew+sizeof(IMAGE_NT_HEADERS));
if (m_SectionHeader == NULL)
{
return FALSE;
}
pSectionHeader = m_SectionHeader;
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
IMAGE_DOS_HEADER *MyDosHeader = NULL;
IMAGE_NT_HEADERS *MyNtHeader = NULL;
IMAGE_SECTION_HEADER *MySection = NULL;
PEinfo Mypeinfo;
Mypeinfo.GetFilePath();
Mypeinfo.GetDosHeader(MyDosHeader);//重点是这里,我想在这里获取函数里面的PE头指针,可是这样貌似不行哦。请各位大侠指点一下,谢啦。
system("pause");
return 0;
}