From d6c098813fde016e225c4ee072f38cd69d9783f0 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 15 Jul 2025 06:11:11 -0400 Subject: [WARP] Fallback to using segment information for relocatable ranges This previously was not allowed as the information would sometimes include a zero based segment, however this is still preferable in the case of firmware, where sections will not be available by default. This improves the usability of WARP with firmware by removing the requirement of filling section information prior to function analysis. --- plugins/warp/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/warp/src/lib.rs b/plugins/warp/src/lib.rs index 39f39e1c..dd94ada0 100644 --- a/plugins/warp/src/lib.rs +++ b/plugins/warp/src/lib.rs @@ -393,11 +393,28 @@ pub fn is_address_relocatable(relocatable_regions: &[Range], address: u64) /// Currently, this is all the sections, however, this might be refined later. pub fn relocatable_regions(view: &BinaryView) -> Vec> { // NOTE: We cannot use segments here as there will be a zero-based segment. - view.sections() + let mut ranges: Vec<_> = view + .sections() .iter() .map(|s| Range { start: s.start(), end: s.end(), }) - .collect() + .collect(); + + // If the only section available is the synthetic one, fallback to using the segments. + // NOTE: This should only happen for firmware, and it should be _fine_ considering that we + // do not use segments for the case where we are based at some zero offset. The user should have + // based the image somewhere reasonably. + // TODO: Restrict this to only when image base is above some value? + if ranges.len() <= 1 { + let segment_ranges = view + .segments() + .iter() + .map(|s| s.address_range()) + .collect::>(); + ranges.extend(segment_ranges); + } + + ranges } -- cgit v1.3.1