这货只能判断没导出的函数吧?
俺研究了很久了不知道是俺写的有问题还是本来只能解析没导出的函数.
#pragma once
#ifndef PDBDATA_H
#define PDBDATA_H
#include "KillProtectDll.h"
#include "..\\KillProtect\\struct.h"
#include <fstream>
;using namespace std;
class PDBData
{
private:
wchar_t ch_path[MAX_PATH];
protected:
public:
PDBData();
~PDBData();
wchar_t* GetPDBPath();
BOOL Symbol_View(char* ch_Module,DWORD64 BaseAddr,DWORD FileSize);
BOOL WcharToAchar(wchar_t* ch_temp,char* ch_temp1);
ULONG EnumModule(wchar_t* ch_ModuleName,BOOL b_open);
};
#endif
//------------------------------------------
#include "PDBData.h"
PDBData::PDBData()
{
ZeroMemory(ch_path,MAX_PATH);
}
PDBData::~PDBData()
{
}
wchar_t* PDBData::GetPDBPath()
{
::GetModuleFileName(::GetModuleHandle(DLL_Name),ch_path,MAX_PATH);
::PathRemoveFileSpec(ch_path);
::PathAppend(ch_path,PDB_Path);
return ch_path;
}
char* ch_Name[]={"PsTerminateProcess","PsGetNextProcess","PsGetNextProcessThread"};
_FuncCou FunCont[100];
int in_Count=0;
BOOL CALLBACK EnumSymCallBack( PSYMBOL_INFO pSymInfo,ULONG SymbolSize,PVOID UserContext )
{
for(unsigned int i=0;i<3;i++)
{
if(strcmp(pSymInfo->Name,ch_Name[i])==0)
{
ZeroMemory(&FunCont[in_Count],sizeof(FunCont[in_Count]));
::memcpy(FunCont[in_Count].ch_FunName,pSymInfo->Name,strlen(pSymInfo->Name)+1);
FunCont[in_Count].dw_Addr=pSymInfo->Address;
in_Count++;
}
}
return TRUE;
}
BOOL PDBData::Symbol_View(char* ch_Module,DWORD64 BaseAddr,DWORD FileSize)
{
PIMAGEHLP_SYMBOL pSymbol=NULL;
DWORD Options=::SymGetOptions();
Options=Options|SYMOPT_DEBUG;
::SymSetOptions(Options);
HANDLE hProcess=::GetCurrentProcess();
BOOL bRet=::SymInitialize(hProcess,0,FALSE);
if(!bRet)
{
return FALSE;
}
char SymbolPath[MAX_PATH];
::GetCurrentDirectoryA(MAX_PATH,SymbolPath);
::PathAppendA(SymbolPath,PDB_PathA);
::SymSetSearchPath(hProcess,SymbolPath);
char FileName[MAX_PATH] ;
::GetSystemDirectoryA(FileName,MAX_PATH);
::PathAppendA(FileName,ch_Module);
DWORD64 BaseOfDll=::SymLoadModule64(hProcess,NULL,FileName,NULL,BaseAddr,FileSize);
if(BaseOfDll == 0)
{
return FALSE;
}
::SymEnumSymbols(hProcess,BaseOfDll,0,EnumSymCallBack,0);
::SymUnloadModule64(hProcess,BaseOfDll);
::SymCleanup(hProcess);
return TRUE;
}
BOOL PDBData::WcharToAchar( wchar_t* ch_temp,char* ch_temp1 )
{
int in_len=::WideCharToMultiByte(CP_ACP,0,ch_temp,wcslen(ch_temp)*2+1,NULL,NULL,NULL,NULL);
::WideCharToMultiByte(CP_ACP,0,ch_temp,wcslen(ch_temp)*2+1,ch_temp1,in_len,NULL,NULL);
return TRUE;
}
ULONG PDBData::EnumModule( wchar_t* ch_ModuleName,BOOL b_open=FALSE)
{
int status;
LPVOID lpBuffer;
int len=0;
PSYSTEM_MODULE_INFORMATION ModuleTion;
NtQuerySystemInformation* _NtQuerySystemInformation;
_NtQuerySystemInformation=(NtQuerySystemInformation*)::GetProcAddress(::GetModuleHandle(L"ntdll.dll"),"NtQuerySystemInformation");
status=_NtQuerySystemInformation((SYSTEM_INFORMATION_CLASS)11,NULL,0,(PULONG)&len);
lpBuffer=new BYTE[len];
if(lpBuffer==NULL)
{
return 0;
}
_NtQuerySystemInformation((SYSTEM_INFORMATION_CLASS)11,lpBuffer,len,NULL);
ModuleTion=(PSYSTEM_MODULE_INFORMATION)lpBuffer;
ULONG data=0;
char ch_modulenames[MAX_PATH];
ZeroMemory(ch_modulenames,MAX_PATH);
WcharToAchar(ch_ModuleName,ch_modulenames);
for(unsigned int i=0;i<ModuleTion->Count;i++)
{
if(strstr(ModuleTion->Module[i].ImageName,ch_modulenames))
{
if(b_open==FALSE)
{
data=(ULONG)ModuleTion->Module[0].Base;
}
else
{
data=(ULONG)ModuleTion->Module[0].Size;
}
break;
}
}
delete [] lpBuffer;
return data;
}