-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmispWiresharkUtils.lua
More file actions
79 lines (71 loc) · 2.3 KB
/
mispWiresharkUtils.lua
File metadata and controls
79 lines (71 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
local utils = {}
-- https://gist.github.com/tylerneylon/81333721109155b2d244
function utils.deepcopy(obj)
if type(obj) ~= 'table' then return obj end
local res = setmetatable({}, getmetatable(obj))
for k, v in pairs(obj) do res[utils.deepcopy(k)] = utils.deepcopy(v) end
return res
end
function utils.save_to_file(content, export_filepath, tw)
local now = os.time(os.date("!*t"))
local filename = string.format("wireshark-misp-%s.json", now)
local full_path
if export_filepath ~= '' then
full_path = string.format('%s/%s', export_filepath, filename)
else
full_path = string.format('%s', export_filepath, filename)
end
local file = assert(io.open(full_path, "w"))
file:write(content)
file:close()
utils.make_splash(string.format("Saved %s at %s", filename, export_filepath))
if tw then
tw:close()
end
end
function utils.make_splash(text)
if gui_enabled() then
local splash = TextWindow.new("MISP Export error");
splash:set(text)
return splash
else
print(text)
end
end
-- verify tshark/wireshark version is new enough - needs to be 3.3.1+ as community was introduced in this version
function utils.check_wireshark_version()
local version_ok = true
local major, minor, micro = 0, 0, 0
major, minor, micro = get_version():match("(%d+)%.(%d+)%.(%d+)")
if (
tonumber(major) < 3) or
((tonumber(major) <= 3) and (tonumber(minor) < 3)) or
((tonumber(major) <= 3) and (tonumber(minor) <= 3) and (tonumber(micro) < 1)
) then
version_ok = false
end
return version_ok
end
function utils.humanizeFilesize(size)
if (size == 0) then
return "0.00 B"
end
local sizes = {'B', 'kB', 'MB', 'GB', 'TB', 'PB'}
local e = math.floor(math.log(size, 1024))
local significant = math.floor(size/math.pow(1024, e), 2)
local remaining = math.floor(size/math.pow(1024, e-1), 2) % 1024
local text = string.format("%s.%s%s", significant, remaining, sizes[e])
return text
end
function utils.parse_args(args)
local t = {}
for i, arg in ipairs(args) do
local matches = string.gmatch(arg, "([^=]+)=(.+)")
local k, v = matches()
if k ~= '' and v ~= '' then
t[k] = v
end
end
return t
end
return utils