Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Dec 5, 2015
1 parent 088f42c commit 69ddc0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 14 additions & 3 deletions PEAnalyzer/PortableExecutableFile.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/**
**/
#include "stdafx.h"
#include <winnt.h>
#include <winnt.h>
#include <Dbghelp.h>
#include "PortableExecutableFile.h"
#include <codecvt>
#pragma comment(lib,"DbgHelp.lib")

#ifndef HINST_THISCOMPONENT
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
#endif


enum FileMappingStatus {
kNotOptions,
kCreateFile,
Expand Down Expand Up @@ -210,7 +216,7 @@ bool PortableExecutableFile::Analyzer()
if (!winfile.CreateFileMap(L"PEAnalyzer.Executeable.MAP"))
return false;
char *baseAddress = (char*)winfile.MapViewOfFile();
IMAGE_DOS_HEADER *pDOSHeader = reinterpret_cast<IMAGE_DOS_HEADER *>(baseAddress);
IMAGE_DOS_HEADER *pDOSHeader = reinterpret_cast<IMAGE_DOS_HEADER *>(baseAddress);
IMAGE_NT_HEADERS *pNTHeader = reinterpret_cast<IMAGE_NT_HEADERS *>(baseAddress + pDOSHeader->e_lfanew);
if (largeFile.QuadPart < (LONGLONG)(sizeof(IMAGE_DOS_HEADER) + pDOSHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)))
return false;
Expand Down Expand Up @@ -256,7 +262,12 @@ bool PortableExecutableFile::Analyzer()
wsprintfW(imageVersion, L"%d.%d",
pNTHeader->OptionalHeader.MajorImageVersion,
pNTHeader->OptionalHeader.MinorImageVersion);
wsprintfW(entryPoint, L"0x%x", pNTHeader->OptionalHeader.AddressOfEntryPoint);
auto self = &__ImageBase;
auto selfNTHeader = reinterpret_cast<IMAGE_NT_HEADERS *>((char*)self + self->e_lfanew);
if (selfNTHeader->FileHeader.Machine != pNTHeader->FileHeader.Machine) {
clrMessage = L"PEAnaylzer's Architecture is different with Input PE File,cannot check CLR";
return true;
}
IMAGE_DATA_DIRECTORY *entry = &(pNTHeader->OptionalHeader).DataDirectory[IMAGE_DIRECTORY_ENTRY_COMHEADER];
if (entry->Size != sizeof(IMAGE_COR20_HEADER)) {
return true;
Expand Down
5 changes: 0 additions & 5 deletions PEAnalyzer/PortableExecutableFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class PortableExecutableFile {
wchar_t osVersion[16];
wchar_t subsystemVersion[16];
wchar_t imageVersion[16];
wchar_t entryPoint[16];
public:
PortableExecutableFile(const std::wstring &mPath);
bool Analyzer();
Expand Down Expand Up @@ -72,10 +71,6 @@ class PortableExecutableFile {
{
return imageVersion;
}
const wchar_t *GetEntryPoint()
{
return entryPoint;
}
};

#endif

0 comments on commit 69ddc0d

Please sign in to comment.