Files

checklibs.src
  • TableHandler = {"table": {"columns": [], "rows": []}, "undefined": "?"}
  • TableHandler.add_column = function(title)
  • self.table["columns"].push(title)
  • for row_data in self.table["rows"]
  • row_data[title] = self.undefined
  • end for
  • end function
  • TableHandler.add_columns = function(title_list)
  • for title in title_list
  • self.add_column(title)
  • end for
  • end function
  • TableHandler.add_row = function(row_map)
  • data = {}
  • for column in self.table["columns"]
  • if row_map.hasIndex(column) then
  • data[column] = str(row_map[column])
  • else
  • data[column] = self.undefined
  • end if
  • end for
  • self.table["rows"].push(data)
  • end function
  • TableHandler.add_rows = function(rows_list)
  • for row_map in rows_list
  • self.add_row(row_map)
  • end for
  • end function
  • TableHandler.print_data = function(indent, title_color)
  • output_data = ""
  • columns = self.table["columns"]
  • rows = self.table["rows"]
  • title_indents = {}
  • for column in columns
  • output_data = output_data + "<color=" + title_color + ">" + column
  • title_indent = self.get_max_length(column) + indent - column.len
  • if title_indent < indent then title_indent = indent
  • title_indents[column] = title_indent
  • if columns.indexOf(column) != columns.len - 1 then output_data = output_data + " " * title_indent
  • end for
  • output_data = output_data + "</color>\n"
  • for row in rows
  • for column in columns
  • output_data = output_data + row[column]
  • row_indent = title_indents[column] + self.raw_string(column).len - self.raw_string(row[column]).len
  • if row_indent < indent then row_indent = indent
  • if columns.indexOf(column) != columns.len - 1 then output_data = output_data + " " * row_indent
  • end for
  • if rows.indexOf(row) != rows.len - 1 then output_data = output_data + "\n"
  • end for
  • print(output_data)
  • end function
  • TableHandler.get_max_length = function(column)
  • max_length = 0
  • for row in self.table["rows"]
  • length = self.raw_string(row[column]).len
  • if max_length < length then max_length = length
  • end for
  • return max_length
  • end function
  • TableHandler.raw_string = function(string)
  • if string.indexOf("<color=") != null then
  • string = string.split(">")[1].split("<")[0]
  • end if
  • return string
  • end function
  • TableHandler.clear = function()
  • self.table["columns"] = []
  • self.table["rows"] = []
  • end function
  • LibHandler = {"path_to_libs": "/lib", "metalibs_list": [], "libs_files": {}, "required_update": []}
  • LibHandler._init_ = function(libs_path)
  • if libs_path then
  • self.path_to_libs = libs_path
  • self.metalibs_list = []
  • self.libs_files = {}
  • self.required_update = []
  • self.libs_directory = get_shell.host_computer.File(self.path_to_libs)
  • if not self.libs_directory then self.error("Folder ""<b>" + self.path_to_libs + "</b>"" was not found!")
  • self.metaxploit = self.include("metaxploit.so")
  • self.apt_client = self.include("aptclient.so")
  • self.get_libs()
  • end function
  • LibHandler.get_libs = function()
  • self.metalibs_list = []
  • self.libs_files = {}
  • self.required_update = []
  • for file in self.libs_directory.get_files
  • if not file.is_binary or file.name.split(".")[-1] != "so" then continue
  • lib = self.load_lib(file.name)
  • self.metalibs_list.push(lib)
  • self.libs_files[lib.lib_name] = file
  • self.get_update(lib)
  • end for
  • end function
  • LibHandler.load_lib = function(file_name)
  • lib = self.metaxploit.load(self.path_to_libs + "/" + file_name)
  • if not lib then self.error("File ""<b>" + self.path_to_libs + "/" + file_name + "</b>"" was not loaded!")
  • return lib
  • end function
  • LibHandler.include = function(file_name)
  • lib = include_lib(self.path_to_libs + "/" + file_name)
  • if not lib then self.error("File ""<b>" + self.path_to_libs + "/" + file_name + "</b>"" was not found!")
  • return lib
  • end function
  • LibHandler.error = function(content)
  • exit("<color=red>" + content + "</color>")
  • end function
  • LibHandler.print_data = function()
  • data_table = new TableHandler
  • data_table.add_columns(["NAME", "VERSION", "UPDATE"])
  • for lib in self.metalibs_list
  • data_table.add_row({"NAME": lib.lib_name, "VERSION": lib.version, "UPDATE": self.get_update(lib)})
  • end for
  • data_table.print_data(5, "orange")
  • data_table.clear()
  • end function
  • LibHandler.add_to_required = function(lib_name_string)
  • if self.required_update.indexOf(lib_name_string) == null then self.required_update.push(lib_name_string)
  • end function
  • LibHandler.get_update = function(lib)
  • output = ""
  • update_state = self.apt_client.check_upgrade(self.libs_files[lib.lib_name].path)
  • if update_state == 0 then
  • output = "<color=green>RECEIVED</color>"
  • else if update_state == 1 then
  • output = "<color=red>REQUIRED</color>"
  • self.add_to_required(lib.lib_name)
  • else
  • output = "<color=yellow>UNDEFINED</color>"
  • end if
  • return output
  • end function
  • LibHandler.update = function(lib)
  • if typeof(lib) == "string" then lib = self.load_lib(lib)
  • print("Downloading update for ""<b>" + lib.lib_name + "</b>""...")
  • old_version = lib.version
  • wait(0.5)
  • self.apt_client.install(lib.lib_name, self.path_to_libs)
  • print("Update for ""<b>" + lib.lib_name + "</b>"" installed <color=green>successfully</color>! [<b>" + old_version + "</b>-><b>" + lib.version + "</b>]")
  • end function
  • LibHandler.update_required = function()
  • if self.required_update.len == 0 then
  • for lib in self.metalibs_list
  • self.get_update(lib)
  • end for
  • end if
  • for lib_name_string in self.required_update
  • self.update(self.load_lib(lib_name_string))
  • end for
  • self.get_libs()
  • end function
  • parse_parameters = function(parameters, allowed_flags, data_flags, optional_data_flags)
  • is_flag = function(parameter)
  • if parameter[0] == "-" then
  • return true
  • else
  • return false
  • end if
  • end function
  • is_allowed = function(flag)
  • if allowed_flags.indexOf(flag) != null then
  • return true
  • else
  • return false
  • end if
  • end function
  • is_data = function(flag)
  • return data_flags.hasIndex(flag)
  • end function
  • is_optional_data = function(flag)
  • return optional_data_flags.hasIndex(flag)
  • end function
  • invalid_option = function(flag, flag_help)
  • exit("<color=red>Wrong argument. Usage: ""<b>" + flag + " " + flag_help + "</b>""")
  • end function
  • output = []
  • if parameters.len == 0 then return []
  • for i in range(0, parameters.len - 1)
  • parameter = parameters[i]
  • if is_flag(parameter) then
  • if not is_allowed(parameter) then exit("<color=red>Flag ""<b>" + parameter + "</b>"" is not allowed!")
  • if not is_data(parameter) and not is_optional_data(parameter) then
  • output.push({"data_flag": false, "flag": parameter})
  • else if is_data(parameter) and not is_optional_data(parameter) then
  • if not parameters.hasIndex(i+1) or is_flag(parameters[i+1]) then invalid_option(parameter, data_flags[parameter])
  • output.push({"data_flag": true, "flag": parameter, "data": parameters[i+1]})
  • else
  • if parameters.hasIndex(i+1) and not is_flag(parameters[i+1]) then
  • output.push({"data_flag": true, "flag": parameter, "data": parameters[i+1]})
  • else
  • output.push({"data_flag": false, "flag": parameter})
  • end if
  • end if
  • end if
  • end for
  • return output
  • end function
  • help = function(close)
  • info = "Additional parameters:\nParameter ""<b>-p</b>"" is required to set path to libs folder. \nExample: <b>" + program_path.split("/")[-1] + " -p /bin/libs</b>\nParameter ""<b>-u</b> optional:[library_name]"" is required to update libs.\nExample: <b>" + program_path.split("/")[-1] + " -u init.so</b>\nParameter ""<b>-s</b>"" is required to show libs info.\nExample: <b>" + program_path.split("/")[-1] + " -s </b>"
  • if close then
  • exit(info)
  • else
  • print(info)
  • end function
  • find_any = function(parameters, flags)
  • for parameter in parameters
  • for flag in flags
  • if parameter["flag"] == flag then return true
  • end for
  • end for
  • return false
  • end function
  • main = function()
  • libs_path = "/lib"
  • lib_handler = new LibHandler
  • lib_handler._init_(libs_path)
  • parameters = parse_parameters(params, ["-h", "-help", "-p", "-path", "-u", "-update", "-s", "-show"], {"-p": "[path]", "-path": "[path]"}, {"-u": "[library_name]", "-update": "[library_name]"})
  • for parameter in parameters
  • if parameter["flag"] == "-s" or parameter["flag"] == "-show" then lib_handler.print_data()
  • if parameter["flag"] == "-h" or parameter["flag"] == "-help" then help(false)
  • if parameter["flag"] == "-p" or parameter["flag"] == "-path" then
  • libs_path = parameter["data"]
  • lib_handler._init_(libs_path)
  • end if
  • if parameter["flag"] == "-u" or parameter["flag"] == "-update" then
  • if parameter["data_flag"] then lib_handler.update(parameter["data"])
  • if not parameter["data_flag"] then lib_handler.update_required()
  • end if
  • end for
  • if parameters.len == 0 or not find_any(parameters, ["-h", "-help", "-s", "-show"]) then lib_handler.print_data()
  • end function
  • main()