summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-07-16 14:41:31 -0400
committerMason Reed <mason@vector35.com>2025-07-17 06:20:20 -0400
commit2f947fd6971e284ebc0f38219c1687afa15d73b0 (patch)
tree3326fda2f5d2105fa53609e51705b1a30bed824f
parent302b3295e6db60c1ee5a076d8f57ebfd5e1eb30a (diff)
[WARP] Construct a minimal version of the function object when user only wants the symbol
We were previously constructing the function type, comments and variables to just throw away, wasting precious cpu cycles!
-rw-r--r--plugins/warp/benches/function.rs4
-rw-r--r--plugins/warp/src/lib.rs46
-rw-r--r--plugins/warp/src/plugin/debug.rs2
-rw-r--r--plugins/warp/src/plugin/ffi/function.rs2
-rw-r--r--plugins/warp/src/processor.rs10
5 files changed, 37 insertions, 27 deletions
diff --git a/plugins/warp/benches/function.rs b/plugins/warp/benches/function.rs
index dc5016be..526d97c4 100644
--- a/plugins/warp/benches/function.rs
+++ b/plugins/warp/benches/function.rs
@@ -21,7 +21,7 @@ pub fn function_benchmark(c: &mut Criterion) {
c.bench_function("signature all functions", |b| {
b.iter(|| {
for func in &functions {
- let _ = build_function(&func, &func.lifted_il().unwrap());
+ let _ = build_function(&func, &func.lifted_il().unwrap(), false);
}
})
});
@@ -33,7 +33,7 @@ pub fn function_benchmark(c: &mut Criterion) {
.par_iter()
.filter_map(|func| {
let llil = func.lifted_il().ok()?;
- Some(build_function(func.as_ref(), llil.as_ref()))
+ Some(build_function(func.as_ref(), llil.as_ref(), false))
})
.collect::<Vec<_>>()
})
diff --git a/plugins/warp/src/lib.rs b/plugins/warp/src/lib.rs
index dd94ada0..bea85cdd 100644
--- a/plugins/warp/src/lib.rs
+++ b/plugins/warp/src/lib.rs
@@ -105,34 +105,44 @@ pub fn build_variables(func: &BNFunction) -> Vec<FunctionVariable> {
variables
}
+// TODO: Get rid of the minimal bool.
pub fn build_function<M: FunctionMutability>(
func: &BNFunction,
lifted_il: &LowLevelILFunction<M, NonSSA>,
+ minimal: bool,
) -> Function {
- let comments = func
- .comments()
- .iter()
- .map(|c| bn_comment_to_comment(func, c))
- .collect();
- Function {
+ let mut function = Function {
guid: cached_function_guid(func, lifted_il),
symbol: from_bn_symbol(&func.symbol()),
- // Currently we only store the type if its a user type.
- // TODO: In the future we might want to make this configurable.
- ty: match func.has_user_type() || func.has_explicitly_defined_type() {
- true => Some(from_bn_type(
- &func.view(),
- &func.function_type(),
- MAX_CONFIDENCE,
- )),
- false => None,
- },
// NOTE: Adding adjacent only works if analysis is complete.
// NOTE: We do not filter out adjacent functions here.
constraints: cached_constraints(func, |_| true),
- comments,
- variables: build_variables(func),
+ ty: None,
+ comments: vec![],
+ variables: vec![],
+ };
+
+ if minimal {
+ return function;
}
+
+ // Currently we only store the type if its a user type.
+ // TODO: In the future we might want to make this configurable.
+ function.ty = match func.has_user_type() || func.has_explicitly_defined_type() {
+ true => Some(from_bn_type(
+ &func.view(),
+ &func.function_type(),
+ MAX_CONFIDENCE,
+ )),
+ false => None,
+ };
+ function.comments = func
+ .comments()
+ .iter()
+ .map(|c| bn_comment_to_comment(func, c))
+ .collect();
+ function.variables = build_variables(func);
+ function
}
/// Basic blocks sorted from high to low.
diff --git a/plugins/warp/src/plugin/debug.rs b/plugins/warp/src/plugin/debug.rs
index fc4e5817..24cdf1c3 100644
--- a/plugins/warp/src/plugin/debug.rs
+++ b/plugins/warp/src/plugin/debug.rs
@@ -10,7 +10,7 @@ pub struct DebugFunction;
impl FunctionCommand for DebugFunction {
fn action(&self, _view: &BinaryView, func: &Function) {
if let Ok(lifted_il) = func.lifted_il() {
- log::info!("{:#?}", build_function(func, &lifted_il));
+ log::info!("{:#?}", build_function(func, &lifted_il, false));
}
}
diff --git a/plugins/warp/src/plugin/ffi/function.rs b/plugins/warp/src/plugin/ffi/function.rs
index 3db8f307..a7ec6593 100644
--- a/plugins/warp/src/plugin/ffi/function.rs
+++ b/plugins/warp/src/plugin/ffi/function.rs
@@ -40,7 +40,7 @@ pub unsafe extern "C" fn BNWARPGetFunction(
let Ok(lifted_il) = function.lifted_il() else {
return std::ptr::null_mut();
};
- let function = build_function(&function, &lifted_il);
+ let function = build_function(&function, &lifted_il, false);
Arc::into_raw(Arc::new(function)) as *mut BNWARPFunction
}
diff --git a/plugins/warp/src/processor.rs b/plugins/warp/src/processor.rs
index d3ccb300..75e8569e 100644
--- a/plugins/warp/src/processor.rs
+++ b/plugins/warp/src/processor.rs
@@ -816,11 +816,11 @@ impl WarpFileProcessor {
.filter_map(|func| {
let lifted_il = func.lifted_il().ok()?;
let target = platform_to_target(&func.platform());
- let mut built_function = build_function(&func, &lifted_il);
- // User asked to only save symbols, so we will remove the function type.
- if self.file_data == FileDataKindField::Symbols {
- built_function.ty = None;
- }
+ let built_function = build_function(
+ &func,
+ &lifted_il,
+ self.file_data == FileDataKindField::Symbols,
+ );
Some((target, built_function))
})
.fold(