-
-
[旧帖] [求助]PE结构一点编程的问题 0.00雪花
-
发表于: 2012-2-16 16:01 985
-
我们获取一个PE文件的内存文件映像之后,比如想获得.text的内容,应该怎么做,下面的代码总是总是会访问越界
#define NUM_SAMPLE_SPACES 40000
DWORD g_arrCounts[NUM_SAMPLE_SPACES];
DWORD g_dwTotalCounts;
void CalcProb(PBYTE pBuffer, DWORD dwBufLen)
{
DWORD i = 0;
if(dwBufLen == 0)
return;
for(i = 0; i < dwBufLen; i++)
{
g_arrCounts[pBuffer[i]]++;
}
g_dwTotalCounts += dwBufLen;
}
double CalcEntropyOrder0(void)
{
double fProb = 0.0;
double fEntropy = 0.0;
DWORD i = 0;
for(i = 0; i < NUM_SAMPLE_SPACES; i++)
{
fProb = 1.0 * g_arrCounts[i] / g_dwTotalCounts;
if(fProb != 0)
{
fEntropy += -fProb * (log10(fProb) / log10(2.0));
}
}
return fEntropy;
}
bool ParsePEFileFromMem(LPVOID ImageBase)
{
WORD i;
PIMAGE_FILE_HEADER pFH=NULL;
PIMAGE_SECTION_HEADER pSH=NULL;
pFH=GetFileHeader(ImageBase);
if(!pFH) return 0;
pSH=GetFirstSectionHeader(ImageBase);
memset(&g_arrCounts, 0, sizeof(g_arrCounts));
g_dwTotalCounts = 0;
for(i = 0; i < pFH->NumberOfSections; i++)
{
PBYTE pData = (PBYTE)ImageBase+pSH->PointerToRawData;
DWORD dwLength =pSH->SizeOfRawData<pSH->Misc.VirtualSize? pSH->SizeOfRawData : pSH->Misc.VirtualSize;
while(dwLength && pData[dwLength - 1] == 0)
{
dwLength--;
}
CalcProb(pData, dwLength);
pSH++;
}
double fEntropy = CalcEntropyOrder0();
return fEntropy >7.5;
}
#define NUM_SAMPLE_SPACES 40000
DWORD g_arrCounts[NUM_SAMPLE_SPACES];
DWORD g_dwTotalCounts;
void CalcProb(PBYTE pBuffer, DWORD dwBufLen)
{
DWORD i = 0;
if(dwBufLen == 0)
return;
for(i = 0; i < dwBufLen; i++)
{
g_arrCounts[pBuffer[i]]++;
}
g_dwTotalCounts += dwBufLen;
}
double CalcEntropyOrder0(void)
{
double fProb = 0.0;
double fEntropy = 0.0;
DWORD i = 0;
for(i = 0; i < NUM_SAMPLE_SPACES; i++)
{
fProb = 1.0 * g_arrCounts[i] / g_dwTotalCounts;
if(fProb != 0)
{
fEntropy += -fProb * (log10(fProb) / log10(2.0));
}
}
return fEntropy;
}
bool ParsePEFileFromMem(LPVOID ImageBase)
{
WORD i;
PIMAGE_FILE_HEADER pFH=NULL;
PIMAGE_SECTION_HEADER pSH=NULL;
pFH=GetFileHeader(ImageBase);
if(!pFH) return 0;
pSH=GetFirstSectionHeader(ImageBase);
memset(&g_arrCounts, 0, sizeof(g_arrCounts));
g_dwTotalCounts = 0;
for(i = 0; i < pFH->NumberOfSections; i++)
{
PBYTE pData = (PBYTE)ImageBase+pSH->PointerToRawData;
DWORD dwLength =pSH->SizeOfRawData<pSH->Misc.VirtualSize? pSH->SizeOfRawData : pSH->Misc.VirtualSize;
while(dwLength && pData[dwLength - 1] == 0)
{
dwLength--;
}
CalcProb(pData, dwLength);
pSH++;
}
double fEntropy = CalcEntropyOrder0();
return fEntropy >7.5;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
赞赏
他的文章
- [求助][求助]调试驱动用什么调试器 4150
- [原创]八数码演示(开源) 5137
- [求助]如何获取U盘插入的消息 4383
- [讨论]看了版主强制删除的代码,抛出几个疑问 4897
- [讨论]结贴。。。 3902
看原图
赞赏
雪币:
留言: