basic sessions view

This commit is contained in:
Pavel Yosifovich
2022-10-31 10:20:15 -04:00
parent 1d1c129bdd
commit 0886fed2d5
25 changed files with 408 additions and 145 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "WTLHelper"]
path = WTLHelper
url = https://github.com/zodiacon/WTLHelper.git
+3
View File
@@ -3,3 +3,6 @@
#include "pch.h"
#pragma comment(lib, "Fwpuclnt.lib")
#pragma comment(lib, "Shlwapi.lib")
+8
View File
@@ -78,6 +78,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>
@@ -95,6 +97,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>
@@ -112,6 +116,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>
@@ -129,6 +135,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>
+28 -67
View File
@@ -23,37 +23,6 @@ DWORD WFPEngine::LastError() const {
return m_LastError;
}
std::vector<WFPSessionInfo> WFPEngine::EnumSessions() const {
HANDLE hEnum;
std::vector<WFPSessionInfo> info;
m_LastError = FwpmSessionCreateEnumHandle(m_hEngine, nullptr, &hEnum);
if (m_LastError != ERROR_SUCCESS)
return info;
UINT32 count;
FWPM_SESSION** sessions;
if ((m_LastError = FwpmSessionEnum(m_hEngine, hEnum, 128, &sessions, &count)) == ERROR_SUCCESS) {
info.reserve(count);
for (UINT32 i = 0; i < count; i++) {
auto session = sessions[i];
WFPSessionInfo si;
si.Name = ParseMUIString(session->displayData.name);
si.Desc = ParseMUIString(session->displayData.description);
si.SessionKey = session->sessionKey;
si.ProcessId = session->processId;
si.UserName = session->username;
si.Flags = session->flags;
::CopySid(sizeof(si.Sid), (PSID)si.Sid, session->sid);
si.KernelMode = session->kernelMode;
info.emplace_back(std::move(si));
}
FwpmFreeMemory((void**)&sessions);
}
m_LastError = FwpmSessionDestroyEnumHandle(m_hEngine, hEnum);
return info;
}
std::vector<WFPLayerInfo> WFPEngine::EnumLayers() const {
HANDLE hEnum;
std::vector<WFPLayerInfo> info;
@@ -89,6 +58,34 @@ std::vector<WFPLayerInfo> WFPEngine::EnumLayers() const {
return info;
}
std::vector<WFPSubLayerInfo> WFPEngine::EnumSubLayers() const {
HANDLE hEnum;
std::vector<WFPSubLayerInfo> info;
m_LastError = FwpmSubLayerCreateEnumHandle(m_hEngine, nullptr, &hEnum);
if (m_LastError)
return info;
FWPM_SUBLAYER** layers;
UINT32 count;
m_LastError = FwpmSubLayerEnum(m_hEngine, hEnum, 256, &layers, &count);
if (m_LastError == ERROR_SUCCESS) {
info.reserve(count);
for (UINT32 i = 0; i < count; i++) {
auto layer = layers[i];
WFPSubLayerInfo li;
li.Name = ParseMUIString(layer->displayData.name);
li.Desc = ParseMUIString(layer->displayData.description);
li.SubLayerKey = layer->subLayerKey;
li.Flags = layer->flags;
li.Weight = layer->weight;
li.ProviderKey = layer->providerKey ? *layer->providerKey : GUID_NULL;
li.ProviderData.resize(layer->providerData.size);
memcpy(li.ProviderData.data(), layer->providerData.data, layer->providerData.size);
info.emplace_back(std::move(li));
}
}
return info;
}
std::vector<WFPProviderInfo> WFPEngine::EnumProviders(bool includeData) const {
HANDLE hEnum;
std::vector<WFPProviderInfo> info;
@@ -143,41 +140,6 @@ std::vector<WFPCalloutInfo> WFPEngine::EnumCallouts() const {
return info;
}
std::vector<WFPFilterInfo> WFPEngine::EnumFilters(bool includeConditions) const {
HANDLE hEnum;
std::vector<WFPFilterInfo> info;
m_LastError = FwpmFilterCreateEnumHandle(m_hEngine, nullptr, &hEnum);
if (m_LastError)
return info;
FWPM_FILTER** filters;
UINT32 count;
m_LastError = FwpmFilterEnum(m_hEngine, hEnum, 4096, &filters, &count);
if (m_LastError == ERROR_SUCCESS) {
info.reserve(count);
for (UINT32 i = 0; i < count; i++) {
auto filter = filters[i];
WFPFilterInfo fi;
fi.FilterKey = filter->filterKey;
fi.FilterId = filter->filterId;
fi.ProviderKey = filter->providerKey ? *filter->providerKey : GUID_NULL;
fi.Name = ParseMUIString(filter->displayData.name);
fi.Desc = ParseMUIString(filter->displayData.description);
fi.ConditionCount = filter->numFilterConditions;
fi.EffectiveWeight = *(WFPValue*)&filter->effectiveWeight;
fi.LayerKey = filter->layerKey;
fi.SubLayerKey = filter->subLayerKey;
fi.Weight = *(WFPValue*)&filter->weight;
if (includeConditions) {
// TODO
}
info.emplace_back(std::move(fi));
}
FwpmFreeMemory((void**)&filters);
m_LastError = FwpmFilterDestroyEnumHandle(m_hEngine, hEnum);
}
return info;
}
WFPProviderInfo WFPEngine::GetProviderByKey(GUID const& guid) const {
FWPM_PROVIDER* provider;
m_LastError = FwpmProviderGetByKey(m_hEngine, &guid, &provider);
@@ -202,7 +164,6 @@ WFPProviderInfo WFPEngine::InitProvider(FWPM_PROVIDER* p, bool includeData) {
return pi;
}
std::wstring WFPEngine::ParseMUIString(PCWSTR input) {
if (input == nullptr)
return L"";
+82 -3
View File
@@ -3,6 +3,8 @@
#include <vector>
#include <atlsecurity.h>
#include <memory>
#include <type_traits>
#include <concepts>
struct WFPSessionInfo {
GUID SessionKey;
@@ -101,6 +103,16 @@ struct WFPLayerInfo {
UINT16 LayerId;
};
struct WFPSubLayerInfo {
GUID SubLayerKey;
std::wstring Name;
std::wstring Desc;
UINT32 Flags;
GUID ProviderKey;
std::vector<BYTE> ProviderData;
UINT16 Weight;
};
enum class WFPMatchType {
EQUAL,
GREATER,
@@ -195,11 +207,78 @@ public:
DWORD LastError() const;
//
// enumrations
// enumerations
//
std::vector<WFPSessionInfo> EnumSessions() const;
std::vector<WFPFilterInfo> EnumFilters(bool includeConditions = false) const;
template<typename TSession = WFPSessionInfo> requires std::is_base_of_v<WFPSessionInfo, TSession>
std::vector<TSession> EnumSessions() const {
HANDLE hEnum;
std::vector<TSession> info;
m_LastError = FwpmSessionCreateEnumHandle(m_hEngine, nullptr, &hEnum);
if (m_LastError != ERROR_SUCCESS)
return info;
UINT32 count;
FWPM_SESSION** sessions;
if ((m_LastError = FwpmSessionEnum(m_hEngine, hEnum, 128, &sessions, &count)) == ERROR_SUCCESS) {
info.reserve(count);
for (UINT32 i = 0; i < count; i++) {
auto session = sessions[i];
TSession si;
si.Name = ParseMUIString(session->displayData.name);
si.Desc = ParseMUIString(session->displayData.description);
si.SessionKey = session->sessionKey;
si.ProcessId = session->processId;
si.UserName = session->username;
si.Flags = session->flags;
::CopySid(sizeof(si.Sid), (PSID)si.Sid, session->sid);
si.KernelMode = session->kernelMode;
info.emplace_back(std::move(si));
}
FwpmFreeMemory((void**)&sessions);
}
m_LastError = FwpmSessionDestroyEnumHandle(m_hEngine, hEnum);
return info;
}
template<typename TFilter = WFPFilterInfo> requires std::is_base_of_v<WFPFilterInfo, TFilter>
std::vector<TFilter> EnumFilters(bool includeConditions = false) const {
HANDLE hEnum;
std::vector<TFilter> info;
m_LastError = FwpmFilterCreateEnumHandle(m_hEngine, nullptr, &hEnum);
if (m_LastError)
return info;
FWPM_FILTER** filters;
UINT32 count;
m_LastError = FwpmFilterEnum(m_hEngine, hEnum, 4096, &filters, &count);
if (m_LastError == ERROR_SUCCESS) {
info.reserve(count);
for (UINT32 i = 0; i < count; i++) {
auto filter = filters[i];
TFilter fi;
fi.FilterKey = filter->filterKey;
fi.FilterId = filter->filterId;
fi.ProviderKey = filter->providerKey ? *filter->providerKey : GUID_NULL;
fi.Name = ParseMUIString(filter->displayData.name);
fi.Desc = ParseMUIString(filter->displayData.description);
fi.ConditionCount = filter->numFilterConditions;
fi.EffectiveWeight = *(WFPValue*)&filter->effectiveWeight;
fi.LayerKey = filter->layerKey;
fi.SubLayerKey = filter->subLayerKey;
fi.Weight = *(WFPValue*)&filter->weight;
if (includeConditions) {
// TODO
}
info.emplace_back(std::move(fi));
}
FwpmFreeMemory((void**)&filters);
m_LastError = FwpmFilterDestroyEnumHandle(m_hEngine, hEnum);
}
return info;
}
std::vector<WFPLayerInfo> EnumLayers() const;
std::vector<WFPSubLayerInfo> EnumSubLayers() const;
std::vector<WFPProviderInfo> EnumProviders(bool includeData = false) const;
std::vector<WFPCalloutInfo> EnumCallouts() const;
+2
View File
@@ -14,5 +14,7 @@
#include <string>
#include <vector>
#include <memory>
#include <concepts>
#include <type_traits>
#endif //PCH_H
+28
View File
@@ -9,38 +9,66 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WFPExplorer", "WFPExplorer\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WFPCore", "WFPCore\WFPCore.vcxproj", "{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WTLHelper", "WTLHelper\WTLHelper.vcxproj", "{AE53419F-A769-4548-8E15-E311904DF7DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Debug|ARM64.ActiveCfg = Debug|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Debug|ARM64.Build.0 = Debug|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Debug|x64.ActiveCfg = Debug|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Debug|x64.Build.0 = Debug|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Debug|x86.ActiveCfg = Debug|Win32
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Debug|x86.Build.0 = Debug|Win32
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Release|ARM64.ActiveCfg = Release|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Release|ARM64.Build.0 = Release|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Release|x64.ActiveCfg = Release|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Release|x64.Build.0 = Release|x64
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Release|x86.ActiveCfg = Release|Win32
{838BF7A3-0019-47F4-9DA8-2DC1194BF8CB}.Release|x86.Build.0 = Release|Win32
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Debug|ARM64.ActiveCfg = Debug|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Debug|ARM64.Build.0 = Debug|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Debug|x64.ActiveCfg = Debug|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Debug|x64.Build.0 = Debug|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Debug|x86.ActiveCfg = Debug|Win32
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Debug|x86.Build.0 = Debug|Win32
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Release|ARM64.ActiveCfg = Release|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Release|ARM64.Build.0 = Release|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Release|x64.ActiveCfg = Release|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Release|x64.Build.0 = Release|x64
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Release|x86.ActiveCfg = Release|Win32
{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}.Release|x86.Build.0 = Release|Win32
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Debug|ARM64.ActiveCfg = Debug|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Debug|ARM64.Build.0 = Debug|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Debug|x64.ActiveCfg = Debug|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Debug|x64.Build.0 = Debug|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Debug|x86.ActiveCfg = Debug|Win32
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Debug|x86.Build.0 = Debug|Win32
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Release|ARM64.ActiveCfg = Release|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Release|ARM64.Build.0 = Release|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Release|x64.ActiveCfg = Release|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Release|x64.Build.0 = Release|x64
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Release|x86.ActiveCfg = Release|Win32
{1EC9C4CA-34FD-4BE0-9662-9D92C53B9A90}.Release|x86.Build.0 = Release|Win32
{AE53419F-A769-4548-8E15-E311904DF7DF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Debug|ARM64.Build.0 = Debug|ARM64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Debug|x64.ActiveCfg = Debug|x64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Debug|x64.Build.0 = Debug|x64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Debug|x86.ActiveCfg = Debug|Win32
{AE53419F-A769-4548-8E15-E311904DF7DF}.Debug|x86.Build.0 = Debug|Win32
{AE53419F-A769-4548-8E15-E311904DF7DF}.Release|ARM64.ActiveCfg = Release|ARM64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Release|ARM64.Build.0 = Release|ARM64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Release|x64.ActiveCfg = Release|x64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Release|x64.Build.0 = Release|x64
{AE53419F-A769-4548-8E15-E311904DF7DF}.Release|x86.ActiveCfg = Release|Win32
{AE53419F-A769-4548-8E15-E311904DF7DF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+4
View File
@@ -0,0 +1,4 @@
#pragma once
struct IMainFrame abstract {
};
+12 -4
View File
@@ -5,7 +5,7 @@
#include "pch.h"
#include "resource.h"
#include "AboutDlg.h"
#include "View.h"
#include "SessionsView.h"
#include "MainFrm.h"
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) {
@@ -20,10 +20,15 @@ BOOL CMainFrame::OnIdle() {
}
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
if (!m_Engine.Open()) {
AtlMessageBox(nullptr, L"Failed to open WFP Engine", IDR_MAINFRAME, MB_ICONERROR);
return -1;
}
CreateSimpleStatusBar();
m_hWndClient = m_view.Create(m_hWnd, rcDefault, nullptr,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0);
UISetCheck(ID_VIEW_STATUS_BAR, 1);
CMessageLoop* pLoop = _Module.GetMessageLoop();
@@ -35,6 +40,9 @@ LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/
CMenuHandle menuMain = GetMenu();
m_view.SetWindowMenu(menuMain.GetSubMenu(WINDOW_MENU_POSITION));
if (!m_Engine.Open()) {
AtlMessageBox(nullptr, L"Failed to open WFP Engine", IDR_MAINFRAME, MB_ICONERROR);
}
return 0;
}
@@ -53,9 +61,9 @@ LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCt
}
LRESULT CMainFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
CView* pView = new CView;
auto pView = new CSessionsView(this, m_Engine);
pView->Create(m_view, rcDefault, nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0);
m_view.AddPage(pView->m_hWnd, _T("Document"));
m_view.AddPage(pView->m_hWnd, _T("Sessions"));
// TODO: add code to initialize document
+7 -6
View File
@@ -1,15 +1,14 @@
// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include <WFPEngine.h>
#include "Interfaces.h"
class CMainFrame :
public CFrameWindowImpl<CMainFrame>,
public CAutoUpdateUI<CMainFrame>,
public CMessageFilter,
public CIdleHandler
{
public IMainFrame,
public CIdleHandler {
public:
DECLARE_FRAME_WND_CLASS(L"WFPExplorerMainWndClass", IDR_MAINFRAME)
@@ -46,4 +45,6 @@ public:
LRESULT OnWindowClose(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnWindowCloseAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnWindowActivate(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
WFPEngine m_Engine;
};
+31
View File
@@ -0,0 +1,31 @@
#include "pch.h"
#include "ProcessHelper.h"
CString ProcessHelper::GetProcessName(DWORD pid) {
static std::unordered_map<DWORD, CString> processes;
CString name;
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if (hProcess) {
WCHAR path[MAX_PATH];
DWORD size = _countof(path);
if (::QueryFullProcessImageName(hProcess, 0, path, &size))
name = wcsrchr(path, L'\\') + 1;
::CloseHandle(hProcess);
}
if(name.IsEmpty()) {
if (processes.empty()) {
auto hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ATLASSERT(hSnap != INVALID_HANDLE_VALUE);
PROCESSENTRY32 pe;
pe.dwSize = sizeof(pe);
::Process32First(hSnap, &pe);
while (::Process32Next(hSnap, &pe)) {
if (wcsrchr(pe.szExeFile, L'\\') == nullptr)
processes.insert({ pe.th32ProcessID, pe.szExeFile });
}
::CloseHandle(hSnap);
}
name = processes.at(pid);
}
return name;
}
+6
View File
@@ -0,0 +1,6 @@
#pragma once
struct ProcessHelper abstract final {
static CString GetProcessName(DWORD pid);
};
+57
View File
@@ -0,0 +1,57 @@
// View.cpp : implementation of the CSessionsView class
//
/////////////////////////////////////////////////////////////////////////////
#include "pch.h"
#include "resource.h"
#include "SessionsView.h"
#include <WFPEngine.h>
#include "StringHelper.h"
#include "ProcessHelper.h"
CSessionsView::CSessionsView(IMainFrame* frame, WFPEngine& engine) : CFrameView(frame), m_Engine(engine) {
}
BOOL CSessionsView::PreTranslateMessage(MSG* pMsg) {
pMsg;
return FALSE;
}
void CSessionsView::Refresh() {
m_Sessions = m_Engine.EnumSessions<Session>();
m_List.SetItemCountEx((int)m_Sessions.size(), LVSICF_NOSCROLL);
}
CString CSessionsView::GetColumnText(HWND, int row, int col) {
auto& session = m_Sessions[row];
switch (GetColumnManager(m_List)->GetColumnTag<ColumnType>(col)) {
case ColumnType::Key: return StringHelper::GuidToString(session.SessionKey);
case ColumnType::Name: return session.Name.c_str();
case ColumnType::Desc: return session.Desc.c_str();
case ColumnType::ProcessId: return std::to_wstring(session.ProcessId).c_str();
case ColumnType::Flags: return std::to_wstring(session.Flags).c_str();
case ColumnType::ProcessName:
if (session.ProcessName.IsEmpty())
session.ProcessName = ProcessHelper::GetProcessName(session.ProcessId);
return session.ProcessName;
}
return CString();
}
LRESULT CSessionsView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
m_hWndClient = m_List.Create(m_hWnd, rcDefault, nullptr,
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | LVS_OWNERDATA | LVS_REPORT | LVS_SHOWSELALWAYS);
m_List.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
auto cm = GetColumnManager(m_List);
cm->AddColumn(L"Session Key", 0, 250, ColumnType::Key);
cm->AddColumn(L"PID", LVCFMT_RIGHT, 90, ColumnType::ProcessId);
cm->AddColumn(L"Process Name", LVCFMT_LEFT, 180, ColumnType::ProcessName);
cm->AddColumn(L"Flags", LVCFMT_RIGHT, 80, ColumnType::Flags);
cm->AddColumn(L"Session Name", 0, 180, ColumnType::Name);
cm->AddColumn(L"Description", 0, 180, ColumnType::Desc);
Refresh();
return 0;
}
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include <FrameView.h>
#include <VirtualListView.h>
#include "Interfaces.h"
#include <WFPEngine.h>
class WFPEngine;
class CSessionsView :
public CFrameView<CSessionsView, IMainFrame>,
public CVirtualListView<CSessionsView> {
public:
CSessionsView(IMainFrame* frame, WFPEngine& engine);
DECLARE_WND_CLASS(nullptr)
BOOL PreTranslateMessage(MSG* pMsg);
void Refresh();
CString GetColumnText(HWND, int row, int col);
BEGIN_MSG_MAP(CSessionsView)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CVirtualListView<CSessionsView>)
CHAIN_MSG_MAP(BaseFrame)
END_MSG_MAP()
// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
private:
enum class ColumnType {
Key, Name, Desc, Flags, ProcessId, ProcessName,
};
struct Session : WFPSessionInfo {
CString ProcessName;
};
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
WFPEngine& m_Engine;
CListViewCtrl m_List;
std::vector<Session> m_Sessions;
};
+7
View File
@@ -0,0 +1,7 @@
#include "pch.h"
#include "StringHelper.h"
CString StringHelper::GuidToString(GUID const& guid) {
WCHAR sguid[64];
return ::StringFromGUID2(guid, sguid, _countof(sguid)) ? sguid : L"";
}
+6
View File
@@ -0,0 +1,6 @@
#pragma once
struct StringHelper abstract final {
static CString GuidToString(GUID const& guid);
};
-24
View File
@@ -1,24 +0,0 @@
// View.cpp : implementation of the CView class
//
/////////////////////////////////////////////////////////////////////////////
#include "pch.h"
#include "resource.h"
#include "View.h"
BOOL CView::PreTranslateMessage(MSG* pMsg) {
pMsg;
return FALSE;
}
void CView::OnFinalMessage(HWND /*hWnd*/) {
delete this;
}
LRESULT CView::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
CPaintDC dc(m_hWnd);
//TODO: Add your drawing code here
return 0;
}
-26
View File
@@ -1,26 +0,0 @@
// View.h : interface of the CView class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
class CView : public CWindowImpl<CView>
{
public:
DECLARE_WND_CLASS(nullptr)
BOOL PreTranslateMessage(MSG* pMsg);
virtual void OnFinalMessage(HWND /*hWnd*/);
BEGIN_MSG_MAP(CView)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
END_MSG_MAP()
// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
};
+8 -1
View File
@@ -4,6 +4,11 @@
#include "pch.h"
#include "resource.h"
#include "MainFrm.h"
#include <ThemeHelper.h>
#pragma comment(lib, "Fwpuclnt.lib")
#pragma comment(lib, "Shlwapi.lib")
CAppModule _Module;
@@ -26,7 +31,7 @@ int Run(LPTSTR /*lpstrCmdLine*/ = nullptr, int nCmdShow = SW_SHOWDEFAULT) {
return nRet;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) {
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) {
HRESULT hRes = ::CoInitialize(nullptr);
ATLASSERT(SUCCEEDED(hRes));
@@ -35,6 +40,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lp
hRes = _Module.Init(nullptr, hInstance);
ATLASSERT(SUCCEEDED(hRes));
ThemeHelper::Init();
int nRet = Run(lpstrCmdLine, nCmdShow);
_Module.Term();
+25 -2
View File
@@ -21,6 +21,7 @@
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<ProjectGuid>{67BC52CE-A4B4-4C3A-85B6-71B5C70BC2E0}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -87,6 +88,9 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\WTLHelper;..\WFPCore</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -119,6 +123,9 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\WTLHelper;..\WFPCore</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -151,6 +158,9 @@
<DebugInformationFormat />
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\WTLHelper;..\WFPCore</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -182,6 +192,9 @@
<DebugInformationFormat />
<PreprocessorDefinitions>_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\WTLHelper;..\WFPCore</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -212,15 +225,20 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="View.cpp" />
<ClCompile Include="ProcessHelper.cpp" />
<ClCompile Include="SessionsView.cpp" />
<ClCompile Include="StringHelper.cpp" />
<ClCompile Include="WFPExplorer.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AboutDlg.h" />
<ClInclude Include="Interfaces.h" />
<ClInclude Include="MainFrm.h" />
<ClInclude Include="ProcessHelper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="View.h" />
<ClInclude Include="SessionsView.h" />
<ClInclude Include="StringHelper.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="WFPExplorer.rc" />
@@ -242,15 +260,20 @@
<ProjectReference Include="..\WFPCore\WFPCore.vcxproj">
<Project>{1ec9c4ca-34fd-4be0-9662-9d92c53b9a90}</Project>
</ProjectReference>
<ProjectReference Include="..\WTLHelper\WTLHelper.vcxproj">
<Project>{ae53419f-a769-4548-8e15-e311904df7df}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\wtl.10.0.10320\build\native\wtl.targets" Condition="Exists('..\packages\wtl.10.0.10320\build\native\wtl.targets')" />
<Import Project="..\packages\Detours.4.0.1\build\native\Detours.targets" Condition="Exists('..\packages\Detours.4.0.1\build\native\Detours.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\wtl.10.0.10320\build\native\wtl.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\wtl.10.0.10320\build\native\wtl.targets'))" />
<Error Condition="!Exists('..\packages\Detours.4.0.1\build\native\Detours.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Detours.4.0.1\build\native\Detours.targets'))" />
</Target>
</Project>
+25 -4
View File
@@ -16,6 +16,12 @@
<Filter Include="Resource Files\Icons">
<UniqueIdentifier>{dd3ee917-d543-4f76-9565-2c62be172421}</UniqueIdentifier>
</Filter>
<Filter Include="Views">
<UniqueIdentifier>{badfa682-db92-4619-8c6c-b99b2a803286}</UniqueIdentifier>
</Filter>
<Filter Include="Dialogs">
<UniqueIdentifier>{f00a7e40-bce0-4e4b-98eb-144534e3639f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
@@ -27,10 +33,16 @@
<ClCompile Include="MainFrm.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="View.cpp">
<ClCompile Include="AboutDlg.cpp">
<Filter>Dialogs</Filter>
</ClCompile>
<ClCompile Include="SessionsView.cpp">
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="StringHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AboutDlg.cpp">
<ClCompile Include="ProcessHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -41,13 +53,22 @@
<ClInclude Include="MainFrm.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="View.h">
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AboutDlg.h">
<Filter>Dialogs</Filter>
</ClInclude>
<ClInclude Include="SessionsView.h">
<Filter>Views</Filter>
</ClInclude>
<ClInclude Include="Interfaces.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<ClInclude Include="StringHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ProcessHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Detours" version="4.0.1" targetFramework="native" developmentDependency="true" />
<package id="wtl" version="10.0.10320" targetFramework="native" />
</packages>
+8 -8
View File
@@ -1,13 +1,8 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
// Change these values to use different versions
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
#define WINVER 0x0603
#define _WIN32_WINNT 0x0603
#define _WIN32_IE 0x0700
#define _RICHEDIT_VER 0x0500
@@ -18,15 +13,20 @@
extern CAppModule _Module;
#include <atlwin.h>
#include <atlframe.h>
#include <atlctrls.h>
#include <atldlgs.h>
#include <atlctrlx.h>
#include <atlsplit.h>
#include <fwpmu.h>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <concepts>
#include <strsafe.h>
#include <dontuse.h>
#include <TlHelp32.h>
#if defined _M_IX86
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
Submodule
+1
Submodule WTLHelper added at d5d71a8c1e
+8
View File
@@ -78,6 +78,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -94,6 +96,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -110,6 +114,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -126,6 +132,8 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>