Skip to content

Commit

Permalink
upd project sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypp committed Dec 12, 2021
1 parent c069150 commit 483bdbf
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/listview.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ INT CALLBACK _app_listview_compare_callback (_In_ LPARAM lparam1, _In_ LPARAM lp

result = 0;

if ((_r_listview_getexstyle (hwnd, listview_id) & LVS_EX_CHECKBOXES) != 0)
if ((_r_listview_getstyle_ex (hwnd, listview_id) & LVS_EX_CHECKBOXES) != 0)
{
is_checked1 = _r_listview_isitemchecked (hwnd, listview_id, item_id1);
is_checked2 = _r_listview_isitemchecked (hwnd, listview_id, item_id2);
Expand Down
7 changes: 4 additions & 3 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ VOID CALLBACK _wfp_logcallback (_In_ PITEM_LOG_CALLBACK log)
PR_STRING sid_string;
UINT8 filter_weight;
BOOLEAN is_myprovider;
NTSTATUS status;

engine_handle = _wfp_getenginehandle ();

Expand Down Expand Up @@ -498,9 +499,9 @@ VOID CALLBACK _wfp_logcallback (_In_ PITEM_LOG_CALLBACK log)
// get package id (win8+)
if ((log->flags & FWPM_NET_EVENT_FLAG_PACKAGE_ID_SET) && log->package_id)
{
sid_string = _r_str_fromsid (log->package_id);
status = _r_str_fromsid (log->package_id, &sid_string);

if (sid_string)
if (status == STATUS_SUCCESS)
{
if (!_app_isappfound (_r_str_gethash2 (sid_string, TRUE)))
_r_obj_clearreference (&sid_string);
Expand Down Expand Up @@ -542,7 +543,7 @@ VOID CALLBACK _wfp_logcallback (_In_ PITEM_LOG_CALLBACK log)

// get username information
if ((log->flags & FWPM_NET_EVENT_FLAG_USER_ID_SET) && log->user_id)
ptr_log->username = _r_sys_getusernamefromsid (log->user_id);
_r_sys_getusernamefromsid (log->user_id, &ptr_log->username);

// destination
if ((log->flags & FWPM_NET_EVENT_FLAG_IP_VERSION_SET))
Expand Down
9 changes: 4 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ BOOLEAN _app_installmessage (_In_opt_ HWND hwnd, _In_ BOOLEAN is_install)
TASKDIALOG_BUTTON td_buttons[2] = {0};
TASKDIALOG_BUTTON td_radios[2] = {0};

INT command_id;
INT radio_id;
BOOL is_flagchecked;

tdc.cbSize = sizeof (tdc);
tdc.dwFlags = TDF_ENABLE_HYPERLINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_NO_SET_FOREGROUND | TDF_VERIFICATION_FLAG_CHECKED;
tdc.hwndParent = hwnd;
tdc.pszWindowTitle = _r_app_getname ();
tdc.pszMainIcon = is_install ? TD_INFORMATION_ICON : TD_WARNING_ICON;
//tdc.dwCommonButtons = TDCBF_YES_BUTTON | TDCBF_NO_BUTTON;
tdc.pszMainInstruction = _r_app_getname ();
tdc.pfCallback = &_r_msg_callback;
tdc.lpCallbackData = MAKELONG (0, TRUE); // on top

Expand Down Expand Up @@ -96,10 +99,6 @@ BOOLEAN _app_installmessage (_In_opt_ HWND hwnd, _In_ BOOLEAN is_install)
_r_str_copy (str_flag, RTL_NUMBER_OF (str_flag), _r_locale_getstring (IDS_ENABLEWINDOWSFIREWALL_CHK));
}

INT command_id;
INT radio_id;
BOOL is_flagchecked;

tdc.pszMainInstruction = str_main;
tdc.pszVerificationText = str_flag;

Expand Down
12 changes: 7 additions & 5 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ typedef struct _STATIC_DATA
PSID pbuiltin_netops_sid;
PSID pbuiltin_admins_sid;

PSID pservice_mpssvc_sid;
PSID pservice_nlasvc_sid;
PSID pservice_policyagent_sid;
PSID pservice_rpcss_sid;
PSID pservice_wdiservicehost_sid;
PR_BYTE pservice_mpssvc_sid;
PR_BYTE pservice_nlasvc_sid;
PR_BYTE pservice_policyagent_sid;
PR_BYTE pservice_rpcss_sid;
PR_BYTE pservice_wdiservicehost_sid;

HIMAGELIST himg_toolbar;
HIMAGELIST himg_rules_small;
Expand Down Expand Up @@ -226,6 +226,8 @@ typedef struct _PROFILE_DATA
PR_STRING profile_path_backup;
PR_STRING profile_path_internal;

PR_STRING profile_path_old; // old

LONG64 profile_internal_timestamp;
} PROFILE_DATA, *PPROFILE_DATA;

Expand Down
26 changes: 14 additions & 12 deletions src/packages.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ VOID _app_package_getpackageslist ()
ULONG key_index;
ULONG max_length;
ULONG size;
LSTATUS code;
NTSTATUS status;

code = RegOpenKeyEx (
status = RegOpenKeyEx (
HKEY_CURRENT_USER,
L"Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\Repository\\Packages",
0,
KEY_READ,
&hkey
);

if (code != ERROR_SUCCESS)
if (status != ERROR_SUCCESS)
return;

max_length = _r_reg_querysubkeylength (hkey);
Expand All @@ -125,19 +125,19 @@ VOID _app_package_getpackageslist ()

_r_obj_trimstringtonullterminator (key_name);

code = RegOpenKeyEx (hkey, key_name->buffer, 0, KEY_READ, &hsubkey);
status = RegOpenKeyEx (hkey, key_name->buffer, 0, KEY_READ, &hsubkey);

if (code == ERROR_SUCCESS)
if (status == ERROR_SUCCESS)
{
package_sid = _r_reg_querybinary (hsubkey, NULL, L"PackageSid");

if (package_sid)
{
if (RtlValidSid (package_sid->buffer))
{
package_sid_string = _r_str_fromsid (package_sid->buffer);
status = _r_str_fromsid (package_sid->buffer, &package_sid_string);

if (package_sid_string)
if (status == STATUS_SUCCESS)
{
if (!_app_isappfound (_r_str_gethash2 (package_sid_string, TRUE)))
{
Expand Down Expand Up @@ -226,9 +226,9 @@ VOID _app_package_getserviceslist ()
R_STRINGREF service_name;
LPENUM_SERVICE_STATUS_PROCESS service;
LPENUM_SERVICE_STATUS_PROCESS services;
PSID service_sid;
PVOID service_sd;
PR_STRING service_path;
PR_BYTE service_sid;
LONG64 service_timestamp;
ULONG_PTR app_hash;
ULONG service_type;
Expand All @@ -250,6 +250,8 @@ VOID _app_package_getserviceslist ()

HKEY hkey;

NTSTATUS status;

hsvcmgr = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE);

if (!hsvcmgr)
Expand Down Expand Up @@ -353,16 +355,16 @@ VOID _app_package_getserviceslist ()
service_timestamp = _r_reg_querytimestamp (hkey);

// query service sid
service_sid = _r_sys_getservicesid (&service_name);
status = _r_sys_getservicesid (&service_name, &service_sid);

if (service_sid)
if (status == STATUS_SUCCESS)
{
// When evaluating SECURITY_DESCRIPTOR conditions, the filter engine
// checks for FWP_ACTRL_MATCH_FILTER access. If the DACL grants access,
// it does not mean that the traffic is allowed; it just means that the
// condition evaluates to true. Likewise if it denies access, the
// condition evaluates to false.
_app_setexplicitaccess (&ea, GRANT_ACCESS, FWP_ACTRL_MATCH_FILTER, NO_INHERITANCE, service_sid);
_app_setexplicitaccess (&ea, GRANT_ACCESS, FWP_ACTRL_MATCH_FILTER, NO_INHERITANCE, service_sid->buffer);

// Security descriptors must be in self-relative form (i.e., contiguous).
// The security descriptor returned by BuildSecurityDescriptorW is
Expand Down Expand Up @@ -393,7 +395,7 @@ VOID _app_package_getserviceslist ()
_r_obj_dereference (name_string);
}

_r_mem_free (service_sid);
_r_obj_dereference (service_sid);
}

_r_obj_dereference (service_path);
Expand Down
30 changes: 15 additions & 15 deletions src/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,35 @@ VOID _app_generate_credentials ()
{
_r_obj_initializestringref (&service_name, L"mpssvc");

config.pservice_mpssvc_sid = _r_sys_getservicesid (&service_name);
_r_sys_getservicesid (&service_name, &config.pservice_mpssvc_sid);
}

if (!config.pservice_nlasvc_sid)
{
_r_obj_initializestringref (&service_name, L"NlaSvc");

config.pservice_nlasvc_sid = _r_sys_getservicesid (&service_name);
_r_sys_getservicesid (&service_name, &config.pservice_nlasvc_sid);
}

if (!config.pservice_policyagent_sid)
{
_r_obj_initializestringref (&service_name, L"PolicyAgent");

config.pservice_policyagent_sid = _r_sys_getservicesid (&service_name);
_r_sys_getservicesid (&service_name, &config.pservice_policyagent_sid);
}

if (!config.pservice_rpcss_sid)
{
_r_obj_initializestringref (&service_name, L"RpcSs");

config.pservice_rpcss_sid = _r_sys_getservicesid (&service_name);
_r_sys_getservicesid (&service_name, &config.pservice_rpcss_sid);
}

if (!config.pservice_wdiservicehost_sid)
{
_r_obj_initializestringref (&service_name, L"WdiServiceHost");

config.pservice_wdiservicehost_sid = _r_sys_getservicesid (&service_name);
_r_sys_getservicesid (&service_name, &config.pservice_wdiservicehost_sid);
}
}

Expand Down Expand Up @@ -264,32 +264,32 @@ VOID _app_setsecurityinfoforengine (_In_ HANDLE hengine)

if (config.pservice_mpssvc_sid)
{
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, NO_INHERITANCE, config.pservice_mpssvc_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xE0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_mpssvc_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, NO_INHERITANCE, config.pservice_mpssvc_sid->buffer);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xE0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_mpssvc_sid->buffer);
}

if (config.pservice_nlasvc_sid)
{
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE, NO_INHERITANCE, config.pservice_nlasvc_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xA0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_nlasvc_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE, NO_INHERITANCE, config.pservice_nlasvc_sid->buffer);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xA0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_nlasvc_sid->buffer);
}

if (config.pservice_policyagent_sid)
{
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, NO_INHERITANCE, config.pservice_policyagent_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xE0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_policyagent_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, NO_INHERITANCE, config.pservice_policyagent_sid->buffer);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xE0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_policyagent_sid->buffer);
}

if (config.pservice_rpcss_sid)
{
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, NO_INHERITANCE, config.pservice_rpcss_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xE0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_rpcss_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_ALL | DELETE, NO_INHERITANCE, config.pservice_rpcss_sid->buffer);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xE0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_rpcss_sid->buffer);
}

if (config.pservice_wdiservicehost_sid)
{
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE, NO_INHERITANCE, config.pservice_wdiservicehost_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xA0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_wdiservicehost_sid);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, FWPM_GENERIC_READ | FWPM_GENERIC_EXECUTE, NO_INHERITANCE, config.pservice_wdiservicehost_sid->buffer);
_app_setexplicitaccess (&ea[count++], GRANT_ACCESS, 0xA0000000, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE, config.pservice_wdiservicehost_sid->buffer);
}

_app_setexplicitaccess (&ea[count++], SET_ACCESS, FWPM_ACTRL_CLASSIFY | FWPM_ACTRL_OPEN, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE, &SeEveryoneSid);
Expand Down
16 changes: 10 additions & 6 deletions src/wfp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ ENUM_INSTALL_TYPE _wfp_isproviderinstalled (_In_ HANDLE engine_handle)
{
if (ptr_provider)
{
if ((ptr_provider->flags & FWPM_PROVIDER_FLAG_DISABLED))
if (ptr_provider->flags & FWPM_PROVIDER_FLAG_DISABLED)
{
result = INSTALL_DISABLED;
//result = INSTALL_DISABLED;
}
else if ((ptr_provider->flags & FWPM_PROVIDER_FLAG_PERSISTENT))
else if (ptr_provider->flags & FWPM_PROVIDER_FLAG_PERSISTENT)
{
result = INSTALL_ENABLED;
}
Expand All @@ -50,7 +50,7 @@ ENUM_INSTALL_TYPE _wfp_issublayerinstalled (_In_ HANDLE engine_handle)
{
if (ptr_sublayer)
{
if ((ptr_sublayer->flags & FWPM_SUBLAYER_FLAG_PERSISTENT))
if (ptr_sublayer->flags & FWPM_SUBLAYER_FLAG_PERSISTENT)
{
result = INSTALL_ENABLED;
}
Expand Down Expand Up @@ -185,13 +185,17 @@ PR_STRING _wfp_getlayername (_In_ LPCGUID layer_guid)

C_ASSERT (RTL_NUMBER_OF (layer_guids) == RTL_NUMBER_OF (layer_names));

PR_STRING string;

for (SIZE_T i = 0; i < RTL_NUMBER_OF (layer_guids); i++)
{
if (IsEqualGUID (layer_guid, layer_guids[i]))
return _r_obj_createstring3 (&layer_names[i]);
}

return _r_str_fromguid (layer_guid, TRUE);
_r_str_fromguid (layer_guid, TRUE, &string);

return string;
}

BOOLEAN _wfp_initialize (_In_ HANDLE engine_handle)
Expand Down Expand Up @@ -652,7 +656,7 @@ BOOLEAN _wfp_deletefilter (_In_ HANDLE engine_handle, _In_ LPCGUID filter_id)
if (code != ERROR_SUCCESS)
#endif // !DEBUG
{
string = _r_str_fromguid (filter_id, TRUE);
_r_str_fromguid (filter_id, TRUE, &string);

_r_log (LOG_LEVEL_ERROR, &GUID_TrayIcon, L"FwpmFilterDeleteByKey", code, _r_obj_getstringordefault (string, SZ_EMPTY));

Expand Down

0 comments on commit 483bdbf

Please sign in to comment.