Skip to content

Commit d6c0988

Browse files
committed
[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.
1 parent 4a49ba5 commit d6c0988

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

plugins/warp/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,28 @@ pub fn is_address_relocatable(relocatable_regions: &[Range<u64>], address: u64)
393393
/// Currently, this is all the sections, however, this might be refined later.
394394
pub fn relocatable_regions(view: &BinaryView) -> Vec<Range<u64>> {
395395
// NOTE: We cannot use segments here as there will be a zero-based segment.
396-
view.sections()
396+
let mut ranges: Vec<_> = view
397+
.sections()
397398
.iter()
398399
.map(|s| Range {
399400
start: s.start(),
400401
end: s.end(),
401402
})
402-
.collect()
403+
.collect();
404+
405+
// If the only section available is the synthetic one, fallback to using the segments.
406+
// NOTE: This should only happen for firmware, and it should be _fine_ considering that we
407+
// do not use segments for the case where we are based at some zero offset. The user should have
408+
// based the image somewhere reasonably.
409+
// TODO: Restrict this to only when image base is above some value?
410+
if ranges.len() <= 1 {
411+
let segment_ranges = view
412+
.segments()
413+
.iter()
414+
.map(|s| s.address_range())
415+
.collect::<Vec<_>>();
416+
ranges.extend(segment_ranges);
417+
}
418+
419+
ranges
403420
}

0 commit comments

Comments
 (0)