Skip to content

Commit 1d81c72

Browse files
committed
Fix Rust LowLevelILFunction owner function method
LowLevelILFunction objects can be constructed without a owner function. BNGetLowLevelILOwnerFunction can return NULL and must be checked before creating a Function object.
1 parent a5ffff2 commit 1d81c72

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

plugins/warp/src/plugin/ffi.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ pub unsafe extern "C" fn BNWARPIsLiftedInstructionVariant(
142142
unsafe { LowLevelILFunction::from_raw(analysis_function) };
143143
match lifted_il.instruction_from_index(index) {
144144
Some(instr) => {
145-
let relocatable_regions = relocatable_regions(&lifted_il.function().view());
145+
let Some(owner_function) = lifted_il.function() else {
146+
return false;
147+
};
148+
let relocatable_regions = relocatable_regions(&owner_function.view());
146149
is_variant_instruction(&relocatable_regions, &instr)
147150
}
148151
None => false,
@@ -158,7 +161,10 @@ pub unsafe extern "C" fn BNWARPIsLowLevelInstructionComputedVariant(
158161
unsafe { LowLevelILFunction::from_raw(analysis_function) };
159162
match llil.instruction_from_index(index) {
160163
Some(instr) => {
161-
let relocatable_regions = relocatable_regions(&llil.function().view());
164+
let Some(owner_function) = llil.function() else {
165+
return false;
166+
};
167+
let relocatable_regions = relocatable_regions(&owner_function.view());
162168
is_computed_variant_instruction(&relocatable_regions, &instr)
163169
}
164170
None => false,

plugins/warp/src/plugin/render_layer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ impl HighlightRenderLayer {
4848
llil: &LowLevelILRegularFunction,
4949
lines: &mut [DisassemblyTextLine],
5050
) {
51-
let relocatable_regions = relocatable_regions(&lifted_il.function().view());
51+
let Some(owner_function) = lifted_il.function() else {
52+
return;
53+
};
54+
55+
let relocatable_regions = relocatable_regions(&owner_function.view());
5256
for line in lines {
5357
// We use address here instead of index since it's more reliable for other IL's.
5458
for lifted_il_instr in filtered_instructions_at(lifted_il, line.address) {

rust/src/low_level_il/function.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ where
8888
}
8989

9090
pub(crate) fn arch(&self) -> CoreArchitecture {
91+
// TODO: self.function() can return None under rare circumstances
9192
match self.arch {
92-
None => self.function().arch(),
93+
None => self.function().unwrap().arch(),
9394
Some(arch) => arch,
9495
}
9596
}
@@ -167,10 +168,13 @@ where
167168
}
168169
}
169170

170-
pub fn function(&self) -> Ref<Function> {
171+
pub fn function(&self) -> Option<Ref<Function>> {
171172
unsafe {
172173
let func = BNGetLowLevelILOwnerFunction(self.handle);
173-
Function::ref_from_raw(func)
174+
if func.is_null() {
175+
return None;
176+
}
177+
Some(Function::ref_from_raw(func))
174178
}
175179
}
176180

0 commit comments

Comments
 (0)