Skip to content

Commit 1b555c2

Browse files
committed
[BNTL] Misc improvements
1 parent d35ce9b commit 1b555c2

File tree

7 files changed

+33
-17
lines changed

7 files changed

+33
-17
lines changed

Cargo.lock

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

plugins/bntl_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ walkdir = "2.5"
2323
dashmap = "6.1"
2424

2525
# For TBD parsing
26-
serde-saphyr = { version = "0.0.18", default-features = false, features = [] }
26+
serde-saphyr = { version = "0.0.19", default-features = false, features = [] }
2727

2828
# For reports
2929
minijinja = "2.10.2"

plugins/bntl_utils/cli/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Examples:
3434
- Downloads and processes all files in the project, placing potentially multiple `.bntl` files in the `output` directory.
3535
- `./bntl_cli create sqlite3.dll "windows-x86_64" ./winmd/ ./output/`
3636
- `winmd` files are also supported as input, they will be processed together. You also probably want to provide some apiset schema files as well.
37+
- `./bntl_cli create sqlite3.dll "windows-x86_64" ./headers/ ./output/ --include-directories ./system_headers/`
38+
- You can also specify additional include directories to search for referenced headers.
3739

3840
#### Dump
3941

@@ -45,7 +47,7 @@ Examples:
4547

4648
#### Diff
4749

48-
Compare two type libraries and generate a .diff file containing a similarity ratio.
50+
Compare two type libraries and generate a .diff file.
4951

5052
Examples:
5153

plugins/bntl_utils/cli/src/create.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct CreateArgs {
1414
pub platform: String,
1515
pub input: Input,
1616
pub output_directory: Option<PathBuf>,
17+
/// A list of directories to use for include paths when parsing C header files.
18+
#[clap(long)]
19+
pub include_directories: Vec<PathBuf>,
1720
#[clap(long)]
1821
pub dry_run: bool,
1922
}
@@ -37,7 +40,8 @@ impl CreateArgs {
3740
}
3841
std::fs::create_dir_all(&output_path).expect("Failed to create output directory");
3942

40-
let processor = TypeLibProcessor::new(&self.name, &self.platform);
43+
let processor = TypeLibProcessor::new(&self.name, &self.platform)
44+
.with_include_directories(self.include_directories.clone());
4145
// TODO: Need progress indicator here, when downloading files.
4246
let resolved_input = self.input.resolve().expect("Failed to resolve input");
4347

plugins/bntl_utils/src/command/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::command::{InputDirectoryField, OutputDirectoryField};
22
use crate::helper::path_to_type_libraries;
33
use crate::validate::TypeLibValidater;
4-
use binaryninja::binary_view::{BinaryView, BinaryViewExt};
4+
use binaryninja::binary_view::BinaryView;
55
use binaryninja::command::Command;
66
use binaryninja::interaction::Form;
77
use binaryninja::platform::Platform;

plugins/bntl_utils/src/process.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,12 @@ impl ProcessedData {
354354
(QualifiedName, CoreArchitecture),
355355
Vec<Ref<TypeLibrary>>,
356356
> = HashMap::new();
357-
for merged_type_library in &self.type_libraries {
358-
for named_type in &merged_type_library.named_types() {
357+
for tl in &self.type_libraries {
358+
for named_type in &tl.named_types() {
359359
mapped_named_types
360-
.entry((named_type.name.clone(), merged_type_library.arch()))
360+
.entry((named_type.name.clone(), tl.arch()))
361361
.or_default()
362-
.push(merged_type_library.clone());
362+
.push(tl.clone());
363363
}
364364
}
365365

@@ -553,12 +553,16 @@ impl TypeLibProcessor {
553553
.filter_map(|res| match res {
554554
Ok(result) => Some(Ok(result)),
555555
Err(ProcessingError::SkippedFile(path)) => {
556-
tracing::debug!("Skipping project root file: {:?}", path);
556+
tracing::debug!("Skipping project file: {:?}", path);
557557
None
558558
}
559559
Err(ProcessingError::Cancelled) => Some(Err(ProcessingError::Cancelled)),
560+
Err(ProcessingError::NoPathToProjectFile(path)) => {
561+
tracing::warn!("Project file not downloaded: {:?}", path);
562+
None
563+
}
560564
Err(e) => {
561-
tracing::error!("Project root file processing error: {:?}", e);
565+
tracing::error!("Project file processing error: {:?}", e);
562566
None
563567
}
564568
})
@@ -588,12 +592,16 @@ impl TypeLibProcessor {
588592
.filter_map(|res| match res {
589593
Ok(result) => Some(Ok(result)),
590594
Err(ProcessingError::SkippedFile(path)) => {
591-
tracing::debug!("Skipping project directory file: {:?}", path);
595+
tracing::debug!("Skipping project file: {:?}", path);
592596
None
593597
}
594598
Err(ProcessingError::Cancelled) => Some(Err(ProcessingError::Cancelled)),
599+
Err(ProcessingError::NoPathToProjectFile(path)) => {
600+
tracing::warn!("Project file not downloaded: {:?}", path);
601+
None
602+
}
595603
Err(e) => {
596-
tracing::error!("Project folder file processing error: {:?}", e);
604+
tracing::error!("Project file processing error: {:?}", e);
597605
None
598606
}
599607
})
@@ -1093,13 +1101,13 @@ pub fn is_parsable(path: &Path) -> bool {
10931101
if path.extension() == Some(OsStr::new("pdb")) {
10941102
return false;
10951103
}
1096-
let mut metadata = FileMetadata::with_file_path(path);
1097-
let Ok(view) = BinaryView::from_path(&metadata, path) else {
1104+
let metadata = FileMetadata::with_file_path(path);
1105+
let Ok(view) = BinaryView::from_metadata(&metadata) else {
10981106
return false;
10991107
};
11001108
// If any view type parses this file, consider it for this source.
11011109
// All files will have a "Raw" file type, so we account for that.
1102-
BinaryViewType::list_valid_types_for(&view).len() > 1
1110+
BinaryViewType::valid_types_for_data(&view).len() > 1
11031111
}
11041112

11051113
#[cfg(test)]

plugins/bntl_utils/src/tbd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Parse Apples TBD file format, which gives information about where source symbols are located.
2+
13
use binaryninja::architecture::CoreArchitecture;
24
use binaryninja::platform::Platform;
35
use binaryninja::rc::Ref;

0 commit comments

Comments
 (0)