Skip to content

Commit

Permalink
[Added] File, Opt, Nt headers, Data dirs, Rich - to Hex.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovibor committed Feb 23, 2019
1 parent c804877 commit 5b526d8
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 13 deletions.
100 changes: 94 additions & 6 deletions Pepper/ViewRightBL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,21 @@ void CViewRightBL::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/
case IDC_LIST_DOSHEADER_ENTRY:
CreateHexDosHeaderEntry(HIWORD(lHint));
break;
case IDC_LIST_RICHHEADER_ENTRY:
CreateHexRichHeaderEntry(HIWORD(lHint));
break;
case IDC_LIST_NTHEADER_ENTRY:
CreateHexNtHeaderEntry(HIWORD(lHint));
break;
case IDC_LIST_FILEHEADER_ENTRY:
CreateHexFileHeaderEntry(HIWORD(lHint));
break;
case IDC_LIST_OPTIONALHEADER_ENTRY:
CreateHexOptHeaderEntry(HIWORD(lHint));
break;
case IDC_LIST_DATADIRECTORIES_ENTRY:
CreateHexDataDirsEntry(HIWORD(lHint));
break;
case IDC_LIST_SECHEADERS_ENTRY:
CreateHexSecHeadersEntry(HIWORD(lHint));
break;
Expand Down Expand Up @@ -109,7 +118,7 @@ void CViewRightBL::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/
CreateHexSecurityEntry(HIWORD(lHint));
break;
case IDC_LIST_LOADCONFIG_ENTRY:
CreateHexLoadConfigEntry(HIWORD(lHint));
CreateHexLCDEntry(HIWORD(lHint));
break;
case IDC_LIST_RELOCATIONS_ENTRY:
CreateListRelocsEntry(HIWORD(lHint));
Expand Down Expand Up @@ -211,6 +220,19 @@ int CViewRightBL::CreateHexDosHeaderEntry(DWORD dwEntry)
return 0;
}

int CViewRightBL::CreateHexRichHeaderEntry(DWORD dwEntry)
{
PCLIBPE_RICHHEADER_VEC pRichHeader;
if (m_pLibpe->GetRichHeader(pRichHeader) != S_OK)
return -1;

CRect rc;
GetClientRect(&rc);
m_stHexEdit.SetWindowPos(this, 0, 0, rc.Width(), rc.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
//Each «Rich» takes 8 bytes (two DWORDs).
m_pFileLoader->ShowOffset(pRichHeader->at(dwEntry).dwOffsetRich, 8, &m_stHexEdit);
}

int CViewRightBL::CreateHexNtHeaderEntry(DWORD dwEntry)
{
PCLIBPE_NTHEADER pNTHdr;
Expand Down Expand Up @@ -254,6 +276,69 @@ int CViewRightBL::CreateHexFileHeaderEntry(DWORD dwEntry)

int CViewRightBL::CreateHexOptHeaderEntry(DWORD dwEntry)
{
PCLIBPE_OPTHEADER_VAR pOptHdr;
if (m_pLibpe->GetOptionalHeader(pOptHdr) != S_OK)
return -1;
PCLIBPE_NTHEADER pNTHdr;
if (m_pLibpe->GetNTHeader(pNTHdr) != S_OK)
return -1;

if (m_pActiveWnd != &m_stHexEdit)
{
if (m_pActiveWnd)
m_pActiveWnd->ShowWindow(SW_HIDE);
m_pActiveWnd = &m_stHexEdit;
}

DWORD dwOffset, dwSize;
if (ImageHasFlag(m_dwFileSummary, IMAGE_FLAG_PE32))
{
dwOffset = pNTHdr->dwOffsetNTHdrDesc + offsetof(IMAGE_NT_HEADERS32, OptionalHeader) + g_mapOptHeader32.at(dwEntry).dwOffset;
dwSize = g_mapOptHeader32.at(dwEntry).dwSize;
}
else if (ImageHasFlag(m_dwFileSummary, IMAGE_FLAG_PE64))
{
dwOffset = pNTHdr->dwOffsetNTHdrDesc + offsetof(IMAGE_NT_HEADERS64, OptionalHeader) + g_mapOptHeader64.at(dwEntry).dwOffset;
dwSize = g_mapOptHeader64.at(dwEntry).dwSize;
}

CRect rc;
GetClientRect(&rc);
m_stHexEdit.SetWindowPos(this, 0, 0, rc.Width(), rc.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
m_pFileLoader->ShowOffset(dwOffset, dwSize, &m_stHexEdit);

return 0;
}

int CViewRightBL::CreateHexDataDirsEntry(DWORD dwEntry)
{
PCLIBPE_OPTHEADER_VAR pOptHdr;
if (m_pLibpe->GetOptionalHeader(pOptHdr) != S_OK)
return -1;
PCLIBPE_NTHEADER pNTHdr;
if (m_pLibpe->GetNTHeader(pNTHdr) != S_OK)
return -1;

if (m_pActiveWnd != &m_stHexEdit)
{
if (m_pActiveWnd)
m_pActiveWnd->ShowWindow(SW_HIDE);
m_pActiveWnd = &m_stHexEdit;
}

DWORD dwOffset, dwSize = sizeof(IMAGE_DATA_DIRECTORY);
if (ImageHasFlag(m_dwFileSummary, IMAGE_FLAG_PE32))
dwOffset = pNTHdr->dwOffsetNTHdrDesc + offsetof(IMAGE_NT_HEADERS32, OptionalHeader)
+ offsetof(IMAGE_OPTIONAL_HEADER32, DataDirectory) + sizeof(IMAGE_DATA_DIRECTORY) * dwEntry;
else if (ImageHasFlag(m_dwFileSummary, IMAGE_FLAG_PE64))
dwOffset = pNTHdr->dwOffsetNTHdrDesc + offsetof(IMAGE_NT_HEADERS64, OptionalHeader)
+ offsetof(IMAGE_OPTIONAL_HEADER64, DataDirectory) + sizeof(IMAGE_DATA_DIRECTORY) * dwEntry;

CRect rc;
GetClientRect(&rc);
m_stHexEdit.SetWindowPos(this, 0, 0, rc.Width(), rc.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
m_pFileLoader->ShowOffset(dwOffset, dwSize, &m_stHexEdit);

return 0;
}

Expand All @@ -279,7 +364,7 @@ int CViewRightBL::CreateHexSecHeadersEntry(DWORD dwEntry)
return 0;
}

int CViewRightBL::CreateHexLoadConfigEntry(DWORD dwEntry)
int CViewRightBL::CreateHexLCDEntry(DWORD dwEntry)
{
PCLIBPE_LOADCONFIG pLCD;
if (m_pLibpe->GetLoadConfig(pLCD) != S_OK)
Expand Down Expand Up @@ -701,13 +786,16 @@ int CViewRightBL::CreateHexTLS()
if (m_pLibpe->GetTLS(pTLS) != S_OK)
return -1;

const auto& tlsRawData = pTLS->vecTLSRawData;
m_stHexEdit.SetData((PBYTE)tlsRawData.data(), tlsRawData.size());

if (m_pActiveWnd != &m_stHexEdit)
{
if (m_pActiveWnd)
m_pActiveWnd->ShowWindow(SW_HIDE);
m_pActiveWnd = &m_stHexEdit;
}
CRect rc;
GetClientRect(&rc);
m_stHexEdit.SetWindowPos(this, 0, 0, rc.Width(), rc.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
m_pActiveWnd = &m_stHexEdit;
m_pFileLoader->ShowFilePiece(pTLS->dwRawDataOffset, pTLS->dwRawDataSize, &m_stHexEdit);

return 0;
}
7 changes: 3 additions & 4 deletions Pepper/ViewRightTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,8 @@ BOOL CViewRightTL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_LIST_DOSHEADER_ENTRY, pNMI->iItem));
break;
case IDC_LIST_RICHHEADER:
if (pNMI->hdr.code == LISTEX_MSG_MENUSELECTED)
{
}
if (pNMI->hdr.code == LVN_ITEMCHANGED || pNMI->hdr.code == NM_CLICK)
m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_LIST_RICHHEADER_ENTRY, pNMI->iItem));
break;
case IDC_LIST_NTHEADER:
if (pNMI->hdr.code == LVN_ITEMCHANGED || pNMI->hdr.code == NM_CLICK)
Expand Down Expand Up @@ -659,7 +658,7 @@ int CViewRightTL::CreateListRichHeader()
PCLIBPE_RICHHEADER_VEC pRichHeader;
if (m_pLibpe->GetRichHeader(pRichHeader) != S_OK)
return -1;

m_listRichHdr.Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, IDC_LIST_RICHHEADER, &m_stListInfo);
m_listRichHdr.ShowWindow(SW_HIDE);
m_listRichHdr.InsertColumn(0, L"Offset", LVCFMT_CENTER, 90);
Expand Down
6 changes: 4 additions & 2 deletions Pepper/include/ViewRightBL.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ class CViewRightBL : public CScrollView
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
int CreateHexDosHeaderEntry(DWORD dwEntry);
int CreateHexRichHeaderEntry(DWORD dwEntry);
int CreateHexNtHeaderEntry(DWORD dwEntry);
int CreateHexFileHeaderEntry(DWORD dwEntry);
int CreateHexOptHeaderEntry(DWORD dwEntry);
int CreateHexDataDirsEntry(DWORD dwEntry);
int CreateHexSecHeadersEntry(DWORD dwEntry);
int CreateHexLoadConfigEntry(DWORD dwEntry);
int CreateHexLCDEntry(DWORD dwEntry);
int CreateListExportFuncs();
int CreateListImportEntry(DWORD dwEntry);
int CreateListDelayImportEntry(DWORD dwEntry);
int CreateListExportFuncs();
int CreateListRelocsEntry(DWORD dwEntry);
int CreateHexDebugEntry(DWORD dwEntry);
int CreateTreeResources();
Expand Down
3 changes: 2 additions & 1 deletion Pepper/include/libpe.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ namespace libpe
struct LIBPE_TLS {
DWORD dwOffsetTLS;
union LIBPE_TLS_VAR { IMAGE_TLS_DIRECTORY32 stTLSDir32; IMAGE_TLS_DIRECTORY64 stTLSDir64; } varTLS;
std::vector<std::byte> vecTLSRawData; std::vector<DWORD> vecTLSCallbacks;
DWORD dwRawDataOffset; DWORD dwRawDataSize;
std::vector<DWORD> vecTLSCallbacks;
};
using PCLIBPE_TLS = const LIBPE_TLS*;

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
This software is available under the "MIT License modified with The Commons Clause".

### [Latest release page](https://github.com/jovibor/Pepper/releases/latest)

[Microsoft Visual C++ Redistributable for Visual Studio 2017 might be needed.](https://aka.ms/vs/15/release/VC_redist.x86.exe)

0 comments on commit 5b526d8

Please sign in to comment.