Skip to content

Commit 3401ea6

Browse files
committed
add dropped packets log id column
1 parent dcad34b commit 3401ea6

File tree

6 files changed

+77
-44
lines changed

6 files changed

+77
-44
lines changed

src/controls.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ VOID _app_getapptooltipstring (
4545
path = ptr_log->path;
4646
}
4747

48+
if (ptr_log)
49+
_r_obj_appendstringbuilderformat (buffer, L"#%d - ", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0));
50+
4851
if (path)
4952
{
5053
_r_obj_appendstringbuilder2 (buffer, &path->sr);

src/listview.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,9 @@ VOID _app_listview_resize (
788788
_In_ BOOLEAN is_forced
789789
)
790790
{
791-
PR_STRING column_text;
792-
PR_STRING item_text;
791+
PR_STRING string;
793792
HWND hlistview;
794-
HWND hhdr = NULL;
793+
HWND header = NULL;
795794
HDC hdc_listview = NULL;
796795
HDC hdc_header = NULL;
797796
LONG column_general_id = 0; // set general column id
@@ -819,24 +818,24 @@ VOID _app_listview_resize (
819818
if (!column_count)
820819
return;
821820

822-
// get device context and fix font set
821+
// get device context
823822
hdc_listview = GetDC (hlistview);
824823

825824
if (!hdc_listview)
826825
goto CleanupExit;
827826

828-
hhdr = _r_listview_getheader (hwnd, listview_id);
827+
header = _r_listview_getheader (hwnd, listview_id);
829828

830-
if (!hhdr)
829+
if (!header)
831830
goto CleanupExit;
832831

833-
hdc_header = GetDC (hhdr);
832+
hdc_header = GetDC (header);
834833

835834
if (!hdc_header)
836835
goto CleanupExit;
837836

838-
_r_dc_fixfont (hdc_listview, hwnd, listview_id); // fix
839-
_r_dc_fixfont (hdc_header, hhdr, 0); // fix
837+
_r_dc_fixfont (hdc_listview, hwnd, listview_id); // fix font set
838+
_r_dc_fixfont (hdc_header, header, 0); // fix font set
840839

841840
is_tableview = (_r_listview_getview (hwnd, listview_id) == LV_VIEW_DETAILS);
842841

@@ -848,18 +847,23 @@ VOID _app_listview_resize (
848847
total_width = _r_ctrl_getwidth (hwnd, listview_id);
849848
item_count = _r_listview_getitemcount (hwnd, listview_id);
850849

850+
if (listview_id == IDC_LOG)
851+
column_general_id = 1;
852+
851853
for (LONG i = 0; i < column_count; i++)
852854
{
853855
if (i == column_general_id)
854856
continue;
855857

856858
// get column text width
857-
column_text = _r_listview_getcolumntext (hwnd, listview_id, i);
859+
string = _r_listview_getcolumntext (hwnd, listview_id, i);
858860

859-
if (!column_text)
861+
if (!string)
860862
continue;
861863

862-
column_width = _r_dc_getfontwidth (hdc_header, &column_text->sr, NULL) + spacing;
864+
column_width = _r_dc_getfontwidth (hdc_header, &string->sr, NULL) + spacing;
865+
866+
_r_obj_dereference (string);
863867

864868
if (column_width >= max_width)
865869
{
@@ -872,14 +876,22 @@ VOID _app_listview_resize (
872876
{
873877
for (INT j = 0; j < item_count; j++)
874878
{
875-
item_text = _r_listview_getitemtext (hwnd, listview_id, j, i);
879+
// check for number column
880+
if ((i == 0) && (listview_id == IDC_LOG))
881+
{
882+
text_width = _r_dc_getdpi (50, dpi_value);
883+
}
884+
else
885+
{
886+
string = _r_listview_getitemtext (hwnd, listview_id, j, i);
876887

877-
if (!item_text)
878-
continue;
888+
if (!string)
889+
continue;
879890

880-
text_width = _r_dc_getfontwidth (hdc_listview, &item_text->sr, NULL) + spacing;
891+
text_width = _r_dc_getfontwidth (hdc_listview, &string->sr, NULL) + spacing;
881892

882-
_r_obj_dereference (item_text);
893+
_r_obj_dereference (string);
894+
}
883895

884896
// do not continue reaching higher and higher values for performance reason!
885897
if (text_width >= max_width)
@@ -898,8 +910,6 @@ VOID _app_listview_resize (
898910
_r_listview_setcolumn (hwnd, listview_id, i, NULL, column_width);
899911

900912
calculated_width += column_width;
901-
902-
_r_obj_dereference (column_text);
903913
}
904914

905915
// set general column width
@@ -911,7 +921,7 @@ VOID _app_listview_resize (
911921
ReleaseDC (hlistview, hdc_listview);
912922

913923
if (hdc_header)
914-
ReleaseDC (hhdr, hdc_header);
924+
ReleaseDC (header, hdc_header);
915925
}
916926

917927
VOID _app_listview_setfont (

src/log.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ ULONG _app_getloghash (
8383
ULONG log_hash;
8484

8585
string = _r_format_string (
86-
L"%" TEXT (PRIu8) L"-%" TEXT (PR_ULONG) L"-%" TEXT (PRIu8) L"-%" \
87-
TEXT (PRIu8) L"-%" TEXT (PRIu16) L"-%" TEXT (PRIu16) L"-%s-%s",
86+
L"%" TEXT (PRIu8) L"_%" TEXT (PR_ULONG) L"_%" TEXT (PRIu8) L"_%" \
87+
TEXT (PRIu8) L"_%" TEXT (PRIu16) L"_%" TEXT (PRIu16) L"_%s_%s_IJAHudm4*^(uaokUH_!&%#!",
8888
ptr_log->af,
8989
ptr_log->app_hash,
9090
ptr_log->protocol,
@@ -190,6 +190,8 @@ VOID _app_logclear_ui (
190190
_In_ HWND hwnd
191191
)
192192
{
193+
_InterlockedExchange (&config.log_id, 0);
194+
193195
_r_listview_deleteallitems (hwnd, IDC_LOG);
194196

195197
_app_listview_resize (hwnd, IDC_LOG, FALSE);
@@ -1407,7 +1409,15 @@ VOID NTAPI _app_logthread (
14071409
{
14081410
// write log to a ui
14091411
if (is_loguienabled)
1412+
{
1413+
// increment value
1414+
_InterlockedIncrement (&config.log_id);
1415+
1416+
ptr_log->log_id = _InterlockedCompareExchange (&config.log_id, 0, 0);
1417+
1418+
// write to a ui
14101419
_app_logwrite_ui (hwnd, ptr_log);
1420+
}
14111421

14121422
// display notification
14131423
if (is_notificationenabled)

src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ VOID _app_tabs_init (
20092009
{
20102010
_r_listview_setstyle (hwnd, tab_context->listview_id, style, TRUE);
20112011

2012-
_r_listview_addcolumn (hwnd, tab_context->listview_id, 0, L"", -10, LVCFMT_LEFT);
2012+
_r_listview_addcolumn (hwnd, tab_context->listview_id, 0, L"#", -10, LVCFMT_LEFT);
20132013
_r_listview_addcolumn (hwnd, tab_context->listview_id, 1, L"", -10, LVCFMT_LEFT);
20142014
_r_listview_addcolumn (hwnd, tab_context->listview_id, 2, L"", -10, LVCFMT_LEFT);
20152015
_r_listview_addcolumn (hwnd, tab_context->listview_id, 3, L"", -10, LVCFMT_LEFT);
@@ -2020,6 +2020,7 @@ VOID _app_tabs_init (
20202020
_r_listview_addcolumn (hwnd, tab_context->listview_id, 8, L"", -10, LVCFMT_LEFT);
20212021
_r_listview_addcolumn (hwnd, tab_context->listview_id, 9, L"", -10, LVCFMT_RIGHT);
20222022
_r_listview_addcolumn (hwnd, tab_context->listview_id, 10, L"", -10, LVCFMT_LEFT);
2023+
_r_listview_addcolumn (hwnd, tab_context->listview_id, 11, L"", -10, LVCFMT_LEFT);
20232024

20242025
_r_listview_addgroup (hwnd, tab_context->listview_id, 0, L"", 0, LVGS_NOHEADER, LVGS_NOHEADER);
20252026
}

src/main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ typedef struct _STATIC_DATA
220220
volatile HICON htray_icon;
221221
volatile HANDLE hnetevent;
222222
volatile HANDLE hlogfile;
223+
volatile LONG log_id;
223224

224225
ULONG color_nonremovable;
225226
ULONG color_network;
@@ -431,6 +432,8 @@ typedef struct _ITEM_LOG
431432

432433
ULONG app_hash;
433434

435+
volatile LONG log_id;
436+
434437
FWP_DIRECTION direction;
435438

436439
ADDRESS_FAMILY af;

src/messages.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -435,30 +435,30 @@ VOID _app_message_localize (
435435

436436
case IDC_LOG:
437437
{
438-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 0, _r_locale_getstring (IDS_NAME), 0);
439-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 1, _r_locale_getstring (IDS_DATE), 0);
438+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 1, _r_locale_getstring (IDS_NAME), 0);
439+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 2, _r_locale_getstring (IDS_DATE), 0);
440440

441441
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_LOCAL)));
442-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 2, localized_string->buffer, 0);
442+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 3, localized_string->buffer, 0);
443443

444444
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_LOCAL)));
445-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 3, localized_string->buffer, 0);
445+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 4, localized_string->buffer, 0);
446446

447447
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_LOCAL)));
448-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 4, localized_string->buffer, 0);
448+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 5, localized_string->buffer, 0);
449449

450450
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_ADDRESS), _r_locale_getstring (IDS_DIRECTION_REMOTE)));
451-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 5, localized_string->buffer, 0);
451+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 6, localized_string->buffer, 0);
452452

453453
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_HOST), _r_locale_getstring (IDS_DIRECTION_REMOTE)));
454-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 6, localized_string->buffer, 0);
454+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 7, localized_string->buffer, 0);
455455

456456
_r_obj_movereference ((PVOID_PTR)&localized_string, _r_format_string (L"%s (%s)", _r_locale_getstring (IDS_PORT), _r_locale_getstring (IDS_DIRECTION_REMOTE)));
457-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 7, localized_string->buffer, 0);
457+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 8, localized_string->buffer, 0);
458458

459-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 8, _r_locale_getstring (IDS_PROTOCOL), 0);
460-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 9, _r_locale_getstring (IDS_DIRECTION), 0);
461-
_r_listview_setcolumn (hwnd, tab_context->listview_id, 10, _r_locale_getstring (IDS_FILTER), 0);
459+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 9, _r_locale_getstring (IDS_PROTOCOL), 0);
460+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 10, _r_locale_getstring (IDS_DIRECTION), 0);
461+
_r_listview_setcolumn (hwnd, tab_context->listview_id, 11, _r_locale_getstring (IDS_FILTER), 0);
462462

463463
break;
464464
}
@@ -1518,6 +1518,12 @@ VOID _app_displayinfolog_callback (
15181518
switch (lpnmlv->item.iSubItem)
15191519
{
15201520
case 0:
1521+
{
1522+
_r_str_printf (lpnmlv->item.pszText, lpnmlv->item.cchTextMax, L"%d", _InterlockedCompareExchange (&ptr_log->log_id, 0, 0));
1523+
break;
1524+
}
1525+
1526+
case 1:
15211527
{
15221528
if (ptr_app)
15231529
{
@@ -1542,7 +1548,7 @@ VOID _app_displayinfolog_callback (
15421548
break;
15431549
}
15441550

1545-
case 1:
1551+
case 2:
15461552
{
15471553
string = _r_format_unixtime (ptr_log->timestamp, FDTF_SHORTDATE | FDTF_LONGTIME);
15481554

@@ -1556,7 +1562,7 @@ VOID _app_displayinfolog_callback (
15561562
break;
15571563
}
15581564

1559-
case 2:
1565+
case 3:
15601566
{
15611567
string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_addr_str, NULL, NULL);
15621568

@@ -1566,7 +1572,7 @@ VOID _app_displayinfolog_callback (
15661572
break;
15671573
}
15681574

1569-
case 3:
1575+
case 4:
15701576
{
15711577
string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->local_host_str, NULL, NULL);
15721578

@@ -1582,7 +1588,7 @@ VOID _app_displayinfolog_callback (
15821588
break;
15831589
}
15841590

1585-
case 4:
1591+
case 5:
15861592
{
15871593
if (ptr_log->local_port)
15881594
{
@@ -1599,7 +1605,7 @@ VOID _app_displayinfolog_callback (
15991605
break;
16001606
}
16011607

1602-
case 5:
1608+
case 6:
16031609
{
16041610
string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_addr_str, NULL, NULL);
16051611

@@ -1609,7 +1615,7 @@ VOID _app_displayinfolog_callback (
16091615
break;
16101616
}
16111617

1612-
case 6:
1618+
case 7:
16131619
{
16141620
string = _InterlockedCompareExchangePointer ((volatile PVOID_PTR)&ptr_log->remote_host_str, NULL, NULL);
16151621

@@ -1625,7 +1631,7 @@ VOID _app_displayinfolog_callback (
16251631
break;
16261632
}
16271633

1628-
case 7:
1634+
case 8:
16291635
{
16301636
if (ptr_log->remote_port)
16311637
{
@@ -1642,7 +1648,7 @@ VOID _app_displayinfolog_callback (
16421648
break;
16431649
}
16441650

1645-
case 8:
1651+
case 9:
16461652
{
16471653
if (ptr_log->protocol_str)
16481654
{
@@ -1656,7 +1662,7 @@ VOID _app_displayinfolog_callback (
16561662
break;
16571663
}
16581664

1659-
case 9:
1665+
case 10:
16601666
{
16611667
string = _app_db_getdirectionname (ptr_log->direction, ptr_log->is_loopback, FALSE);
16621668

@@ -1670,7 +1676,7 @@ VOID _app_displayinfolog_callback (
16701676
break;
16711677
}
16721678

1673-
case 10:
1679+
case 11:
16741680
{
16751681
string = _r_obj_concatstrings (
16761682
2,

0 commit comments

Comments
 (0)