Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
parse string table resources
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed May 6, 2022
1 parent 6927618 commit 3b7f2fd
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 42 deletions.
4 changes: 2 additions & 2 deletions TotalPE/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void CMainFrame::BuildTreeImageList() {
IDI_DELAY_IMPORT, IDI_EXCEPTION, IDI_SHIELD2, IDI_RELOC,

IDI_MANIFEST, IDI_VERSION, IDI_ICONS, IDI_CURSORS, IDI_DIALOGS,
IDI_BITMAP, IDI_FONT, IDI_HTML,
IDI_BITMAP, IDI_FONT, IDI_HTML, IDI_TEXT,
};

for (auto icon : icons)
Expand Down Expand Up @@ -234,7 +234,7 @@ void CMainFrame::ParseResources(HTREEITEM hRoot) {

int CMainFrame::ResourceTypeIconIndex(WORD type) {
static const int indices[] = {
-1, 3, 5, 2, -1, 4, -1, // string table
-1, 3, 5, 2, -1, 4, 8, // string table
-1, 6, 6, -1, -1, 3, // group cursor
-1, 2, -1, 1, 4, -1, -1, // P&P
-1, -1, -1, 7, 0, // manifest
Expand Down
81 changes: 53 additions & 28 deletions TotalPE/MessageTableView.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
#include "pch.h"
#include "MessageTableView.h"
#include "SortHelper.h"
#include "ClipboardHelper.h"

void CMessageTableView::SetData(uint8_t const* data) {
m_data = data;
BuildItems();
void CMessageTableView::SetMessageTableData(uint8_t const* data) {
uint32_t index = 0;
m_Items.clear();
m_Items.reserve(32);
auto res = (MESSAGE_RESOURCE_DATA const*)data;
for (DWORD i = 0; i < res->NumberOfBlocks; i++) {
auto const& block = res->Blocks[i];
auto entries = (MESSAGE_RESOURCE_ENTRY*)((PBYTE const)res + block.OffsetToEntries);
for (DWORD id = block.LowId; id <= block.HighId; id++) {
Item item;
item.Index = ++index;
item.Id = id;
if (entries->Flags & 1)
item.Text = (PCWSTR)CString((PCWSTR)entries->Text, entries->Length / sizeof(WCHAR));
else
item.Text = (PCWSTR)CString(CStringA((PCSTR)entries->Text, entries->Length));
m_Items.push_back(std::move(item));
entries = (MESSAGE_RESOURCE_ENTRY*)((PBYTE)entries + entries->Length);
}
}
m_List.SetItemCount((int)m_Items.size());
}

void CMessageTableView::SetStringTableData(uint8_t const* data, int size, UINT id) {
m_Items.clear();
m_Items.reserve(32);

UINT index = 0;
auto st = (WORD const*)data;
id = (id - 1) * 16;
while (size > 0) {
while (*st == 0) {
st++;
id++;
size -= 2;
}
if (size <= 0)
break;
std::wstring s((PCWSTR)(st + 1), *st);
m_Items.push_back({ ++index, id++, std::move(s) });
size -= (*st + 1) * 2;
st += *st + 1;
}
m_List.SetItemCount((int)m_Items.size());
}

CString CMessageTableView::GetColumnText(HWND, int row, int col) const {
auto& item = m_Items[row];
switch (col) {
case 0: return std::to_wstring(item.Index).c_str();
case 1: return std::format(L"0x{:X}", item.Id).c_str();
case 2: return item.Text;
case 2: return item.Text.c_str();
}
return CString();
}
Expand Down Expand Up @@ -42,33 +84,16 @@ LRESULT CMessageTableView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
cm->AddColumn(L"Index", LVCFMT_RIGHT, 80);
cm->AddColumn(L"ID", LVCFMT_RIGHT, 80);
cm->AddColumn(L"Text", LVCFMT_LEFT, 600);
m_List.DeleteColumn(0);
cm->UpdateColumns();
cm->DeleteColumn(0);

return 0;
}

void CMessageTableView::BuildItems() {
ATLASSERT(m_data);
auto data = m_data;
uint32_t index = 0;
m_Items.clear();
m_Items.reserve(32);
auto res = (MESSAGE_RESOURCE_DATA*)data;
for (DWORD i = 0; i < res->NumberOfBlocks; i++) {
auto& block = res->Blocks[i];
auto entries = (MESSAGE_RESOURCE_ENTRY*)((PBYTE)res + block.OffsetToEntries);
for (DWORD id = block.LowId; id <= block.HighId; id++) {
Item item;
item.Index = ++index;
item.Id = id;
if (entries->Flags & 1)
item.Text = CString((PCWSTR)entries->Text, entries->Length / sizeof(WCHAR));
else
item.Text = CStringA((PCSTR)entries->Text, entries->Length);
m_Items.push_back(std::move(item));
entries = (MESSAGE_RESOURCE_ENTRY*)((PBYTE)entries + entries->Length);
}
}
m_List.SetItemCount((int)m_Items.size());
LRESULT CMessageTableView::OnCopy(WORD, WORD, HWND, BOOL&) const {
auto text = ListViewHelper::GetSelectedRowsAsString(m_List);
if (!text.IsEmpty())
ClipboardHelper::CopyText(m_hWnd, text);
return 0;
}

10 changes: 5 additions & 5 deletions TotalPE/MessageTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ class CMessageTableView :
public:
using CView::CView;

void SetData(uint8_t const* data);
void SetMessageTableData(uint8_t const* data);
void SetStringTableData(uint8_t const* data, int size, UINT id);

CString GetColumnText(HWND, int row, int col) const;
void DoSort(SortInfo const* si);

BEGIN_MSG_MAP(CMessageTableView)
COMMAND_ID_HANDLER(ID_EDIT_COPY, OnCopy)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CView<CMessageTableView>)
CHAIN_MSG_MAP(CVirtualListView<CMessageTableView>)
END_MSG_MAP()

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) const;

private:
struct Item {
uint32_t Index;
uint32_t Id;
CString Text;
std::wstring Text;
};

void BuildItems();

CListViewCtrl m_List;
SortedFilteredVector<Item> m_Items;
uint8_t const* m_data{ nullptr };
};

2 changes: 2 additions & 0 deletions TotalPE/TotalPE.rc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ IDI_SHIELD2 ICON "res\\shield.ico"

IDI_RELOC ICON "res\\relocation.ico"

IDI_TEXT ICON "res\\text.ico"


/////////////////////////////////////////////////////////////////////////////
//
Expand Down
9 changes: 5 additions & 4 deletions TotalPE/TotalPE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..;..\WTLHelper\WTLHelper</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;..\WTLHelper</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
Expand Down Expand Up @@ -121,7 +121,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..;..\WTLHelper\WTLHelper</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;..\WTLHelper</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
Expand Down Expand Up @@ -154,7 +154,7 @@
<DebugInformationFormat />
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..;..\WTLHelper\WTLHelper</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;..\WTLHelper</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
Expand Down Expand Up @@ -186,7 +186,7 @@
<DebugInformationFormat />
<PreprocessorDefinitions>_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..;..\WTLHelper\WTLHelper</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..;..\WTLHelper</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
Expand Down Expand Up @@ -325,6 +325,7 @@
<Image Include="res\section.ico" />
<Image Include="res\sections.ico" />
<Image Include="res\shield.ico" />
<Image Include="res\text.ico" />
<Image Include="res\time-import.ico" />
<Image Include="res\TotalPE.ico" />
<Image Include="res\version.ico" />
Expand Down
3 changes: 3 additions & 0 deletions TotalPE/TotalPE.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@
<Image Include="res\relocation.ico">
<Filter>Resource Files\Icons</Filter>
</Image>
<Image Include="res\text.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
8 changes: 7 additions & 1 deletion TotalPE/ViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ HWND ViewManager::CreateOrGetView(TreeItemType type, HWND hParent, pe_image_full
else if (typeName == L"Message Table") {
auto view = new CMessageTableView(m_pFrame, pe);
hView = view->DoCreate(hParent);
view->SetData(data.data());
view->SetMessageTableData(data.data());
}
else if (typeName == L"String Table") {
auto view = new CMessageTableView(m_pFrame, pe);
hView = view->DoCreate(hParent);
auto sid = m_pFrame->GetTreeItemText(1);
view->SetStringTableData(data.data(), (ULONG)data.size(), _wtoi(sid.Mid(1)));
}
else {
auto view = new CReadOnlyHexView(m_pFrame);
Expand Down
Binary file modified TotalPE/res/text.ico
Binary file not shown.
4 changes: 3 additions & 1 deletion TotalPE/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#define IDI_CODE 240
#define IDI_SHIELD2 241
#define IDI_RELOC 242
#define IDI_ICON1 243
#define IDI_TEXT 243
#define IDC_EXTLINK 1000
#define IDC_LINK 1001
#define ID_OPTIONS_ALWAYSONTOP 32775
Expand Down Expand Up @@ -92,7 +94,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 243
#define _APS_NEXT_RESOURCE_VALUE 244
#define _APS_NEXT_COMMAND_VALUE 32813
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 102
Expand Down
2 changes: 1 addition & 1 deletion WTLHelper
Submodule WTLHelper updated 78 files
+17 −0 BasicDemo/AboutDlg.cpp
+25 −0 BasicDemo/AboutDlg.h
+44 −0 BasicDemo/BasicDemo.cpp
+1 −0 BasicDemo/BasicDemo.h
+310 −0 BasicDemo/BasicDemo.rc
+249 −0 BasicDemo/BasicDemo.vcxproj
+64 −0 BasicDemo/BasicDemo.vcxproj.filters
+103 −0 BasicDemo/MainFrm.cpp
+51 −0 BasicDemo/MainFrm.h
+162 −0 BasicDemo/ProcessTreeListView.cpp
+57 −0 BasicDemo/ProcessTreeListView.h
+4 −0 BasicDemo/packages.config
+5 −0 BasicDemo/pch.cpp
+41 −0 BasicDemo/pch.h
+ BasicDemo/res/BasicDemo.ico
+23 −0 BasicDemo/resource.h
+0 −0 ClipboardHelper.cpp
+0 −0 ClipboardHelper.h
+0 −0 ColorHelper.cpp
+0 −0 ColorHelper.h
+0 −0 ColumnManager.cpp
+0 −0 ColumnManager.h
+0 −0 CompoundFile.cpp
+0 −0 CompoundFile.h
+0 −0 CompoundFileReaderWriter.cpp
+0 −0 CompoundFileReaderWriter.h
+1 −0 CustomButton.h
+0 −0 CustomDialog.h
+0 −0 CustomEdit.h
+0 −0 CustomHeader.h
+0 −0 CustomListView.h
+0 −0 CustomRebar.h
+0 −0 CustomStatusBar.h
+0 −0 CustomTabControl.h
+1 −1 CustomTabView.cpp
+0 −0 CustomTabView.h
+21 −0 CustomTreeView.h
+0 −0 DialogHelper.h
+0 −0 IListView.cpp
+0 −0 IListView.h
+0 −0 IconHelper.cpp
+0 −0 IconHelper.h
+0 −0 IniFile.cpp
+0 −0 IniFile.h
+0 −0 ListViewhelper.cpp
+0 −0 ListViewhelper.h
+0 −0 OwnerDrawnMenu.cpp
+0 −0 OwnerDrawnMenu.h
+0 −0 QuickFindEdit.h
+0 −0 Settings.cpp
+0 −0 Settings.h
+0 −0 SizeGrip.h
+0 −0 SortHelper.cpp
+0 −0 SortHelper.h
+0 −0 SortedFilteredVector.h
+0 −0 StandardColors.h
+0 −0 StringHelper.cpp
+0 −0 StringHelper.h
+0 −0 Theme.cpp
+0 −0 Theme.h
+0 −0 ThemeHelper.cpp
+0 −0 ThemeHelper.h
+0 −0 ToolbarHelper.cpp
+0 −0 ToolbarHelper.h
+0 −0 TreeListViewCtrl.cpp
+0 −0 TreeListViewCtrl.h
+6 −6 TreeViewHelper.h
+0 −0 UIFramework.h
+0 −0 VersionResourceHelper.cpp
+0 −0 VersionResourceHelper.h
+0 −0 VirtualListView.h
+0 −0 WTLHelper.cpp
+9 −3 WTLHelper.sln
+6 −6 WTLHelper.vcxproj
+0 −0 WTLHelper.vcxproj.filters
+0 −0 packages.config
+0 −0 pch.cpp
+0 −0 pch.h

0 comments on commit 3b7f2fd

Please sign in to comment.