Skip to content

Commit 05b7a18

Browse files
committed
More rust cleanup
- Updated README to clarify offline documentation - Refactored settings api - Added settings example to show dumping settings value and specific properties - Use the workspace to depend on binaryninja and binaryninjacore-sys - Remove binaryninjacore-sys as a workspace member (its not really required)
1 parent 72c98dc commit 05b7a18

File tree

32 files changed

+475
-288
lines changed

32 files changed

+475
-288
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
resolver = "2"
77
members = [
88
"rust",
9-
"rust/binaryninjacore-sys",
109
"arch/riscv",
1110
"arch/msp430",
1211
"view/bintxt",
@@ -20,6 +19,10 @@ members = [
2019
"plugins/warp"
2120
]
2221

22+
[workspace.dependencies]
23+
binaryninja = { path = "rust" }
24+
binaryninjacore-sys = { path = "rust/binaryninjacore-sys" }
25+
2326
[profile.release]
2427
lto = true
2528
debug = "full"

arch/msp430/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ authors = ["jrozner"]
55
edition = "2021"
66

77
[dependencies]
8-
binaryninja = { path = "../../rust" }
9-
binaryninjacore-sys = { path = "../../rust/binaryninjacore-sys" }
8+
binaryninja.workspace = true
9+
binaryninjacore-sys.workspace = true
1010
log = "0.4"
1111
msp430-asm = "^0.2"
1212

arch/riscv/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ authors = ["Ryan Snyder <ryan.snyder.or@gmail.com>"]
55
edition = "2021"
66

77
[dependencies]
8-
binaryninja = { path = "../../rust" }
9-
binaryninjacore-sys = { path = "../../rust/binaryninjacore-sys" }
8+
binaryninja.workspace = true
9+
binaryninjacore-sys.workspace = true
1010
riscv-dis = { path = "disasm" }
1111
log = "0.4"
1212
rayon = { version = "1.0", optional = true }

plugins/dwarf/dwarf_export/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2021"
77
crate-type = ["cdylib"]
88

99
[dependencies]
10-
binaryninja = { path = "../../../rust" }
11-
binaryninjacore-sys = { path = "../../../rust/binaryninjacore-sys" }
10+
binaryninja.workspace = true
11+
binaryninjacore-sys.workspace = true
1212
gimli = "^0.31"
13-
log = "^0.4"
13+
log = "0.4"
1414
object = { version = "0.32.1", features = ["write"] }

plugins/dwarf/dwarf_import/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
dwarfreader = { path = "../shared/" }
11-
binaryninja = { path = "../../../rust" }
12-
binaryninjacore-sys = { path = "../../../rust/binaryninjacore-sys" }
11+
binaryninja.workspace = true
12+
binaryninjacore-sys.workspace = true
1313
gimli = "0.31"
14-
log = "0.4.20"
14+
log = "0.4"
1515
iset = "0.2.2"
1616
cpp_demangle = "0.4.3"
1717
regex = "1"

plugins/dwarf/dwarf_import/src/helpers.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use gimli::{
3333
DebuggingInformationEntry, Operation, Unit, UnitOffset, UnitSectionOffset,
3434
};
3535

36+
use binaryninja::settings::QueryOptions;
3637
use log::warn;
3738

3839
pub(crate) fn get_uid<R: ReaderType>(
@@ -414,9 +415,10 @@ pub(crate) fn download_debug_info(
414415
build_id: &str,
415416
view: &BinaryView,
416417
) -> Result<Ref<BinaryView>, String> {
417-
let settings = Settings::new("");
418-
419-
let debug_server_urls = settings.get_string_list("network.debuginfodServers", Some(view), None);
418+
let mut settings_query_opts = QueryOptions::new_with_view(view);
419+
let settings = Settings::new();
420+
let debug_server_urls =
421+
settings.get_string_list_with_opts("network.debuginfodServers", &mut settings_query_opts);
420422

421423
for debug_server_url in debug_server_urls.iter() {
422424
let artifact_url = format!("{}/buildid/{}/debuginfo", debug_server_url, build_id);
@@ -487,19 +489,21 @@ pub(crate) fn find_local_debug_file_for_build_id(
487489
build_id: &str,
488490
view: &BinaryView,
489491
) -> Option<String> {
490-
let settings = Settings::new("");
491-
let debug_dirs_enabled = settings.get_bool(
492+
let mut settings_query_opts = QueryOptions::new_with_view(view);
493+
let settings = Settings::new();
494+
let debug_dirs_enabled = settings.get_bool_with_opts(
492495
"analysis.debugInfo.enableDebugDirectories",
493-
Some(view),
494-
None,
496+
&mut settings_query_opts,
495497
);
496498

497499
if !debug_dirs_enabled {
498500
return None;
499501
}
500502

501-
let debug_info_paths =
502-
settings.get_string_list("analysis.debugInfo.debugDirectories", Some(view), None);
503+
let debug_info_paths = settings.get_string_list_with_opts(
504+
"analysis.debugInfo.debugDirectories",
505+
&mut settings_query_opts,
506+
);
503507

504508
if debug_info_paths.is_empty() {
505509
return None;
@@ -530,6 +534,8 @@ pub(crate) fn load_debug_info_for_build_id(
530534
build_id: &str,
531535
view: &BinaryView,
532536
) -> (Option<Ref<BinaryView>>, bool) {
537+
let mut settings_query_opts = QueryOptions::new_with_view(view);
538+
let settings = Settings::new();
533539
if let Some(debug_file_path) = find_local_debug_file_for_build_id(build_id, view) {
534540
return (
535541
binaryninja::load_with_options(
@@ -539,16 +545,19 @@ pub(crate) fn load_debug_info_for_build_id(
539545
),
540546
false,
541547
);
542-
} else if Settings::new("").get_bool("network.enableDebuginfod", Some(view), None) {
548+
} else if settings.get_bool_with_opts("network.enableDebuginfod", &mut settings_query_opts) {
543549
return (download_debug_info(build_id, view).ok(), true);
544550
}
545551
(None, false)
546552
}
547553

548554
pub(crate) fn find_sibling_debug_file(view: &BinaryView) -> Option<String> {
549-
let settings = Settings::new("");
550-
let load_sibling_debug =
551-
settings.get_bool("analysis.debugInfo.loadSiblingDebugFiles", Some(view), None);
555+
let mut settings_query_opts = QueryOptions::new_with_view(view);
556+
let settings = Settings::new();
557+
let load_sibling_debug = settings.get_bool_with_opts(
558+
"analysis.debugInfo.loadSiblingDebugFiles",
559+
&mut settings_query_opts,
560+
);
552561

553562
if !load_sibling_debug {
554563
return None;

plugins/dwarf/dwarf_import/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl CustomDebugInfoParser for DWARFParser {
693693
pub extern "C" fn CorePluginInit() -> bool {
694694
Logger::new("DWARF").init();
695695

696-
let settings = Settings::new("");
696+
let settings = Settings::new();
697697

698698
settings.register_setting_json(
699699
"network.enableDebuginfod",

plugins/dwarf/dwarfdump/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ crate-type = ["cdylib"]
99

1010
[dependencies]
1111
dwarfreader = { path = "../shared/" }
12-
binaryninja = { path = "../../../rust" }
13-
binaryninjacore-sys = { path = "../../../rust/binaryninjacore-sys" }
12+
binaryninja.workspace = true
13+
binaryninjacore-sys.workspace = true
1414
gimli = "0.31"
File renamed without changes.

0 commit comments

Comments
 (0)