Skip to content

Misc WARP fixes for 5.1 stable #7142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions plugins/warp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub fn filtered_instructions_at<M: FunctionMutability>(
LowLevelILInstructionKind::NoRet(_) | LowLevelILInstructionKind::Ret(_) => false,
// Stop collecting instruction if we are probably the end function jump in lifted IL. This
// is emitted at the end of the function and will mess with our GUID.
LowLevelILInstructionKind::Jump(_) => *i != 0,
LowLevelILInstructionKind::Jump(_) => *i == 0,
_ => true,
})
.map(|(_, instr)| instr)
Expand Down Expand Up @@ -400,30 +400,29 @@ pub fn is_address_relocatable(relocatable_regions: &[Range<u64>], address: u64)
// TODO: This might need to be configurable, in that case we better remove this function.
/// Get the relocatable regions of the view.
///
/// Currently, this is all the sections, however, this might be refined later.
/// Currently, segments are used by default, however, if the only segment is based at 0, then we fall
/// back to using sections.
pub fn relocatable_regions(view: &BinaryView) -> Vec<Range<u64>> {
// NOTE: We cannot use segments here as there will be a zero-based segment.
let mut ranges: Vec<_> = view
.sections()
// NOTE: We used to use sections because the image base for some object files would start
// at zero, masking non-relocatable instructions, since then we have started adjusting the
// image base to 0x10000 or higher so we can use segments directly, which improves the accuracy
// of function GUIDs for binaries which have no or bad section definitions, common of firmware.
let mut ranges = view
.segments()
.iter()
.map(|s| Range {
start: s.start(),
end: s.end(),
})
.collect();
.filter(|s| s.address_range().start != 0)
.map(|s| s.address_range())
.collect::<Vec<_>>();

// 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()
if ranges.is_empty() {
// Realistically only happens if the only defined segment was based at 0, in which case
// we hope the user has set up correct sections. If not we are going to be masking off too many
// or too little instructions.
ranges = view
.sections()
.iter()
.map(|s| s.address_range())
.collect::<Vec<_>>();
ranges.extend(segment_ranges);
}

ranges
Expand Down
9 changes: 9 additions & 0 deletions plugins/warp/src/plugin/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ pub fn run_matcher(view: &BinaryView) {
})
.into_group_map();

if functions_by_target_and_guid.is_empty() && !view.functions().is_empty() {
// The user is likely trying to run the matcher on a database before guids were automatically
// generated, we should alert them and ask if they would like to reanalyze.
// TODO: Call reanalyze for them?
log::error!("Trying to match with an older database, please reanalyze the database.");
background_task.finish();
return;
}

// TODO: Par iter this? Using dashmap
let guids_by_target: HashMap<Target, Vec<FunctionGUID>> = functions_by_target_and_guid
.keys()
Expand Down
8 changes: 8 additions & 0 deletions plugins/warp/ui/matched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ void WarpMatchedWidget::Update()
{
m_tableWidget->GetTableView()->setSortingEnabled(false);
m_tableWidget->GetTableView()->setEnabled(false);
m_tableWidget->GetProxyModel()->setDynamicSortFilter(false);
m_tableWidget->GetTableView()->setUpdatesEnabled(false);
m_tableWidget->GetTableView()->setModel(nullptr);
m_tableWidget->GetProxyModel()->setSourceModel(nullptr);
for (const auto &analysisFunction: m_current->GetAnalysisFunctionList())
{
if (const auto &matchedFunction = Warp::Function::GetMatched(*analysisFunction))
Expand All @@ -78,6 +82,10 @@ void WarpMatchedWidget::Update()
m_tableWidget->InsertFunction(startAddress, new WarpFunctionItem(matchedFunction, analysisFunction));
}
}
m_tableWidget->GetTableView()->setModel(m_tableWidget->GetProxyModel());
m_tableWidget->GetProxyModel()->setSourceModel(m_tableWidget->GetModel());
m_tableWidget->GetProxyModel()->setDynamicSortFilter(true);
m_tableWidget->GetTableView()->setEnabled(true);
m_tableWidget->GetTableView()->setSortingEnabled(true);
m_tableWidget->GetTableView()->setUpdatesEnabled(true);
}
3 changes: 1 addition & 2 deletions plugins/warp/ui/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ void WarpSidebarWidget::focus()
void WarpSidebarWidget::Update()
{
m_matchedWidget->Update();
if (!GetMatcherTask())
setMatcherActionIcon(false);
setMatcherActionIcon(false);
}

void WarpSidebarWidget::setMatcherActionIcon(bool running)
Expand Down
Loading