Skip to content

Commit

Permalink
Bug fix displaying 64-bit int and double values
Browse files Browse the repository at this point in the history
Added ASCII text to blog display
  • Loading branch information
zodiacon committed Dec 24, 2022
1 parent b3501c6 commit a959595
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion WFPExplorer/FilterConditionsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CString CFilterConditionsPage::GetColumnText(HWND, int row, int col) const {
case 0: return StringHelper::WFPConditionFieldKeyToString(cond.fieldKey);
case 1: return StringHelper::WFPConditionMatchToString(cond.matchType);
case 2: return StringHelper::WFPDataTypeToString(cond.conditionValue.type);
case 3: return StringHelper::WFPConditionValueToString(cond.conditionValue, true);
case 3: return StringHelper::WFPConditionValueToString(cond.conditionValue, true, true);
}
return CString();
}
Expand Down
17 changes: 8 additions & 9 deletions WFPExplorer/FiltersView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CString CFiltersView::GetColumnText(HWND, int row, int col) {
case ColumnType::Flags:
if (info->flags == 0)
return L"0";
return std::format(L"0x{:02X} ({})", info->flags,
return std::format(L"0x{:02X} ({})", info->flags,
(PCWSTR)StringHelper::WFPFilterFlagsToString(info->flags)).c_str();
case ColumnType::EffectiveWeight: return StringHelper::WFPValueToString(info->effectiveWeight, true);
case ColumnType::ProviderName: return GetProviderName(fi);
Expand All @@ -83,6 +83,7 @@ void CFiltersView::UpdateUI() const {
ui.UIEnable(ID_EDIT_PROPERTIES, selected == 1);
ui.UIEnable(ID_EDIT_DELETE, selected > 0);
ui.UIEnable(ID_EDIT_COPY, selected > 0);
ui.UIEnable(ID_EDIT_FINDNEXT, Frame()->GetFindDialog() != nullptr);
}

CString const& CFiltersView::GetProviderName(FilterInfo& info) const {
Expand Down Expand Up @@ -136,7 +137,7 @@ LRESULT CFiltersView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam
CImageList images;
images.Create(16, 16, ILC_COLOR32 | ILC_MASK, 1, 1);
UINT icons[] = { IDI_FILTER, IDI_FILTER_PERMIT, IDI_FILTER_BLOCK, IDI_FILTER_REFRESH };
for(auto icon : icons)
for (auto icon : icons)
images.AddIcon(AtlLoadIconImage(icon, 0, 16, 16));
m_List.SetImageList(images, LVSIL_SMALL);

Expand All @@ -157,7 +158,7 @@ LRESULT CFiltersView::OnProperties(WORD, WORD, HWND, BOOL&) {
}

LRESULT CFiltersView::OnActivate(UINT, WPARAM activate, LPARAM, BOOL&) {
if(activate)
if (activate)
UpdateUI();
return 0;
}
Expand All @@ -178,7 +179,7 @@ LRESULT CFiltersView::OnDeleteFilter(WORD, WORD, HWND, BOOL&) {
m_List.SelectAllItems(false);
Refresh();
}
if(deleted < selected)
if (deleted < selected)
AtlMessageBox(m_hWnd, std::format(L"Deleted {}/{} filters", deleted, selected).c_str(), IDS_TITLE, MB_ICONINFORMATION);

return 0;
Expand All @@ -198,10 +199,8 @@ LRESULT CFiltersView::OnSave(WORD, WORD, HWND, BOOL&) {

auto ok = IDOK == dlg.DoModal();
ThemeHelper::Resume();
if(ok) {
if(!ListViewHelper::SaveAll(dlg.m_szFileName, m_List, L",")) {
AtlMessageBox(m_hWnd, L"Error in opening file", IDS_TITLE, MB_ICONERROR);
}
if (ok && !ListViewHelper::SaveAll(dlg.m_szFileName, m_List, L",")) {
AtlMessageBox(m_hWnd, L"Error in opening file", IDS_TITLE, MB_ICONERROR);
}
return 0;
}
Expand Down Expand Up @@ -293,7 +292,7 @@ int CFiltersView::GetRowImage(HWND, int row, int) const {
}

void CFiltersView::OnStateChanged(HWND, int from, int to, UINT oldState, UINT newState) {
if((newState & LVIS_SELECTED) || (oldState & LVIS_SELECTED))
if ((newState & LVIS_SELECTED) || (oldState & LVIS_SELECTED))
UpdateUI();
}

Expand Down
22 changes: 16 additions & 6 deletions WFPExplorer/StringHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ CString StringHelper::WFPValueToString(FWP_VALUE const& value, bool hex, bool fu
case FWP_INT32: str.Format(hex ? L"0x%X" : L"%d", value.int32); break;
case FWP_UINT16: str.Format(hex ? L"0x%X" : L"%u", (uint32_t)value.uint16); break;
case FWP_UINT32: str.Format(hex ? L"0x%X" : L"%u", value.uint32); break;
case FWP_INT64: str.Format(hex ? L"0x%llX" : L"%lld", value.int64); break;
case FWP_UINT64: str.Format(hex ? L"0x%llX" : L"%llu", value.uint64); break;
case FWP_INT64: str.Format(hex ? L"0x%llX" : L"%lld", *value.int64); break;
case FWP_UINT64: str.Format(hex ? L"0x%llX" : L"%llu", *value.uint64); break;
case FWP_FLOAT: str.Format(L"%f", value.float32); break;
case FWP_DOUBLE: str.Format(L"%lf", value.double64); break;
case FWP_DOUBLE: str.Format(L"%lf", *value.double64); break;
case FWP_UNICODE_STRING_TYPE: return value.unicodeString;
case FWP_BYTE_ARRAY6_TYPE: return FormatBinary(value.byteArray6->byteArray6, 6);
case FWP_BYTE_ARRAY16_TYPE: return FormatBinary(value.byteArray16->byteArray16, 16);
case FWP_BYTE_BLOB_TYPE: return std::format(L"({} bytes) \r\n", value.byteBlob->size).c_str() +
FormatBinary(value.byteBlob->data, full ? value.byteBlob->size : min(16, value.byteBlob->size));
FormatBinary(value.byteBlob->data, full ? value.byteBlob->size : min(16, value.byteBlob->size), 16, full);
case FWP_SID: return FormatSID(value.sid);
case FWP_SECURITY_DESCRIPTOR_TYPE:
PWSTR sddl;
Expand Down Expand Up @@ -407,13 +407,23 @@ CString StringHelper::WFPConditionFieldKeyToString(GUID const& key) {
return GuidToString(key);
}

CString StringHelper::FormatBinary(BYTE const* buffer, ULONG size, int lineSize) {
CString StringHelper::FormatBinary(BYTE const* buffer, ULONG size, int lineSize, bool ascii) {
CString text;
CString asciiText;
for (ULONG i = 0; i < size; i++) {
text += std::format(L"{:02X} ", buffer[i]).c_str();
if (i % lineSize == lineSize - 1)
if (ascii)
asciiText += isprint(buffer[i]) ? (WCHAR)buffer[i] : L'.';
if (i % lineSize == lineSize - 1) {
if (ascii) {
text += L" " + asciiText;
asciiText.Empty();
}
text += L"\r\n";
}
}
if(ascii && !asciiText.IsEmpty())
text += std::wstring(3 * (lineSize - size % lineSize) + 2, L' ').c_str() + asciiText;
return text;
}

Expand Down
2 changes: 1 addition & 1 deletion WFPExplorer/StringHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct StringHelper abstract final {
static PCWSTR WFPConditionMatchToString(FWP_MATCH_TYPE type);
static PCWSTR WFPDataTypeToString(FWP_DATA_TYPE type);
static CString WFPConditionFieldKeyToString(GUID const& key);
static CString FormatBinary(BYTE const* buffer, ULONG size, int lineSize = 16);
static CString FormatBinary(BYTE const* buffer, ULONG size, int lineSize = 16, bool ascii = false);
static CString FormatSID(PSID const sid);
static PCWSTR WFPFieldTypeToString(FWPM_FIELD_TYPE type);
static CString FormatIpv4Address(UINT32 address);
Expand Down
8 changes: 4 additions & 4 deletions WFPExplorer/WFPExplorer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,5,0,0
PRODUCTVERSION 0,5,0,0
FILEVERSION 0,5,2,0
PRODUCTVERSION 0,5,2,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -476,12 +476,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Scorpio Software"
VALUE "FileDescription", "Windows Filtering Platform Explorer"
VALUE "FileVersion", "0.5.0.0"
VALUE "FileVersion", "0.5.2.0"
VALUE "InternalName", "WFPExplorer"
VALUE "LegalCopyright", "�2022 Pavel Yosifovich"
VALUE "OriginalFilename", "WFPExplorer.exe"
VALUE "ProductName", "WFP Explorer"
VALUE "ProductVersion", "0.5.0.0"
VALUE "ProductVersion", "0.5.2.0"
END
END
BLOCK "VarFileInfo"
Expand Down

0 comments on commit a959595

Please sign in to comment.