diff --git a/Pepper/CMainFrm.cpp b/Pepper/CMainFrm.cpp index c3be07f..4b162aa 100644 --- a/Pepper/CMainFrm.cpp +++ b/Pepper/CMainFrm.cpp @@ -176,7 +176,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) auto pos = tabGroups.GetHeadPosition(); while (pos != nullptr) { - if (auto pTabCtrl = DYNAMIC_DOWNCAST(CMFCTabCtrl, tabGroups.GetNext(pos)); pTabCtrl == pWnd) { //Click on TabCtrl. + if (const auto pTabCtrl = DYNAMIC_DOWNCAST(CMFCTabCtrl, tabGroups.GetNext(pos)); pTabCtrl == pWnd) { //Click on TabCtrl. pTabCtrl->ScreenToClient(&pt); if (const auto iTab = pTabCtrl->GetTabFromPoint(pt); iTab != -1) { if (auto pWndTab = pTabCtrl->GetTabWnd(iTab); pWndTab != nullptr) { @@ -205,8 +205,9 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) { pTabCtrl->ScreenToClient(&pt); if (const auto iTab = pTabCtrl->GetTabFromPoint(pt); iTab != -1) { - if (const auto pTab = pTabCtrl->GetTabWnd(iTab); pTab != nullptr && pTab == pWndMBtnCurrDown) + if (const auto pTab = pTabCtrl->GetTabWnd(iTab); pTab != nullptr && pTab == pWndMBtnCurrDown) { pTab->SendMessageW(WM_CLOSE); + } } } } @@ -231,16 +232,15 @@ LRESULT CMainFrame::MDIClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP ::GetClientRect(hWnd, rc); CMemDC dcMem(dc, rc); auto pDC = &dcMem.GetDC(); - constexpr auto iLengthText = static_cast(std::size(WSTR_PEPPER_PRODUCT_NAME)) - 1; pDC->FillSolidRect(rc, RGB(190, 190, 190)); pDC->SelectObject(m_fontMDIClient); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(205, 205, 205)); //Shadow color. - pDC->DrawTextW(WSTR_PEPPER_PRODUCT_NAME, iLengthText, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER); + pDC->DrawTextW(L"Pepper", 6, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER); pDC->SetTextColor(RGB(193, 193, 193)); //Text color. rc.OffsetRect(-3, 2); - pDC->DrawTextW(WSTR_PEPPER_PRODUCT_NAME, iLengthText, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER); + pDC->DrawTextW(L"Pepper", 6, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER); } break; case WM_SIZE: @@ -256,7 +256,6 @@ LRESULT CMainFrame::MDIClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP void CMainFrame::MDIClientSize(HWND hWnd, WPARAM /*wParam*/, LPARAM lParam) { - constexpr auto iLengthText = static_cast(std::size(WSTR_PEPPER_PRODUCT_NAME)) - 1; const auto pDC = CDC::FromHandle(::GetDC(hWnd)); const auto iWidthNew = LOWORD(lParam); auto iFontSizeMin = 10; @@ -271,7 +270,7 @@ void CMainFrame::MDIClientSize(HWND hWnd, WPARAM /*wParam*/, LPARAM lParam) lf.lfHeight = -MulDiv(iFontSizeMin, m_iLOGPIXELSY, 72); m_fontMDIClient.CreateFontIndirectW(&lf); pDC->SelectObject(m_fontMDIClient); - stSizeText = pDC->GetTextExtent(WSTR_PEPPER_PRODUCT_NAME, iLengthText); + stSizeText = pDC->GetTextExtent(L"Pepper", 6); } ::ReleaseDC(hWnd, pDC->m_hDC); ::RedrawWindow(hWnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); diff --git a/Pepper/CPepper.cpp b/Pepper/CPepper.cpp index 861390e..5539ed8 100644 --- a/Pepper/CPepper.cpp +++ b/Pepper/CPepper.cpp @@ -28,7 +28,10 @@ class CAboutDlg : public CDialogEx BOOL CAboutDlg::OnInitDialog() { CDialogEx::OnInitDialog(); - GetDlgItem(IDC_LINK_PEPPER)->SetWindowTextW(WSTR_PEPPER_VERSION); + + const auto wstrVerPepper = std::format(L"Pepper: PE32/PE32+ Binaries Analyzer v{}.{}.{}", util::PEPPER_VERSION_MAJOR, + util::PEPPER_VERSION_MINOR, util::PEPPER_VERSION_PATCH); + GetDlgItem(IDC_LINK_PEPPER)->SetWindowTextW(wstrVerPepper.data()); const auto wstrVerLibpe = std::format(L"libpe: PE32/PE32+ Binaries Parsing Library v{}.{}.{}", libpe::LIBPE_VERSION_MAJOR, libpe::LIBPE_VERSION_MINOR, libpe::LIBPE_VERSION_PATCH); GetDlgItem(IDC_LINK_LIBPE)->SetWindowTextW(wstrVerLibpe.data()); diff --git a/Pepper/CPepperDoc.cpp b/Pepper/CPepperDoc.cpp index 4fccdee..2d99bcb 100644 --- a/Pepper/CPepperDoc.cpp +++ b/Pepper/CPepperDoc.cpp @@ -163,6 +163,11 @@ void CPepperDoc::OnResExtractAllPng() ExtractAllResToFile(GetResources(), EResType::RTYPE_PNG, m_wstrDocName); } +auto CPepperDoc::GetFileLoader()->CFileLoader& +{ + return m_stFileLoader; +} + void CPepperDoc::SetEditMode(bool fEditMode) { if (!m_stFileLoader.IsWritable()) { diff --git a/Pepper/CPepperDoc.h b/Pepper/CPepperDoc.h index 07ad151..56a344a 100644 --- a/Pepper/CPepperDoc.h +++ b/Pepper/CPepperDoc.h @@ -8,17 +8,16 @@ #include #include "CFileLoader.h" import Utility; -using namespace util; import libpe; using namespace libpe; class CPepperDoc : public CDocument { public: - CFileLoader m_stFileLoader; + [[nodiscard]] auto GetFileLoader() -> CFileLoader&; void SetEditMode(bool fEditMode); [[nodiscard]] bool IsEditMode() { return m_fEditMode; } - [[nodiscard]] auto GetFileInfo() -> PEFILEINFO&; + [[nodiscard]] auto GetFileInfo() -> util::PEFILEINFO&; [[nodiscard]] auto GetOffsetFromVA(ULONGLONG ullVA) -> DWORD; [[nodiscard]] auto GetOffsetFromRVA(ULONGLONG ullRVA) -> DWORD; [[nodiscard]] auto GetDOSHeader() -> std::optional&; @@ -53,12 +52,8 @@ class CPepperDoc : public CDocument DECLARE_DYNCREATE(CPepperDoc); DECLARE_MESSAGE_MAP(); private: + CFileLoader m_stFileLoader; std::wstring m_wstrDocName; //Opened document name. - bool m_fEditMode { false }; - bool m_fHasCur { false }; - bool m_fHasIco { false }; - bool m_fHasBmp { false }; - bool m_fHasPng { false }; std::optional m_optDOS; std::optional m_optRich; std::optional m_optNTHdr; @@ -76,5 +71,10 @@ class CPepperDoc : public CDocument std::optional m_optBoundImp; std::optional m_optDelayImp; std::optional m_optComDescr; - PEFILEINFO m_stFileInfo; + util::PEFILEINFO m_stFileInfo; + bool m_fEditMode { false }; + bool m_fHasCur { false }; + bool m_fHasIco { false }; + bool m_fHasBmp { false }; + bool m_fHasPng { false }; }; \ No newline at end of file diff --git a/Pepper/CSplitterEx.cpp b/Pepper/CSplitterEx.cpp index 0434f07..1cbcef4 100644 --- a/Pepper/CSplitterEx.cpp +++ b/Pepper/CSplitterEx.cpp @@ -16,9 +16,8 @@ END_MESSAGE_MAP() BOOL CSplitterEx::CreateStatic(CWnd* m_pParent, int nRows, int nCols, DWORD dwStyle, UINT nID) { - //If already created. if ((!m_vecRows.empty() && !m_vecCols.empty()) || !(nRows | nCols) || (nRows | nCols) > 16) - return FALSE; + return FALSE; //If already created. m_vecRows.resize(nRows, true); m_vecCols.resize(nCols, true); @@ -141,7 +140,8 @@ void CSplitterEx::RecalcPanes() for (auto iterRow = 0U; iterRow < m_vecRows.size(); ++iterRow) { for (auto iterCol = 0U; iterCol < m_vecCols.size(); ++iterCol) { //Finding an exact pane. - if (const auto iterPane = std::find_if(m_vecPanes.begin(), m_vecPanes.end(), [=](const SPANES& refData) { return refData.iRow == vecRowsOrdered[iterRow] && refData.iCol == vecColsOrdered[iterCol]; }); + if (const auto iterPane = std::find_if(m_vecPanes.begin(), m_vecPanes.end(), + [=](const SPANES& refData) { return refData.iRow == vecRowsOrdered[iterRow] && refData.iCol == vecColsOrdered[iterCol]; }); iterPane != m_vecPanes.end()) { const auto pPane = iterPane->pPane; pPane->SetDlgCtrlID(AFX_IDW_PANE_FIRST + iterRow * 16 + iterCol); diff --git a/Pepper/CSplitterEx.h b/Pepper/CSplitterEx.h index 0b8d12d..6449353 100644 --- a/Pepper/CSplitterEx.h +++ b/Pepper/CSplitterEx.h @@ -31,7 +31,6 @@ class CSplitterEx : public CSplitterWndEx { public: - DECLARE_DYNAMIC(CSplitterEx); BOOL CreateStatic(CWnd* m_pParent, int nRows, int nCols, DWORD dwStyle = WS_CHILD | WS_VISIBLE, UINT nID = AFX_IDW_PANE_FIRST)override; BOOL CreateView(int row, int col, CRuntimeClass* pViewClass, SIZE sizeInit, CCreateContext* pContext)override; bool AddNested(int row, int col, CWnd* pNested); @@ -39,14 +38,14 @@ class CSplitterEx : public CSplitterWndEx bool ShowRow(UINT nRow); bool HideCol(UINT nCol); bool ShowCol(UINT nCol); - DECLARE_MESSAGE_MAP() + DECLARE_MESSAGE_MAP(); + DECLARE_DYNAMIC(CSplitterEx); private: void RecalcPanes(); afx_msg void OnMouseMove(UINT nFlags, CPoint pt); void OnInvertTracker(const CRect& rect)override; private: - struct SPANES - { + struct SPANES { int iRow { }; //Row of the pane. int iCol { }; //Column of the pane. CWnd* pPane { }; //Pane pointer. diff --git a/Pepper/CViewRightBL.cpp b/Pepper/CViewRightBL.cpp index 927db66..a57f886 100644 --- a/Pepper/CViewRightBL.cpp +++ b/Pepper/CViewRightBL.cpp @@ -35,7 +35,7 @@ void CViewRightBL::OnInitialUpdate() m_pChildFrame = static_cast(GetParentFrame()); m_pMainDoc = static_cast(GetDocument()); - m_pFileLoader = &m_pMainDoc->m_stFileLoader; + m_pFileLoader = &m_pMainDoc->GetFileLoader(); m_stFileInfo = m_pMainDoc->GetFileInfo(); //Hex control for SecurityDir and TLSdir. @@ -204,7 +204,7 @@ void CViewRightBL::OnTreeSelChanged(NMHDR* pNMHDR, LRESULT* /*pResult*/) m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_SHOW_RESOURCE_RBR, 0), reinterpret_cast(&m_stResData)); } - else { //Update by default, with no pData — to clear the view. + else { //Update by default, with no pData — to clear the view. m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_SHOW_RESOURCE_RBR, 0), nullptr); } } diff --git a/Pepper/CViewRightTL.cpp b/Pepper/CViewRightTL.cpp index 241eb84..c9edff1 100644 --- a/Pepper/CViewRightTL.cpp +++ b/Pepper/CViewRightTL.cpp @@ -30,7 +30,7 @@ void CViewRightTL::OnInitialUpdate() m_pChildFrame = static_cast(GetParentFrame()); m_pMainDoc = static_cast(GetDocument()); - m_pFileLoader = &m_pMainDoc->m_stFileLoader; + m_pFileLoader = &m_pMainDoc->GetFileLoader(); LOGFONTW lf { }; StringCchCopyW(lf.lfFaceName, 9, L"Consolas"); @@ -59,7 +59,8 @@ void CViewRightTL::OnInitialUpdate() else { m_wstrFileType = L"File type: unknown"; } - m_wstrPepperVersion = WSTR_PEPPER_VERSION; + m_wstrPepperVersion = std::format(L"Pepper v{}.{}.{}", util::PEPPER_VERSION_MAJOR, + util::PEPPER_VERSION_MINOR, util::PEPPER_VERSION_PATCH); m_stlcs.stColor.clrTooltipText = RGB(255, 255, 255); m_stlcs.stColor.clrTooltipBk = RGB(0, 132, 132); diff --git a/Pepper/CViewRightTR.cpp b/Pepper/CViewRightTR.cpp index d21fe39..1ebff78 100644 --- a/Pepper/CViewRightTR.cpp +++ b/Pepper/CViewRightTR.cpp @@ -28,7 +28,7 @@ void CViewRightTR::OnInitialUpdate() m_pChildFrame = static_cast(GetParentFrame()); m_pMainDoc = static_cast(GetDocument()); - m_pFileLoader = &m_pMainDoc->m_stFileLoader; + m_pFileLoader = &m_pMainDoc->GetFileLoader(); //Hex control for Resources raw. m_hcs.hWndParent = m_hWnd; diff --git a/Pepper/Pepper.vcxproj b/Pepper/Pepper.vcxproj index 166ffaa..575dceb 100644 --- a/Pepper/Pepper.vcxproj +++ b/Pepper/Pepper.vcxproj @@ -71,7 +71,7 @@ stdcpp20 true /utf-8 %(AdditionalOptions) - dep\libpe\src\;dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep; + dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep; $(OutDir)$(PlatformToolsetVersion).pdb @@ -111,7 +111,7 @@ true stdcpp20 true - dep\libpe\src\;dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep; + dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep; /utf-8 %(AdditionalOptions) @@ -223,8 +223,6 @@ Document - CompileAsCppModule - CompileAsCppModule NotUsing NotUsing diff --git a/Pepper/Pepper.vcxproj.filters b/Pepper/Pepper.vcxproj.filters index c92c2db..217911c 100644 --- a/Pepper/Pepper.vcxproj.filters +++ b/Pepper/Pepper.vcxproj.filters @@ -40,9 +40,6 @@ Source Files - - Header Files - HexCtrl @@ -88,6 +85,9 @@ libpe + + Header Files + diff --git a/Pepper/Utility.ixx b/Pepper/Utility.ixx index 5a4d117..2cb5ec7 100644 --- a/Pepper/Utility.ixx +++ b/Pepper/Utility.ixx @@ -13,30 +13,16 @@ module; #include #include "HexCtrl.h" -#define PEPPER_PRODUCT_NAME L"Pepper" -#define PEPPER_PRODUCT_DESC L"PE files viewer, github.com/jovibor/Pepper" -#define PEPPER_COPYRIGHT_NAME L"(C) Jovibor 2019-2023" -#define PEPPER_MAJOR_VERSION 1 -#define PEPPER_MINOR_VERSION 5 -#define PEPPER_MAINTENANCE_VERSION 3 - -#define TO_WSTR_HELPER(x) L## #x -#define TO_WSTR(x) TO_WSTR_HELPER(x) -#define PEPPER_VERSION_WSTR PEPPER_PRODUCT_NAME L" - PE32/PE32+ binaries viewer v" TO_WSTR(PEPPER_MAJOR_VERSION) L"."\ - TO_WSTR(PEPPER_MINOR_VERSION) L"." TO_WSTR(PEPPER_MAINTENANCE_VERSION) -#define TO_WSTR_MAP(x) {x, L## #x} export module Utility; - import libpe; +#define TO_WSTR_MAP(x) {x, L## #x} + export namespace util { - constexpr const wchar_t WSTR_PEPPER_PRODUCT_NAME[] = PEPPER_PRODUCT_NAME; -#ifdef _WIN64 - constexpr const auto WSTR_PEPPER_VERSION = PEPPER_VERSION_WSTR L" (x64)"; -#else - constexpr const auto WSTR_PEPPER_VERSION = PEPPER_VERSION_WSTR L" (x86)"; -#endif + constexpr auto PEPPER_VERSION_MAJOR = 1; + constexpr auto PEPPER_VERSION_MINOR = 5; + constexpr auto PEPPER_VERSION_PATCH = 3; [[nodiscard]] inline auto StrToWstr(std::string_view sv, UINT uCodePage = CP_UTF8) -> std::wstring { diff --git a/Pepper/dep/libpe b/Pepper/dep/libpe index 1b2ce20..ffdc936 160000 --- a/Pepper/dep/libpe +++ b/Pepper/dep/libpe @@ -1 +1 @@ -Subproject commit 1b2ce205f71bb3a2d0795760382afd437220aedf +Subproject commit ffdc93628d691fdda443b24ef37001539038a96a