add change setting function und move functionality ir differents files
This commit is contained in:
@@ -3,4 +3,4 @@
|
||||
["eth_fake_header_src"] = "00 00 00 00 00 00",
|
||||
["eth_fake_header_dst"] = "11 11 11 11 11 11",
|
||||
["eth_fake_header_type"] = "47 11"
|
||||
}
|
||||
}
|
||||
|
||||
13
src/b2ws-plugin/b2ws_const.lua
Normal file
13
src/b2ws-plugin/b2ws_const.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
module("b2ws_const")
|
||||
B2WS_PLUGIN_PATH = "plugins/b2ws-plugin/"
|
||||
B2WS_PLUGIN_CONFIG_FILE_NAME = "b2ws.config"
|
||||
B2WS_IMPORT_BLOB_MENU_TITLE = "b2ws/Import Blob"
|
||||
B2WS_IMPORT_BLOB_BTN_TITLE = "Import Blob"
|
||||
B2WS_SAVE_SETTINGS_BTN_TITLE = "Save Current Settings"
|
||||
B2WS_CHANGE_SETTINGS_BTN_TITLE = "Change Settings"
|
||||
B2WS_CHANGE_SETTINGS_DLG_TITLE = "Change Settings"
|
||||
B2WS_IMPORT_BLOB_WIN_TITLE = "Import Blob"
|
||||
B2WS_CONFIG_LABEL_BLOB_SRC = "Blob file path"
|
||||
B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_SRC = "fake eth src address"
|
||||
B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_DST = "fake eth dst address"
|
||||
B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_TYPE = "fake eth type"
|
||||
@@ -1,49 +1,10 @@
|
||||
require "b2ws_const"
|
||||
local loaded_b2ws_util= assert(loadfile(b2ws_const.B2WS_PLUGIN_PATH .. "b2ws_util.lua"))
|
||||
loaded_b2ws_util()
|
||||
|
||||
local PLUGIN_PATH = "plugins/b2ws-plugin/"
|
||||
local PLUGIN_CONFIG_FILE_NAME = "b2ws.config"
|
||||
|
||||
-- from http://lua-users.org/wiki/StringRecipes
|
||||
local function string_starts(String,Start)
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
end
|
||||
|
||||
-- from http://lua-users.org/wiki/StringTrim
|
||||
function b2ws_trim(s)
|
||||
local from = s:match"^%s*()"
|
||||
return from > #s and "" or s:match(".*%S", from)
|
||||
end
|
||||
|
||||
local function create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
|
||||
return persconffile_path(plugin_path) .. plugin_config_file_name
|
||||
end
|
||||
|
||||
local function write_b2ws_file(file_path, content)
|
||||
local config_inp = assert(io.open(file_path, "w"))
|
||||
config_inp:write(content)
|
||||
assert(config_inp:close())
|
||||
end
|
||||
|
||||
local function read_b2ws_file(file_path)
|
||||
local config_inp = assert(io.open(file_path, "r"))
|
||||
local config_string = config_inp:read("*all")
|
||||
assert(config_inp:close())
|
||||
return config_string
|
||||
end
|
||||
|
||||
local function read_b2ws_config_file(plugin_path, plugin_config_file_name)
|
||||
local path = create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
|
||||
return read_b2ws_file(path)
|
||||
end
|
||||
|
||||
local function write_b2ws_config_file(plugin_path, plugin_config_file_name, settings)
|
||||
local path = create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
|
||||
write_b2ws_file(path, settings)
|
||||
end
|
||||
|
||||
local function b2ws_import_blob(config_string)
|
||||
|
||||
local tmp_config_func = assert(loadstring(string.gsub(config_string, "[\n\r]", "")))
|
||||
b2ws_config = tmp_config_func()
|
||||
function b2ws_import_blob(config_string)
|
||||
-- create config object
|
||||
local b2ws_config = create_b2ws_config_object(config_string)
|
||||
|
||||
-- read blob file
|
||||
local bytes = read_b2ws_file(b2ws_config.blob_src)
|
||||
@@ -67,40 +28,27 @@ local function b2ws_import_blob(config_string)
|
||||
return pcapPath
|
||||
end
|
||||
|
||||
if (gui_enabled()) then
|
||||
-- gui part
|
||||
local IMPORT_BLOB_MENU_TITLE = "b2ws/Import Blob"
|
||||
local IMPORT_BLOB_BTN_TITLE = "Import Blob"
|
||||
local SAVE_SETTINGS_BTN_TITLE = "Save current settings"
|
||||
local IMPORT_BLOB_WIN_TITLE = "Import Blob"
|
||||
|
||||
local function b2ws_win_import_blob()
|
||||
local win = TextWindow.new(IMPORT_BLOB_WIN_TITLE)
|
||||
win:set_editable()
|
||||
win:set(read_b2ws_config_file(PLUGIN_PATH, PLUGIN_CONFIG_FILE_NAME))
|
||||
|
||||
local function b2ws_win_btn_import_blob()
|
||||
|
||||
-- load config from text field
|
||||
local win_text = win:get_text();
|
||||
if not (string_starts(win_text, "return ")) then
|
||||
win_text = "return " .. win_text
|
||||
end
|
||||
|
||||
-- import to and show in pcap file
|
||||
output_path = b2ws_import_blob(win_text)
|
||||
open_capture_file(output_path, "")
|
||||
end
|
||||
|
||||
local function b2ws_win_btn_save_settings()
|
||||
-- load config from text field
|
||||
local win_text = b2ws_trim(win:get_text());
|
||||
write_b2ws_config_file(PLUGIN_PATH, PLUGIN_CONFIG_FILE_NAME, win_text)
|
||||
end
|
||||
|
||||
win:add_button(IMPORT_BLOB_BTN_TITLE, b2ws_win_btn_import_blob)
|
||||
win:add_button(SAVE_SETTINGS_BTN_TITLE, b2ws_win_btn_save_settings)
|
||||
function b2ws_change_settings(config_string, blob_src, eth_src, eth_dst, eth_type)
|
||||
local b2ws_config = create_b2ws_config_object(config_string)
|
||||
if not (blob_src == "") then
|
||||
b2ws_config.blob_src = blob_src
|
||||
end
|
||||
|
||||
register_menu(IMPORT_BLOB_MENU_TITLE, b2ws_win_import_blob, MENU_TOOLS_UNSORTED)
|
||||
if not (eth_src == "") then
|
||||
b2ws_config.eth_fake_header_src = eth_src
|
||||
end
|
||||
|
||||
if not (eth_dst == "") then
|
||||
b2ws_config.eth_fake_header_dst = eth_dst
|
||||
end
|
||||
|
||||
if not (eth_type == "") then
|
||||
b2ws_config.eth_fake_header_type = eth_type
|
||||
end
|
||||
|
||||
local new_config_string = "{\n\t[\"blob_src\"] = \"" .. b2ws_config.blob_src .. "\",\n"
|
||||
new_config_string = new_config_string .. "\t[\"eth_fake_header_src\"] = \"" .. b2ws_config.eth_fake_header_src .. "\",\n"
|
||||
new_config_string = new_config_string .. "\t[\"eth_fake_header_dst\"] = \"" .. b2ws_config.eth_fake_header_dst .. "\",\n"
|
||||
new_config_string = new_config_string .. "\t[\"eth_fake_header_type\"] = \"" .. b2ws_config.eth_fake_header_type .. "\"\n}"
|
||||
return new_config_string
|
||||
end
|
||||
|
||||
47
src/b2ws-plugin/b2ws_import_gui.lua
Normal file
47
src/b2ws-plugin/b2ws_import_gui.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
if not gui_enabled() then return end
|
||||
|
||||
require "b2ws_const"
|
||||
local loaded_b2ws_import= assert(loadfile(b2ws_const.B2WS_PLUGIN_PATH .. "b2ws_import.lua"))
|
||||
loaded_b2ws_import()
|
||||
|
||||
local function b2ws_win_import_blob()
|
||||
local win = TextWindow.new(b2ws_const.B2WS_IMPORT_BLOB_WIN_TITLE)
|
||||
win:set_editable()
|
||||
config_file_path = create_b2ws_config_file_path(b2ws_const.B2WS_PLUGIN_PATH, b2ws_const.B2WS_PLUGIN_CONFIG_FILE_NAME)
|
||||
win:set(read_b2ws_file(config_file_path))
|
||||
|
||||
local function b2ws_win_btn_import_blob()
|
||||
-- load config from text field
|
||||
local win_text = win:get_text();
|
||||
|
||||
-- import to and show in pcap file
|
||||
output_path = b2ws_import_blob(win_text)
|
||||
open_capture_file(output_path, "")
|
||||
end
|
||||
|
||||
local function b2ws_win_btn_save_settings()
|
||||
-- load config from text field
|
||||
local win_text = b2ws_trim(win:get_text())
|
||||
write_b2ws_file(config_file_path, win_text)
|
||||
end
|
||||
|
||||
local function b2ws_win_btn_change_settings()
|
||||
local function b2ws_win_change_settings(blob_src, eth_src, eth_dst, eth_type)
|
||||
local win_text = b2ws_trim(win:get_text())
|
||||
win:set(b2ws_change_settings(win_text, blob_src, eth_src, eth_dst, eth_type))
|
||||
end
|
||||
|
||||
new_dialog(b2ws_const.B2WS_CHANGE_SETTINGS_DLG_TITLE,
|
||||
b2ws_win_change_settings,
|
||||
b2ws_const.B2WS_CONFIG_LABEL_BLOB_SRC,
|
||||
b2ws_const.B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_SRC,
|
||||
b2ws_const.B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_DST,
|
||||
b2ws_const.B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_TYPE)
|
||||
end
|
||||
|
||||
win:add_button(b2ws_const.B2WS_IMPORT_BLOB_BTN_TITLE, b2ws_win_btn_import_blob)
|
||||
win:add_button(b2ws_const.B2WS_SAVE_SETTINGS_BTN_TITLE, b2ws_win_btn_save_settings)
|
||||
win:add_button(b2ws_const.B2WS_CHANGE_SETTINGS_BTN_TITLE, b2ws_win_btn_change_settings)
|
||||
end
|
||||
|
||||
register_menu(b2ws_const.B2WS_IMPORT_BLOB_MENU_TITLE, b2ws_win_import_blob, MENU_TOOLS_UNSORTED)
|
||||
46
src/b2ws-plugin/b2ws_util.lua
Normal file
46
src/b2ws-plugin/b2ws_util.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
-- from http://lua-users.org/wiki/StringRecipes
|
||||
function b2ws_string_starts(String,Start)
|
||||
return string.sub(String,1,string.len(Start))==Start
|
||||
end
|
||||
|
||||
-- from http://lua-users.org/wiki/StringTrim
|
||||
function b2ws_trim(s)
|
||||
local from = s:match"^%s*()"
|
||||
return from > #s and "" or s:match(".*%S", from)
|
||||
end
|
||||
|
||||
function create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
|
||||
return persconffile_path(plugin_path) .. plugin_config_file_name
|
||||
end
|
||||
|
||||
function write_b2ws_file(file_path, content)
|
||||
local config_inp = assert(io.open(file_path, "w"))
|
||||
config_inp:write(content)
|
||||
assert(config_inp:close())
|
||||
end
|
||||
|
||||
function read_b2ws_file(file_path)
|
||||
local config_inp = assert(io.open(file_path, "r"))
|
||||
local config_string = config_inp:read("*all")
|
||||
assert(config_inp:close())
|
||||
return config_string
|
||||
end
|
||||
|
||||
function read_b2ws_config_file(plugin_path, plugin_config_file_name)
|
||||
local path = create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
|
||||
return read_b2ws_file(path)
|
||||
end
|
||||
|
||||
function write_b2ws_config_file(plugin_path, plugin_config_file_name, settings)
|
||||
local path = create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
|
||||
write_b2ws_file(path, settings)
|
||||
end
|
||||
|
||||
function create_b2ws_config_object(config_string)
|
||||
if not (b2ws_string_starts(config_string, "return ")) then
|
||||
config_string = "return " .. config_string
|
||||
end
|
||||
|
||||
local tmp_config_func = assert(loadstring(string.gsub(config_string, "[\n\r]", "")))
|
||||
return tmp_config_func()
|
||||
end
|
||||
Reference in New Issue
Block a user