Skip to content

Commit

Permalink
添加统计
Browse files Browse the repository at this point in the history
  • Loading branch information
2412322029 committed Apr 13, 2024
1 parent 92693c1 commit 78a6bcc
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 125 deletions.
6 changes: 3 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
font_size = 30
show_view = [ [ "Demo", true,], [ "实时捕获", true,], [ "打开 pcap", true,], [ "统计", false,],]
windows_pos = [ -182, 195,]
windows_size = [ 2560, 1370,]
show_view = [ [ "Demo", false,], [ "实时捕获", false,], [ "打开 pcap", true,], [ "统计", true,],]
windows_pos = [ 255, 125,]
windows_size = [ 2139, 1271,]
selected = 3
theme = "light"
tshark_path = "./tshark/tshark.exe"
Expand Down
13 changes: 3 additions & 10 deletions g_live_sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from shark.live_sniffer import packet_sniffer
from shark.data import MAX_SHOW, Share_Data
from util.logger import logger, log_stream
from util.show_log import show_log


def g_live_sniffer(m: imgui, share_data: Share_Data, consola_font):
Expand Down Expand Up @@ -47,7 +48,7 @@ def do_save():
logger.error(f"Permission error. Unable to move file.")
pass

flags = imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE
flags = imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS
m.set_next_window_size(*share_data.windows_size)
with m.begin("实时捕获", flags=flags):
m.text("选择网卡: ")
Expand Down Expand Up @@ -143,15 +144,7 @@ def until_stop():
if share_data.selected_row:
display_packet(share_data.selected_row)

with m.begin_child("日志", 0, 200, border=True):
# 获取当前日志内容
log_lines = log_stream.getvalue().splitlines()[-1000:]
# 只显示最多1000行日志
for line in log_lines:
m.text(line)
if share_data.log_new_line != log_lines[-1]:
m.set_scroll_y(m.get_scroll_max_y())
share_data.log_new_line = log_lines[-1]
show_log(m, share_data)

with m.begin_child("状态", 0, 30):
m.text(f'{len(pak_list)}/{MAX_SHOW}')
Expand Down
16 changes: 5 additions & 11 deletions g_show_pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import imgui
from shark.data import Share_Data
from util.logger import logger, log_stream
from util.show_log import show_log


def g_show_pcap(m: imgui, share_data: Share_Data, consola_font):
Expand All @@ -24,7 +25,7 @@ def reload():
share_data.get_file_capture(share_data.file_path)
share_data.file_pagenum = 0

flags = imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE
flags = imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS
m.set_next_window_size(*share_data.windows_size)
with m.begin("show pcap", flags=flags):
if not share_data.file_loading:
Expand All @@ -43,6 +44,7 @@ def reload():
logger.debug("clear file_pak_list")
share_data.file_pak_list = []
share_data.file_path = None
share_data.file_per_thread = None
if share_data.file_path:
m.same_line()
if m.button("重新加载"):
Expand All @@ -53,7 +55,7 @@ def reload():
m.push_item_width(200)
m.same_line(m.get_window_width() - m.calc_text_size(
"page").x - m.get_style().item_spacing.x)
m.set_cursor_pos_x(m.get_cursor_pos_x() - m.get_style().item_spacing.x-200)
m.set_cursor_pos_x(m.get_cursor_pos_x() - m.get_style().item_spacing.x - 200)
ch, p = m.input_int("", share_data.file_pagenum)
if ch and 0 <= p < len(share_data.file_pak_list) / share_data.file_pagesize:
share_data.file_pagenum = p
Expand Down Expand Up @@ -112,15 +114,7 @@ def reload():
if share_data.selected_file_row:
display_packet(share_data.selected_file_row)

with m.begin_child("日志", 0, 200, border=True):
# 获取当前日志内容
log_lines = log_stream.getvalue().splitlines()[-1000:]
# 只显示最多1000行日志
for line in log_lines:
m.text(line)
if share_data.log_new_line != log_lines[-1]:
m.set_scroll_y(m.get_scroll_max_y())
share_data.log_new_line = log_lines[-1]
show_log(m, share_data)
with m.begin_child("状态", 0, 30):
m.text(f'{len(share_data.file_pak_list)}')
m.same_line()
Expand Down
17 changes: 13 additions & 4 deletions g_statistics.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import os

import imgui

from shark.data import Share_Data
from shark.statistics import statistics
from util.load_img import load_img


def g_statistics(m: imgui, share_data: Share_Data, consola_font):
# flags = imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE
m.set_next_window_size(*share_data.windows_size)
with m.begin("统计"):
m.text("")
flags = imgui.WINDOW_NO_COLLAPSE
with (m.begin("统计", flags=flags)):
if share_data.file_path and share_data.pcap_file:
m.text(share_data.file_path)
m.text(share_data.pcap_file.__str__())
statistics(share_data.pcap_file, share_data.result_image_path)
if m.button("show"):
load_img(share_data.result_image_path, 1)

64 changes: 44 additions & 20 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ Collapsed=0

[Window][show pcap]
Pos=0,32
Size=2560,1370
Size=2125,1250
Collapsed=0

[Window][Dear ImGui Metrics/Debugger]
Pos=1084,98
Pos=417,280
Size=527,557
Collapsed=0

[Window][Dear ImGui Demo]
Pos=326,155
Pos=425,342
Size=916,939
Collapsed=0

Expand All @@ -39,60 +39,80 @@ Size=520,600
Collapsed=0

[Window][Same title as another window##2]
Pos=100,200
Pos=212,236
Size=675,112
Collapsed=0

[Window][Same title as another window##1]
Pos=14,444
Size=675,112
Pos=36,466
Size=741,132
Collapsed=0

[Window][###AnimatedTitle]
Pos=121,347
Size=377,82
Pos=135,350
Size=459,104
Collapsed=0

[Window][Example: Documents]
Pos=466,21
Pos=467,21
Size=1034,1100
Collapsed=0

[Window][Example: Custom rendering]
Pos=321,180
Size=485,618
Pos=286,236
Size=464,623
Collapsed=0

[Window][Example: Console]
Pos=60,59
Size=520,600
Size=757,637
Collapsed=0

[Window][Example: Log]
Pos=60,60
Size=500,400
Pos=262,126
Size=981,357
Collapsed=0

[Window][About Dear ImGui]
Pos=0,32
Size=2113,1192
Size=893,194
Collapsed=0

[Window][统计]
Pos=316,97
Size=2560,1370
Pos=585,216
Size=1274,868
Collapsed=0

[Window][日志]
Pos=543,505
Size=1074,281
Collapsed=0

[Window][Example: Auto-resizing window]
Pos=60,60
Size=717,522
Collapsed=0

[Window][Example: Constrained Resize]
Pos=60,60
Size=903,548
Collapsed=0

[Window][Example: Simple layout]
Pos=60,60
Size=500,440
Collapsed=0

[Window][Example: Property editor]
Pos=60,60
Size=430,450
Collapsed=0

[Table][0xD005EE48,7]
RefScale=30
Column 0 Width=60
Column 1 Width=213
Column 2 Width=224
Column 2 Width=214
Column 3 Width=239
Column 4 Width=70
Column 5 Width=129
Expand All @@ -102,10 +122,10 @@ Column 6 Width=715
RefScale=30
Column 0 Width=69
Column 1 Width=253
Column 2 Width=188 Sort=0v
Column 2 Width=188
Column 3 Width=201
Column 4 Width=93
Column 5 Width=587
Column 5 Width=587 Sort=0v
Column 6 Width=1235

[Table][0x861D378E,3]
Expand All @@ -119,3 +139,7 @@ Column 0 Width=96
Column 1 Width=96
Column 2 Width=96

[Table][0xD0F0C6E3,2]
Column 0 Weight=1.0000
Column 1 Weight=1.0000

36 changes: 8 additions & 28 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from OpenGL import GL
from OpenGL.GL import *
import glfw
import sys
from g_live_sniffer import g_live_sniffer
from g_show_pcap import g_show_pcap
from g_statistics import g_statistics
from menu import menu
from shark import data
from util.logger import logger
import imgui
Expand All @@ -17,7 +15,7 @@

def main():
imgui.create_context()
share_data = data.Share_Data()
share_data = data.Share_Data(main_directory)
window = impl_glfw_init(share_data)
glfw.set_window_pos(window, *share_data.windows_pos)
impl = GlfwRenderer(window)
Expand All @@ -44,31 +42,13 @@ def on_window_pos_change(_, x, y):
glfw.swap_interval(1)
imgui.push_font(chinese_font)
imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND_HOVERED, 0.57, 0.76, 0.98, 0.40)
with imgui.begin_main_menu_bar() as main_menu_bar:
if main_menu_bar.opened:
for i, m in enumerate(share_data.show_view):
o = share_data.show_view[i]
is_selected = imgui.menu_item(o[0], f'{i}', o[1], True)[0]
if is_selected:
share_data.show_view[i][1] = not o[1]
if imgui.begin_popup_context_item(f'Context{i}'):
imgui.menu_item("Close")
imgui.end_popup()

if share_data.show_view[0][1]:
# imgui.set_next_window_focus()
imgui.show_demo_window()
if share_data.show_view[1][1]:
g_live_sniffer(imgui, share_data, consola_font)
if share_data.show_view[2][1]:
g_show_pcap(imgui, share_data, consola_font)
if share_data.show_view[3][1]:
g_statistics(imgui, share_data, consola_font)
if not glfw.get_window_attrib(window, glfw.ICONIFIED):
menu(share_data, consola_font) # 菜单
imgui.pop_font()
imgui.pop_style_color()

GL.glClearColor(1.0, 1.0, 1.0, 1)
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
glClearColor(1.0, 1.0, 1.0, 1)
glClear(GL_COLOR_BUFFER_BIT)

imgui.render()
impl.render(imgui.get_draw_data())
Expand All @@ -91,7 +71,7 @@ def impl_glfw_init(share_data):
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)

window = glfw.create_window(int(width), int(height), window_name, None, None)
glfw.make_context_current(window)
Expand Down
27 changes: 27 additions & 0 deletions menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import imgui

from g_live_sniffer import g_live_sniffer
from g_show_pcap import g_show_pcap
from g_statistics import g_statistics


def menu(share_data, consola_font):
with imgui.begin_main_menu_bar() as main_menu_bar:
if main_menu_bar.opened:
for i, m in enumerate(share_data.show_view):
o = share_data.show_view[i]
is_selected = imgui.menu_item(o[0], f'{i}', o[1], True)[0]
if is_selected:
share_data.show_view[i][1] = not o[1]
if imgui.begin_popup_context_item(f'Context{i}'):
imgui.menu_item("Close")
imgui.end_popup()

if share_data.show_view[0][1]:
imgui.show_demo_window()
if share_data.show_view[1][1]:
g_live_sniffer(imgui, share_data, consola_font)
if share_data.show_view[2][1]:
g_show_pcap(imgui, share_data, consola_font)
if share_data.show_view[3][1]:
g_statistics(imgui, share_data, consola_font)
Loading

0 comments on commit 78a6bcc

Please sign in to comment.