Skip to content

Commit

Permalink
[Added] TLS descriptor and data menu. [Fixes] List tooltiping fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovibor committed May 15, 2019
1 parent 1929e39 commit 2d7f271
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 24 deletions.
10 changes: 7 additions & 3 deletions Pepper/ListEx/src/CListEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,18 @@ UINT CListEx::GetFontSize()

void CListEx::SetCellTooltip(int iItem, int iSubitem, const wchar_t* pwszTooltip, const wchar_t* pwszCaption)
{
//Checking if nullptr, and assign empty string in this case.
const wchar_t* pCaption = pwszCaption ? pwszCaption : L"";
const wchar_t* pTooltip = pwszTooltip ? pwszTooltip : L"";

auto it = m_umapCellTt.find(iItem);

//If there is no tooltip for such item/subitem we just set it.
if (it == m_umapCellTt.end() && (pwszTooltip || pwszCaption))
{
//Initializing inner map.
std::unordered_map<int, std::tuple< std::wstring, std::wstring>> umapInner {
{ iSubitem, { pwszTooltip, pwszCaption } } };
{ iSubitem, { pTooltip, pCaption } } };
m_umapCellTt.insert({ iItem, std::move(umapInner) });
}
else
Expand All @@ -199,11 +203,11 @@ void CListEx::SetCellTooltip(int iItem, int iSubitem, const wchar_t* pwszTooltip
//If there is Item's tooltip but no Subitem's tooltip
//inserting new Subitem into inner map.
if (itInner == it->second.end())
it->second.insert({ iSubitem, { pwszTooltip, pwszCaption } });
it->second.insert({ iSubitem, { pTooltip, pCaption } });
else //If there is already exist this Item-Subitem's tooltip:
//change or erase it, depending on pwszTooltip emptiness.
if (pwszTooltip)
itInner->second = { pwszTooltip, pwszCaption };
itInner->second = { pwszTooltip, pCaption };
else
it->second.erase(itInner);
}
Expand Down
9 changes: 5 additions & 4 deletions Pepper/ViewRightBL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ BOOL CViewRightBL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
{
auto& data = lvl3vec[idlvl3].vecResRawDataLvL3;
//Resource data and resource type to show in CViewRightBR.
m_stResHelper.IdResType = rootvec[idlvlRoot].stResDirEntryRoot.Id;
m_stResHelper.IdResName = lvl2vec[idlvl2].stResDirEntryLvL2.Id;
m_stResHelper.pData = (std::vector<std::byte>*) & data;
m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_SHOW_RESOURCE_RBR, 0), reinterpret_cast<CObject*>(&m_stResHelper));
RESHELPER stResHelper { };
stResHelper.IdResType = rootvec[idlvlRoot].stResDirEntryRoot.Id;
stResHelper.IdResName = lvl2vec[idlvl2].stResDirEntryLvL2.Id;
stResHelper.pData = (std::vector<std::byte>*) & data;
m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_SHOW_RESOURCE_RBR, 0), reinterpret_cast<CObject*>(&stResHelper));
}
}
}
Expand Down
75 changes: 67 additions & 8 deletions Pepper/ViewRightTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void CViewRightTL::OnInitialUpdate()
m_stlcs.pHeaderLogFont = &m_hdrlf;

m_menuList.CreatePopupMenu();
m_menuList.AppendMenuW(MF_STRING, IDM_LIST_GOTODESCOFFSET, L"Go to descriptor offset...");
m_menuList.AppendMenuW(MF_STRING, IDM_LIST_GOTODATAOFFSET, L"Go to data offset...");
m_menuList.AppendMenuW(MF_STRING, IDM_LIST_GOTODESCOFFSET, L"Go to descriptor offset");
m_menuList.AppendMenuW(MF_STRING, IDM_LIST_GOTODATAOFFSET, L"Go to data offset");

CreateListDOSHeader();
CreateListRichHeader();
Expand Down Expand Up @@ -423,6 +423,7 @@ BOOL CViewRightTL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
return TRUE;

bool fx32 = ImageHasFlag(m_dwFileInfo, IMAGE_FLAG_PE32);
bool fx64 = ImageHasFlag(m_dwFileInfo, IMAGE_FLAG_PE64);
DWORD dwOffset, dwSize = 0;
switch (pNMI->hdr.idFrom)
{
Expand Down Expand Up @@ -472,7 +473,6 @@ BOOL CViewRightTL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
dwSize = sizeof(IMAGE_IMPORT_DESCRIPTOR);
break;
case IDM_LIST_GOTODATAOFFSET:
dwSize = 1;
switch (pNMI->iSubItem)
{
case 1: //Str dll name
Expand All @@ -484,7 +484,7 @@ BOOL CViewRightTL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
m_pLibpe->GetOffsetFromRVA(m_pImport->at(pNMI->iItem).stImportDesc.OriginalFirstThunk, dwOffset);
if (fx32)
dwSize = sizeof(IMAGE_THUNK_DATA32);
else
else if (fx64)
dwSize = sizeof(IMAGE_THUNK_DATA64);
break;
case 3: //TimeDateStamp
Expand All @@ -496,7 +496,7 @@ BOOL CViewRightTL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
m_pLibpe->GetOffsetFromRVA(m_pImport->at(pNMI->iItem).stImportDesc.FirstThunk, dwOffset);
if (fx32)
dwSize = sizeof(IMAGE_THUNK_DATA32);
else
else if (fx64)
dwSize = sizeof(IMAGE_THUNK_DATA64);
break;
}
Expand All @@ -519,12 +519,68 @@ BOOL CViewRightTL::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
case IDC_LIST_TLS:
if (pNMI->hdr.code == LISTEX_MSG_MENUSELECTED)
{
PCLIBPE_TLS pTLSDir;
if (m_pLibpe->GetTLS(pTLSDir) != S_OK)
return -1;

switch (pNMI->lParam)
{
case IDM_LIST_GOTODESCOFFSET:
dwOffset = pTLSDir->dwOffsetTLS;
if (fx32)
dwSize = sizeof(IMAGE_TLS_DIRECTORY32);
else if (fx64)
dwSize = sizeof(IMAGE_TLS_DIRECTORY64);
break;
case IDM_LIST_GOTODATAOFFSET:
break;
{
PCLIBPE_OPTHEADER_VAR pOpt;
if (m_pLibpe->GetOptionalHeader(pOpt) != S_OK)
return -1;
dwSize = 1;

if (fx32)
{
const IMAGE_TLS_DIRECTORY32* pTLSDir32 = &pTLSDir->varTLS.stTLSDir32;
const DWORD dwImageBase = pOpt->stOptHdr32.ImageBase;

switch (pNMI->iItem)
{
case 0: //StartAddressOfRawData
m_pLibpe->GetOffsetFromRVA(pTLSDir32->StartAddressOfRawData - dwImageBase, dwOffset);
break;
case 2: //AddressOfIndex
m_pLibpe->GetOffsetFromRVA(pTLSDir32->AddressOfIndex - dwImageBase, dwOffset);
break;
case 3: //AddressOfCallBacks
m_pLibpe->GetOffsetFromRVA(pTLSDir32->AddressOfCallBacks - dwImageBase, dwOffset);
break;
default:
dwSize = 0; //To not process other fields.
}
}
else if (fx64)
{
const IMAGE_TLS_DIRECTORY64* pTLSDir64 = &pTLSDir->varTLS.stTLSDir64;
const ULONGLONG dwImageBase = pOpt->stOptHdr64.ImageBase;

switch (pNMI->iItem)
{
case 0: //StartAddressOfRawData
m_pLibpe->GetOffsetFromRVA(pTLSDir64->StartAddressOfRawData - dwImageBase, dwOffset);
break;
case 2: //AddressOfIndex
m_pLibpe->GetOffsetFromRVA(pTLSDir64->AddressOfIndex - dwImageBase, dwOffset);
break;
case 3: //AddressOfCallBacks
m_pLibpe->GetOffsetFromRVA(pTLSDir64->AddressOfCallBacks - dwImageBase, dwOffset);
break;
default:
dwSize = 0; //To not process other fields.
}
}
}
break;
}
}
break;
Expand Down Expand Up @@ -631,6 +687,8 @@ int CViewRightTL::CreateListDOSHeader()
auto& ref = g_mapDOSHeader.at(i);
DWORD dwOffset = ref.dwOffset;
DWORD dwSize = ref.dwSize;

//Get a pointer to an offset and then take only needed amount of bytes (by &...).
DWORD dwValue = *((PDWORD)((DWORD_PTR)pDosHeader + dwOffset)) & (DWORD_MAX >> ((sizeof(DWORD) - dwSize) * 8));
if (i == 0)
dwValue = (dwValue & 0xFF00) >> 8 | (dwValue & 0xFF) << 8;
Expand Down Expand Up @@ -1502,6 +1560,7 @@ int CViewRightTL::CreateListTLS()
m_listTLSDir->InsertColumn(1, L"Name", LVCFMT_CENTER, 250);
m_listTLSDir->InsertColumn(2, L"Size [BYTES]", LVCFMT_LEFT, 110);
m_listTLSDir->InsertColumn(3, L"Value", LVCFMT_LEFT, 150);
m_listTLSDir->SetListMenu(&m_menuList);

const std::map<DWORD, std::wstring> mapCharact {
{ IMAGE_SCN_ALIGN_1BYTES, L"IMAGE_SCN_ALIGN_1BYTES" },
Expand All @@ -1524,7 +1583,7 @@ int CViewRightTL::CreateListTLS()
WCHAR wstr[18];
if (ImageHasFlag(m_dwFileInfo, IMAGE_FLAG_PE32))
{
const IMAGE_TLS_DIRECTORY32* pTLSDir32 = &pTLSDir->varTLS.stTLSDir32;
const IMAGE_TLS_DIRECTORY32* pTLSDir32 = &pTLSDir->varTLS.stTLSDir32;
for (unsigned i = 0; i < g_mapTLS32.size(); i++)
{
auto& ref = g_mapTLS32.at(i);
Expand All @@ -1549,7 +1608,7 @@ int CViewRightTL::CreateListTLS()
}
else if (ImageHasFlag(m_dwFileInfo, IMAGE_FLAG_PE64))
{
const IMAGE_TLS_DIRECTORY64* pTLSDir64 = &pTLSDir->varTLS.stTLSDir64;
const IMAGE_TLS_DIRECTORY64* pTLSDir64 = &pTLSDir->varTLS.stTLSDir64;
for (unsigned i = 0; i < g_mapTLS64.size(); i++)
{
auto& ref = g_mapTLS64.at(i);
Expand Down
1 change: 0 additions & 1 deletion Pepper/include/ViewRightBL.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ class CViewRightBL : public CView
CImageList m_imglTreeRes;
std::vector<std::tuple<long, long, long>> m_vecResId { };
LOGFONT m_lf { }, m_hdrlf { };
RESHELPER m_stResHelper { };
};
17 changes: 11 additions & 6 deletions Pepper/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ inline const std::map<DWORD, std::wstring> g_mapLibpeErrors {
{ E_IMAGE_HAS_NO_COMDESCRIPTOR, WSTR(E_IMAGE_HAS_NO_COMDESCRIPTOR) }
};

//All possible PE Resource types.
inline const std::map<WORD, std::wstring> g_mapResType {
{ 1, L"RT_CURSOR" },
{ 2, L"RT_BITMAP" },
Expand Down Expand Up @@ -77,15 +78,17 @@ inline const std::map<WORD, std::wstring> g_mapResType {
{ 241, L"RT_TOOLBAR" }
};

struct STRUCTHELPER
//Helper struct for PE structs' fields offsets and sizes.
//Reflection kind of.
struct PESTRUCTREFLECTION
{
DWORD dwSize;
DWORD dwOffset;
std::wstring wstrName;
DWORD dwSize; //Struct's field size.
DWORD dwOffset; //Field offset.
std::wstring wstrName; //Field name.
};
using map_hdr = std::map<DWORD, STRUCTHELPER>;
using map_hdr = std::map<DWORD, PESTRUCTREFLECTION>;

//Standard headers maps.
//Standard headers' maps.
inline const map_hdr g_mapDOSHeader {
{ 0, { sizeof(WORD), 0, L"e_magic" } },
{ 1, { sizeof(WORD), 2, L"e_cblp" } },
Expand Down Expand Up @@ -364,6 +367,8 @@ inline const map_hdr g_mapComDir {
};
////////////////////////////////////////////////////////////

//Helper struct for resources interchange
//between views.
struct RESHELPER
{
RESHELPER() {}
Expand Down
Binary file added Pepper/lib/libpe64.lib
Binary file not shown.
Binary file added Pepper/lib/libpe64d.lib
Binary file not shown.
Binary file added Pepper/lib/libped.lib
Binary file not shown.
4 changes: 2 additions & 2 deletions Pepper/verinfo/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define PRODUCT_DESC "PE files viewer: github.com/jovibor/Pepper"
#define COPYRIGHT_NAME "(C) Jovibor 2018"
#define MAJOR_VERSION 0
#define MINOR_VERSION 8
#define MAINTENANCE_VERSION 12
#define MINOR_VERSION 9
#define MAINTENANCE_VERSION 0
#define REVISION_VERSION 0

0 comments on commit 2d7f271

Please sign in to comment.