summaryrefslogtreecommitdiff
path: root/plugins/warp/src/plugin/settings.rs
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/warp/src/plugin/settings.rs')
-rw-r--r--plugins/warp/src/plugin/settings.rs76
1 files changed, 74 insertions, 2 deletions
diff --git a/plugins/warp/src/plugin/settings.rs b/plugins/warp/src/plugin/settings.rs
index 489deb23..39092177 100644
--- a/plugins/warp/src/plugin/settings.rs
+++ b/plugins/warp/src/plugin/settings.rs
@@ -1,4 +1,4 @@
-use binaryninja::settings::Settings as BNSettings;
+use binaryninja::settings::{QueryOptions, Settings as BNSettings};
use serde_json::json;
use std::string::ToString;
@@ -20,6 +20,12 @@ pub struct PluginSettings {
///
/// This is set to [PluginSettings::SERVER_API_KEY_DEFAULT] by default.
pub server_api_key: Option<String>,
+ pub second_server_url: Option<String>,
+ pub second_server_api_key: Option<String>,
+ /// A source must have at least one of these tags to be considered a valid source.
+ ///
+ /// This is set to [PluginSettings::SOURCE_TAGS_DEFAULT] by default.
+ pub whitelisted_source_tags: Vec<String>,
/// Whether to allow networked WARP requests. Turning this off will not disable local WARP functionality.
///
/// This is set to [PluginSettings::ENABLE_SERVER_DEFAULT] by default.
@@ -27,6 +33,8 @@ pub struct PluginSettings {
}
impl PluginSettings {
+ pub const WHITELISTED_SOURCE_TAGS_DEFAULT: Vec<String> = vec![];
+ pub const WHITELISTED_SOURCE_TAGS_SETTING: &'static str = "analysis.warp.whitelistedSourceTags";
pub const LOAD_BUNDLED_FILES_DEFAULT: bool = true;
pub const LOAD_BUNDLED_FILES_SETTING: &'static str = "analysis.warp.loadBundledFiles";
pub const LOAD_USER_FILES_DEFAULT: bool = true;
@@ -35,10 +43,25 @@ impl PluginSettings {
pub const SERVER_URL_SETTING: &'static str = "analysis.warp.serverUrl";
pub const SERVER_API_KEY_DEFAULT: Option<String> = None;
pub const SERVER_API_KEY_SETTING: &'static str = "analysis.warp.serverApiKey";
+ pub const SECONDARY_SERVER_URL_DEFAULT: Option<String> = None;
+ pub const SECONDARY_SERVER_URL_SETTING: &'static str = "analysis.warp.secondServerUrl";
+ pub const SECONDARY_SERVER_API_KEY_DEFAULT: Option<String> = None;
+ pub const SECONDARY_SERVER_API_KEY_SETTING: &'static str = "analysis.warp.secondServerApiKey";
pub const ENABLE_SERVER_DEFAULT: bool = false;
pub const ENABLE_SERVER_SETTING: &'static str = "network.enableWARP";
pub fn register(bn_settings: &mut BNSettings) {
+ let whitelisted_source_tags_prop = json!({
+ "title" : "Blacklisted Sources",
+ "type" : "array",
+ "default" : Self::WHITELISTED_SOURCE_TAGS_DEFAULT,
+ "description" : "Add a sources UUID to this list to blacklist it from being considered a valid source. This is useful for sources that are known to be false positives.",
+ "ignore" : [],
+ });
+ bn_settings.register_setting_json(
+ Self::WHITELISTED_SOURCE_TAGS_SETTING,
+ &whitelisted_source_tags_prop.to_string(),
+ );
let load_bundled_files_prop = json!({
"title" : "Load Bundled Files",
"type" : "boolean",
@@ -85,6 +108,31 @@ impl PluginSettings {
Self::SERVER_API_KEY_SETTING,
&server_api_key_prop.to_string(),
);
+ let second_server_url_prop = json!({
+ "title" : "Secondary Server URL",
+ "type" : "string",
+ "default" : Self::SECONDARY_SERVER_URL_DEFAULT,
+ "description" : "",
+ "ignore" : ["SettingsProjectScope", "SettingsResourceScope"],
+ "requiresRestart" : true
+ });
+ bn_settings.register_setting_json(
+ Self::SECONDARY_SERVER_URL_SETTING,
+ &second_server_url_prop.to_string(),
+ );
+ let second_server_api_key_prop = json!({
+ "title" : "Secondary Server API Key",
+ "type" : "string",
+ "default" : Self::SECONDARY_SERVER_API_KEY_DEFAULT,
+ "description" : "",
+ "ignore" : ["SettingsProjectScope", "SettingsResourceScope"],
+ "hidden": true,
+ "requiresRestart" : true
+ });
+ bn_settings.register_setting_json(
+ Self::SECONDARY_SERVER_API_KEY_SETTING,
+ &second_server_api_key_prop.to_string(),
+ );
let server_enabled_prop = json!({
"title" : "Enable WARP",
"type" : "boolean",
@@ -100,7 +148,7 @@ impl PluginSettings {
}
/// Retrieve plugin settings from [`BNSettings`].
- pub fn from_settings(bn_settings: &BNSettings) -> Self {
+ pub fn from_settings(bn_settings: &BNSettings, query_opts: &mut QueryOptions) -> Self {
let mut settings = PluginSettings::default();
if bn_settings.contains(Self::LOAD_BUNDLED_FILES_SETTING) {
settings.load_bundled_files = bn_settings.get_bool(Self::LOAD_BUNDLED_FILES_SETTING);
@@ -117,9 +165,30 @@ impl PluginSettings {
settings.server_api_key = Some(server_api_key_str);
}
}
+ if bn_settings.contains(Self::SECONDARY_SERVER_URL_SETTING) {
+ let server_api_key_str = bn_settings.get_string(Self::SECONDARY_SERVER_URL_SETTING);
+ if !server_api_key_str.is_empty() {
+ settings.second_server_url = Some(server_api_key_str);
+ }
+ }
+ if bn_settings.contains(Self::SECONDARY_SERVER_API_KEY_SETTING) {
+ let server_api_key_str = bn_settings.get_string(Self::SECONDARY_SERVER_API_KEY_SETTING);
+ if !server_api_key_str.is_empty() {
+ settings.second_server_api_key = Some(server_api_key_str);
+ }
+ }
if bn_settings.contains(Self::ENABLE_SERVER_SETTING) {
settings.enable_server = bn_settings.get_bool(Self::ENABLE_SERVER_SETTING);
}
+
+ if bn_settings.contains(Self::WHITELISTED_SOURCE_TAGS_SETTING) {
+ let whitelisted_source_tags_str = bn_settings
+ .get_string_list_with_opts(Self::WHITELISTED_SOURCE_TAGS_SETTING, query_opts);
+ settings.whitelisted_source_tags = whitelisted_source_tags_str
+ .iter()
+ .map(|s| s.to_string())
+ .collect();
+ }
settings
}
}
@@ -127,10 +196,13 @@ impl PluginSettings {
impl Default for PluginSettings {
fn default() -> Self {
Self {
+ whitelisted_source_tags: PluginSettings::WHITELISTED_SOURCE_TAGS_DEFAULT,
load_bundled_files: PluginSettings::LOAD_BUNDLED_FILES_DEFAULT,
load_user_files: PluginSettings::LOAD_USER_FILES_DEFAULT,
server_url: PluginSettings::SERVER_URL_DEFAULT.to_string(),
server_api_key: PluginSettings::SERVER_API_KEY_DEFAULT,
+ second_server_url: PluginSettings::SECONDARY_SERVER_URL_DEFAULT,
+ second_server_api_key: PluginSettings::SECONDARY_SERVER_API_KEY_DEFAULT,
enable_server: PluginSettings::ENABLE_SERVER_DEFAULT,
}
}