summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2026-02-17 20:30:44 -0800
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-02-23 00:09:44 -0800
commit65c217ae27e6b0abe26d5baea40f2bab695a3651 (patch)
tree162800e27c5dbe95eb187522b69dec936b4118bf /plugins
parent37008b7fa16837d04c1658868646cad681cbe035 (diff)
[BNTL Utils] Fix misc clippy lints
Diffstat (limited to 'plugins')
-rw-r--r--plugins/bntl_utils/src/command/create.rs5
-rw-r--r--plugins/bntl_utils/src/dump.rs2
-rw-r--r--plugins/bntl_utils/src/helper.rs2
-rw-r--r--plugins/bntl_utils/src/merge.rs3
-rw-r--r--plugins/bntl_utils/src/process.rs44
-rw-r--r--plugins/bntl_utils/src/tbd.rs7
-rw-r--r--plugins/bntl_utils/src/url.rs2
-rw-r--r--plugins/bntl_utils/src/winmd.rs9
-rw-r--r--plugins/bntl_utils/src/winmd/translate.rs11
9 files changed, 38 insertions, 47 deletions
diff --git a/plugins/bntl_utils/src/command/create.rs b/plugins/bntl_utils/src/command/create.rs
index 41b5517a..5fa8c2be 100644
--- a/plugins/bntl_utils/src/command/create.rs
+++ b/plugins/bntl_utils/src/command/create.rs
@@ -7,7 +7,6 @@ use binaryninja::command::{Command, ProjectCommand};
use binaryninja::interaction::{Form, FormInputField, MessageBoxButtonSet, MessageBoxIcon};
use binaryninja::platform::Platform;
use binaryninja::project::Project;
-use binaryninja::types::TypeLibrary;
use std::thread;
pub struct CreateFromCurrentView;
@@ -226,10 +225,10 @@ impl CreateFromProject {
let background_task = BackgroundTask::new("Processing started...", true);
new_processing_state_background_thread(background_task.clone(), processor.state());
- let data = processor.process_project(&project);
+ let data = processor.process_project(project);
background_task.finish();
- let mut finalized_data = match data {
+ let finalized_data = match data {
// Prune off empty type libraries, no need to save them.
Ok(data) => data.finalized(&default_name),
Err(err) => {
diff --git a/plugins/bntl_utils/src/dump.rs b/plugins/bntl_utils/src/dump.rs
index ddc9f602..410f1cb1 100644
--- a/plugins/bntl_utils/src/dump.rs
+++ b/plugins/bntl_utils/src/dump.rs
@@ -58,7 +58,7 @@ impl TILDump {
let platform_name_str = platform_name.to_string();
let platform = Platform::by_name(&platform_name_str)
- .ok_or_else(|| TILDumpError::PlatformNotFound(platform_name_str))?;
+ .ok_or(TILDumpError::PlatformNotFound(platform_name_str))?;
empty_bv.set_default_platform(&platform);
diff --git a/plugins/bntl_utils/src/helper.rs b/plugins/bntl_utils/src/helper.rs
index 3fc1a047..2aea8e0a 100644
--- a/plugins/bntl_utils/src/helper.rs
+++ b/plugins/bntl_utils/src/helper.rs
@@ -8,7 +8,7 @@ pub fn path_to_type_libraries(path: &Path) -> Vec<Ref<TypeLibrary>> {
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
- .filter(|e| e.path().extension().map_or(false, |ext| ext == "bntl"))
+ .filter(|e| e.path().extension().is_some_and(|ext| ext == "bntl"))
.filter_map(|e| TypeLibrary::load_from_file(e.path()))
.collect::<Vec<_>>()
}
diff --git a/plugins/bntl_utils/src/merge.rs b/plugins/bntl_utils/src/merge.rs
index 454be10f..0a3b3377 100644
--- a/plugins/bntl_utils/src/merge.rs
+++ b/plugins/bntl_utils/src/merge.rs
@@ -101,12 +101,11 @@ fn merge_structures(s1: &Structure, s2: &Structure) -> Option<Ref<Structure>> {
for m in &s.members() {
members
.entry(m.offset)
- .and_modify(|(existing_name, existing_ty)| {
+ .and_modify(|(_existing_name, existing_ty)| {
// Update type if merge succeeds
if let Some(merged) = merge_recursive(existing_ty, &m.ty.contents) {
*existing_ty = merged;
}
- // Name collision: Keep existing (s1/first wins), ignoring m.name
})
.or_insert_with(|| (m.name.clone(), m.ty.contents.to_owned()));
}
diff --git a/plugins/bntl_utils/src/process.rs b/plugins/bntl_utils/src/process.rs
index 614e8206..b287a1d4 100644
--- a/plugins/bntl_utils/src/process.rs
+++ b/plugins/bntl_utils/src/process.rs
@@ -144,7 +144,7 @@ impl ProcessedData {
}
pub fn finalized(mut self, default_name: &str) -> Self {
- self.deduplicate_types(&default_name);
+ self.deduplicate_types(default_name);
// TODO: Run remap.
self.prune()
}
@@ -209,7 +209,7 @@ impl ProcessedData {
merged_type_library.add_alternate_name(alt_name);
}
for platform_name in &tl.platform_names() {
- if let Some(platform) = Platform::by_name(&platform_name) {
+ if let Some(platform) = Platform::by_name(platform_name) {
merged_type_library.add_platform(&platform);
} else {
// TODO: Upgrade this to an error?
@@ -375,14 +375,13 @@ impl ProcessedData {
for type_library in type_libraries {
// If the default type library does not have the platform, it will not be pulled in.
for platform_name in &type_library.platform_names() {
- if let Some(platform) = Platform::by_name(&platform_name) {
+ if let Some(platform) = Platform::by_name(platform_name) {
default_type_library.add_platform(&platform);
}
}
type_library.remove_named_type(qualified_name.clone());
- type_library
- .add_type_source(qualified_name.clone(), &default_type_library_name);
+ type_library.add_type_source(qualified_name.clone(), default_type_library_name);
}
} else {
// TODO: Probably demote this to debug, since they might just be disparate types.
@@ -480,7 +479,7 @@ impl TypeLibProcessor {
pub fn process(&self, path: &Path) -> Result<ProcessedData, ProcessingError> {
match path.extension() {
- Some(ext) if ext == "bntl" => self.process_type_library(&path),
+ Some(ext) if ext == "bntl" => self.process_type_library(path),
Some(ext) if ext == "h" || ext == "hpp" => self.process_source(path),
// NOTE: A typical processor will not go down this path where we only provide a single
// winmd file to be processed. You almost always want to process multiple winmd files,
@@ -603,18 +602,18 @@ impl TypeLibProcessor {
project_file: &ProjectFile,
) -> Result<ProcessedData, ProcessingError> {
let file_name = project_file.name();
- let extension = file_name.split('.').last();
+ let extension = file_name.split('.').next_back();
let path = project_file
.path_on_disk()
.ok_or_else(|| ProcessingError::NoPathToProjectFile(project_file.to_owned()))?;
match extension {
- Some(ext) if ext == "bntl" => self.process_type_library(&path),
+ Some("bntl") => self.process_type_library(&path),
Some(ext) if ext == "h" || ext == "hpp" => self.process_source(&path),
// NOTE: A typical processor will not go down this path where we only provide a single
// winmd file to be processed. You almost always want to process multiple winmd files,
// which can be done by passing a directory with the relevant winmd files.
- Some(ext) if ext == "winmd" => self.process_winmd(&[path]),
- Some(ext) if ext == "tbd" => self.process_tbd(&path),
+ Some("winmd") => self.process_winmd(&[path]),
+ Some("tbd") => self.process_tbd(&path),
_ => {
// If the file cannot be parsed, it should be skipped to avoid a load error.
if !is_parsable(&path) {
@@ -623,7 +622,7 @@ impl TypeLibProcessor {
let settings_str = self.analysis_settings.to_string();
let file = binaryninja::load_project_file_with_progress(
- &project_file,
+ project_file,
false,
Some(settings_str),
|_pos, _total| {
@@ -654,7 +653,7 @@ impl TypeLibProcessor {
let settings_str = self.analysis_settings.to_string();
let file = binaryninja::load_with_options_and_progress(
- &path,
+ path,
false,
Some(settings_str),
|_pos, _total| {
@@ -800,10 +799,10 @@ impl TypeLibProcessor {
type_library.store_metadata("ordinals_10_0", &map_md);
}
- let mut processed_data = self.process_external_libraries(&view)?;
+ let mut processed_data = self.process_external_libraries(view)?;
processed_data.type_libraries.insert(type_library);
if let Some(api_set_section) = view.section_by_name(".apiset") {
- let processed_api_set = self.process_api_set(&view, &api_set_section)?;
+ let processed_api_set = self.process_api_set(view, &api_set_section)?;
tracing::info!(
"Found {} api set libraries in '{}', adding alternative names...",
processed_api_set.type_libraries.len(),
@@ -905,7 +904,7 @@ impl TypeLibProcessor {
let section_bytes = view
.read_buffer(section.start(), section.len())
.ok_or_else(|| ProcessingError::BinaryViewRead(section.start(), section.len()))?;
- let api_set_map = ApiSetMap::try_from_apiset_section_bytes(&section_bytes.get_data())?;
+ let api_set_map = ApiSetMap::try_from_apiset_section_bytes(section_bytes.get_data())?;
let mut target_map: HashMap<String, HashSet<String>> = HashMap::new();
for entry in api_set_map.namespace_entries()? {
@@ -944,7 +943,7 @@ impl TypeLibProcessor {
/// during the [`ProcessedData::merge`] step. This lets us add overrides like extra platforms.
pub fn process_type_library(&self, path: &Path) -> Result<ProcessedData, ProcessingError> {
self.state.set_file_state(path.to_owned(), false);
- let finalized_type_library = TypeLibrary::load_from_file(&path)
+ let finalized_type_library = TypeLibrary::load_from_file(path)
.ok_or_else(|| ProcessingError::InvalidTypeLibrary(path.to_owned()))?;
self.state.set_file_state(path.to_owned(), true);
Ok(ProcessedData::new(vec![finalized_type_library]))
@@ -957,8 +956,7 @@ impl TypeLibProcessor {
CoreTypeParser::parser_by_name("ClangTypeParser").expect("Failed to get clang parser");
let platform_type_container = platform.type_container();
- let header_contents =
- std::fs::read_to_string(path).map_err(|e| ProcessingError::FileRead(e))?;
+ let header_contents = std::fs::read_to_string(path).map_err(ProcessingError::FileRead)?;
let file_name = path
.file_name()
@@ -982,7 +980,7 @@ impl TypeLibProcessor {
&include_dirs,
"",
)
- .map_err(|e| ProcessingError::TypeParsingFailed(e))?;
+ .map_err(ProcessingError::TypeParsingFailed)?;
let type_library = TypeLibrary::new(platform.arch(), &self.default_dependency_name);
type_library.add_platform(&platform);
@@ -1000,7 +998,7 @@ impl TypeLibProcessor {
/// most important for us is the list of exported symbols, which we can use to relocate objects
/// in the default type library (specified by `default_dependency_name`) to the correct type library.
pub fn process_tbd(&self, path: &Path) -> Result<ProcessedData, ProcessingError> {
- let mut file = File::open(path).map_err(|e| ProcessingError::FileRead(e))?;
+ let mut file = File::open(path).map_err(ProcessingError::FileRead)?;
let mut type_libraries = Vec::new();
for tbd_info in parse_tbd_info(&mut file).unwrap() {
let install_path = PathBuf::from(tbd_info.install_name);
@@ -1066,7 +1064,7 @@ impl TypeLibProcessor {
}
let platform = self.default_platform()?;
let type_libraries = WindowsMetadataImporter::new()
- .with_files(&paths)
+ .with_files(paths)
.map_err(ProcessingError::WinMdFailedImport)?
.import(&platform)
.map_err(ProcessingError::WinMdFailedImport)?;
@@ -1090,8 +1088,8 @@ pub fn is_parsable(path: &Path) -> bool {
if path.extension() == Some(OsStr::new("pdb")) {
return false;
}
- let mut metadata = FileMetadata::with_file_path(&path);
- let Ok(view) = BinaryView::from_path(&mut metadata, path) else {
+ let mut metadata = FileMetadata::with_file_path(path);
+ let Ok(view) = BinaryView::from_path(&metadata, path) else {
return false;
};
// If any view type parses this file, consider it for this source.
diff --git a/plugins/bntl_utils/src/tbd.rs b/plugins/bntl_utils/src/tbd.rs
index 51222766..9075a8dc 100644
--- a/plugins/bntl_utils/src/tbd.rs
+++ b/plugins/bntl_utils/src/tbd.rs
@@ -8,7 +8,8 @@ use std::str::FromStr;
pub fn parse_tbd_info(data: &mut impl Read) -> Result<Vec<TbdInfo>, serde_saphyr::Error> {
let mut documents = Vec::new();
for file in serde_saphyr::read::<_, TbdFile>(data) {
- if let Some(info) = TbdInfo::try_from(file?).ok() {
+ // TODO: Float errors to caller
+ if let Ok(info) = TbdInfo::try_from(file?) {
documents.push(info);
}
}
@@ -301,8 +302,8 @@ impl TbdTarget {
.iter()
.map(|a| {
Ok(TbdTarget {
- arch: a.clone(),
- platform: platform.clone(),
+ arch: *a,
+ platform: *platform,
})
})
.collect()
diff --git a/plugins/bntl_utils/src/url.rs b/plugins/bntl_utils/src/url.rs
index 16fe75d2..3d8d8ee3 100644
--- a/plugins/bntl_utils/src/url.rs
+++ b/plugins/bntl_utils/src/url.rs
@@ -202,7 +202,7 @@ impl BnParsedUrl {
.get_file_by_id(&item_guid_str)
.ok()
.flatten()
- .ok_or_else(|| BnResourceError::ItemNotFound(item_guid_str))?;
+ .ok_or(BnResourceError::ItemNotFound(item_guid_str))?;
Ok(BnResource::RemoteProjectFile(file))
}
diff --git a/plugins/bntl_utils/src/winmd.rs b/plugins/bntl_utils/src/winmd.rs
index 1cf99ab2..2937a163 100644
--- a/plugins/bntl_utils/src/winmd.rs
+++ b/plugins/bntl_utils/src/winmd.rs
@@ -70,6 +70,7 @@ impl WindowsMetadataImporter {
Ok(self)
}
+ #[allow(dead_code)]
pub fn with_platform(mut self, platform: &Platform) -> Self {
// TODO: platform.address_size()
self.address_size = platform.arch().address_size();
@@ -115,10 +116,10 @@ impl WindowsMetadataImporter {
til.add_platform(platform);
til.set_dependency_name(&type_lib_name);
for ty in &info.metadata.types {
- self.import_type(&til, &ty)?;
+ self.import_type(&til, ty)?;
}
for func in &info.metadata.functions {
- self.import_function(&til, &func)?;
+ self.import_function(&til, func)?;
}
for (name, library_name) in &info.external_references {
let qualified_name = QualifiedName::from(name.clone());
@@ -314,9 +315,7 @@ impl WindowsMetadataImporter {
union.structure_type(StructureType::UnionStructureType);
let mut max_alignment = 0usize;
- // We need to look ahead to figure out when bitfields end and adjust current_byte_offset accordingly.
- let mut field_iter = fields.iter().peekable();
- while let Some(field) = field_iter.next() {
+ for field in fields {
let field_ty = self.convert_type_kind(&field.ty)?;
let field_alignment = self.type_kind_alignment(&field.ty)?;
max_alignment = max_alignment.max(field_alignment);
diff --git a/plugins/bntl_utils/src/winmd/translate.rs b/plugins/bntl_utils/src/winmd/translate.rs
index 01ea54a5..17750354 100644
--- a/plugins/bntl_utils/src/winmd/translate.rs
+++ b/plugins/bntl_utils/src/winmd/translate.rs
@@ -283,7 +283,7 @@ impl WindowsMetadataTranslator {
let nested: Result<HashMap<String, _>, _> = structure
.index()
- .nested(structure.clone())
+ .nested(*structure)
.map(|n| {
// TODO: Are all nested fields a struct?
let nested_ty = self.translate_struct(&n)?;
@@ -372,11 +372,7 @@ impl WindowsMetadataTranslator {
let mut constants = Vec::new();
for field in class.fields() {
- if let Some(constant) = field
- .constant()
- .map(|c| self.value_to_u64(&c.value()))
- .flatten()
- {
+ if let Some(constant) = field.constant().and_then(|c| self.value_to_u64(&c.value())) {
constants.push(MetadataConstantInfo {
name: field.name().to_string(),
namespace: namespace.clone(),
@@ -525,8 +521,7 @@ impl WindowsMetadataTranslator {
}
let variant_constant = variant
.constant()
- .map(|c| self.value_to_u64(&c.value()))
- .flatten()
+ .and_then(|c| self.value_to_u64(&c.value()))
.unwrap_or(last_constant);
let variant_name = variant.name().to_string();
variants.push((variant_name, variant_constant));