diff --git a/src/controls.c b/src/controls.c index 3f8d0401..31da7731 100644 --- a/src/controls.c +++ b/src/controls.c @@ -45,6 +45,9 @@ VOID _app_getapptooltipstring ( path = ptr_log->path; } + if (ptr_log) + _r_obj_appendstringbuilderformat (buffer, L"#%d - ", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0)); + if (path) { _r_obj_appendstringbuilder2 (buffer, &path->sr); diff --git a/src/listview.c b/src/listview.c index 22443541..539a2acd 100644 --- a/src/listview.c +++ b/src/listview.c @@ -788,10 +788,9 @@ VOID _app_listview_resize ( _In_ BOOLEAN is_forced ) { - PR_STRING column_text; - PR_STRING item_text; + PR_STRING string; HWND hlistview; - HWND hhdr = NULL; + HWND header = NULL; HDC hdc_listview = NULL; HDC hdc_header = NULL; LONG column_general_id = 0; // set general column id @@ -819,24 +818,24 @@ VOID _app_listview_resize ( if (!column_count) return; - // get device context and fix font set + // get device context hdc_listview = GetDC (hlistview); if (!hdc_listview) goto CleanupExit; - hhdr = _r_listview_getheader (hwnd, listview_id); + header = _r_listview_getheader (hwnd, listview_id); - if (!hhdr) + if (!header) goto CleanupExit; - hdc_header = GetDC (hhdr); + hdc_header = GetDC (header); if (!hdc_header) goto CleanupExit; - _r_dc_fixfont (hdc_listview, hwnd, listview_id); // fix - _r_dc_fixfont (hdc_header, hhdr, 0); // fix + _r_dc_fixfont (hdc_listview, hwnd, listview_id); // fix font set + _r_dc_fixfont (hdc_header, header, 0); // fix font set is_tableview = (_r_listview_getview (hwnd, listview_id) == LV_VIEW_DETAILS); @@ -848,18 +847,23 @@ VOID _app_listview_resize ( total_width = _r_ctrl_getwidth (hwnd, listview_id); item_count = _r_listview_getitemcount (hwnd, listview_id); + if (listview_id == IDC_LOG) + column_general_id = 1; + for (LONG i = 0; i < column_count; i++) { if (i == column_general_id) continue; // get column text width - column_text = _r_listview_getcolumntext (hwnd, listview_id, i); + string = _r_listview_getcolumntext (hwnd, listview_id, i); - if (!column_text) + if (!string) continue; - column_width = _r_dc_getfontwidth (hdc_header, &column_text->sr, NULL) + spacing; + column_width = _r_dc_getfontwidth (hdc_header, &string->sr, NULL) + spacing; + + _r_obj_dereference (string); if (column_width >= max_width) { @@ -872,14 +876,22 @@ VOID _app_listview_resize ( { for (INT j = 0; j < item_count; j++) { - item_text = _r_listview_getitemtext (hwnd, listview_id, j, i); + // check for number column + if ((i == 0) && (listview_id == IDC_LOG)) + { + text_width = _r_dc_getdpi (50, dpi_value); + } + else + { + string = _r_listview_getitemtext (hwnd, listview_id, j, i); - if (!item_text) - continue; + if (!string) + continue; - text_width = _r_dc_getfontwidth (hdc_listview, &item_text->sr, NULL) + spacing; + text_width = _r_dc_getfontwidth (hdc_listview, &string->sr, NULL) + spacing; - _r_obj_dereference (item_text); + _r_obj_dereference (string); + } // do not continue reaching higher and higher values for performance reason! if (text_width >= max_width) @@ -898,8 +910,6 @@ VOID _app_listview_resize ( _r_listview_setcolumn (hwnd, listview_id, i, NULL, column_width); calculated_width += column_width; - - _r_obj_dereference (column_text); } // set general column width @@ -911,7 +921,7 @@ CleanupExit: ReleaseDC (hlistview, hdc_listview); if (hdc_header) - ReleaseDC (hhdr, hdc_header); + ReleaseDC (header, hdc_header); } VOID _app_listview_setfont ( diff --git a/src/log.c b/src/log.c index e30ddf74..072844cf 100644 --- a/src/log.c +++ b/src/log.c @@ -83,8 +83,8 @@ ULONG _app_getloghash ( ULONG log_hash; string = _r_format_string ( - L"%" TEXT (PRIu8) L"-%" TEXT (PR_ULONG) L"-%" TEXT (PRIu8) L"-%" \ - TEXT (PRIu8) L"-%" TEXT (PRIu16) L"-%" TEXT (PRIu16) L"-%s-%s", + L"%" TEXT (PRIu8) L"_%" TEXT (PR_ULONG) L"_%" TEXT (PRIu8) L"_%" \ + TEXT (PRIu8) L"_%" TEXT (PRIu16) L"_%" TEXT (PRIu16) L"_%s_%s_IJAHudm4*^(uaokUH_!&%#!", ptr_log->af, ptr_log->app_hash, ptr_log->protocol, @@ -190,6 +190,8 @@ VOID _app_logclear_ui ( _In_ HWND hwnd ) { + _InterlockedExchange (&config.log_id, 0); + _r_listview_deleteallitems (hwnd, IDC_LOG); _app_listview_resize (hwnd, IDC_LOG, FALSE); @@ -1407,7 +1409,15 @@ VOID NTAPI _app_logthread ( { // write log to a ui if (is_loguienabled) + { + // increment value + _InterlockedIncrement (&config.log_id); + + ptr_log->log_id = _InterlockedCompareExchange (&config.log_id, 0, 0); + + // write to a ui _app_logwrite_ui (hwnd, ptr_log); + } // display notification if (is_notificationenabled) diff --git a/src/main.c b/src/main.c index 127fa193..392f8809 100644 --- a/src/main.c +++ b/src/main.c @@ -2009,7 +2009,7 @@ VOID _app_tabs_init ( { _r_listview_setstyle (hwnd, tab_context->listview_id, style, TRUE); - _r_listview_addcolumn (hwnd, tab_context->listview_id, 0, L"", -10, LVCFMT_LEFT); + _r_listview_addcolumn (hwnd, tab_context->listview_id, 0, L"#", -10, LVCFMT_LEFT); _r_listview_addcolumn (hwnd, tab_context->listview_id, 1, L"", -10, LVCFMT_LEFT); _r_listview_addcolumn (hwnd, tab_context->listview_id, 2, L"", -10, LVCFMT_LEFT); _r_listview_addcolumn (hwnd, tab_context->listview_id, 3, L"", -10, LVCFMT_LEFT); @@ -2020,6 +2020,7 @@ VOID _app_tabs_init ( _r_listview_addcolumn (hwnd, tab_context->listview_id, 8, L"", -10, LVCFMT_LEFT); _r_listview_addcolumn (hwnd, tab_context->listview_id, 9, L"", -10, LVCFMT_RIGHT); _r_listview_addcolumn (hwnd, tab_context->listview_id, 10, L"", -10, LVCFMT_LEFT); + _r_listview_addcolumn (hwnd, tab_context->listview_id, 11, L"", -10, LVCFMT_LEFT); _r_listview_addgroup (hwnd, tab_context->listview_id, 0, L"", 0, LVGS_NOHEADER, LVGS_NOHEADER); } diff --git a/src/main.h b/src/main.h index 15fd3146..830628c4 100644 --- a/src/main.h +++ b/src/main.h @@ -220,6 +220,7 @@ typedef struct _STATIC_DATA volatile HICON htray_icon; volatile HANDLE hnetevent; volatile HANDLE hlogfile; + volatile LONG log_id; ULONG color_nonremovable; ULONG color_network; @@ -431,6 +432,8 @@ typedef struct _ITEM_LOG ULONG app_hash; + volatile LONG log_id; + FWP_DIRECTION direction; ADDRESS_FAMILY af; diff --git a/src/messages.c b/src/messages.c index d41ed0c9..62e65df1 100644 --- a/src/messages.c +++ b/src/messages.c @@ -435,30 +435,30 @@ VOID _app_message_localize ( case IDC_LOG: { - _r_listview_setcolumn (hwnd, tab_context->listview_id, 0, _r_locale_getstring (IDS_NAME), 0); - _r_listview_setcolumn (hwnd, tab_context->listview_id, 1, _r_locale_getstring (IDS_DATE), 0); + _r_listview_setcolumn (hwnd, tab_context->listview_id, 1, _r_locale_getstring (IDS_NAME), 0); + _r_listview_setcolumn (hwnd, tab_context->listview_id, 2, _r_locale_getstring (IDS_DATE), 0); _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_LOCAL))); - _r_listview_setcolumn (hwnd, tab_context->listview_id, 2, localized_string->buffer, 0); - - _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_LOCAL))); _r_listview_setcolumn (hwnd, tab_context->listview_id, 3, localized_string->buffer, 0); - _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_LOCAL))); + _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_LOCAL))); _r_listview_setcolumn (hwnd, tab_context->listview_id, 4, localized_string->buffer, 0); - _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_REMOTE))); + _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_LOCAL))); _r_listview_setcolumn (hwnd, tab_context->listview_id, 5, localized_string->buffer, 0); - _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_REMOTE))); + _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_REMOTE))); _r_listview_setcolumn (hwnd, tab_context->listview_id, 6, localized_string->buffer, 0); - _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_REMOTE))); + _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_REMOTE))); _r_listview_setcolumn (hwnd, tab_context->listview_id, 7, localized_string->buffer, 0); - _r_listview_setcolumn (hwnd, tab_context->listview_id, 8, _r_locale_getstring (IDS_PROTOCOL), 0); - _r_listview_setcolumn (hwnd, tab_context->listview_id, 9, _r_locale_getstring (IDS_DIRECTION), 0); - _r_listview_setcolumn (hwnd, tab_context->listview_id, 10, _r_locale_getstring (IDS_FILTER), 0); + _r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_REMOTE))); + _r_listview_setcolumn (hwnd, tab_context->listview_id, 8, localized_string->buffer, 0); + + _r_listview_setcolumn (hwnd, tab_context->listview_id, 9, _r_locale_getstring (IDS_PROTOCOL), 0); + _r_listview_setcolumn (hwnd, tab_context->listview_id, 10, _r_locale_getstring (IDS_DIRECTION), 0); + _r_listview_setcolumn (hwnd, tab_context->listview_id, 11, _r_locale_getstring (IDS_FILTER), 0); break; } @@ -1518,6 +1518,12 @@ VOID _app_displayinfolog_callback ( switch (lpnmlv->item.iSubItem) { case 0: + { + _r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%d", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0)); + break; + } + + case 1: { if (ptr_app) { @@ -1542,7 +1548,7 @@ VOID _app_displayinfolog_callback ( break; } - case 1: + case 2: { string = _r_format_unixtime (ptr_log->timestamp, FDTF_SHORTDATE | FDTF_LONGTIME); @@ -1556,7 +1562,7 @@ VOID _app_displayinfolog_callback ( break; } - case 2: + case 3: { string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_addr_str, NULL, NULL); @@ -1566,7 +1572,7 @@ VOID _app_displayinfolog_callback ( break; } - case 3: + case 4: { string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_host_str, NULL, NULL); @@ -1582,7 +1588,7 @@ VOID _app_displayinfolog_callback ( break; } - case 4: + case 5: { if (ptr_log->local_port) { @@ -1599,7 +1605,7 @@ VOID _app_displayinfolog_callback ( break; } - case 5: + case 6: { string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_addr_str, NULL, NULL); @@ -1609,7 +1615,7 @@ VOID _app_displayinfolog_callback ( break; } - case 6: + case 7: { string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_host_str, NULL, NULL); @@ -1625,7 +1631,7 @@ VOID _app_displayinfolog_callback ( break; } - case 7: + case 8: { if (ptr_log->remote_port) { @@ -1642,7 +1648,7 @@ VOID _app_displayinfolog_callback ( break; } - case 8: + case 9: { if (ptr_log->protocol_str) { @@ -1656,7 +1662,7 @@ VOID _app_displayinfolog_callback ( break; } - case 9: + case 10: { string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE); @@ -1670,7 +1676,7 @@ VOID _app_displayinfolog_callback ( break; } - case 10: + case 11: { string = _r_obj_concatstrings ( 2,