MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / DisplayDSCPicker

Function DisplayDSCPicker

view/sharedcache/ui/dscpicker.cpp:12–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace SharedCacheAPI;
11
12void DisplayDSCPicker(UIContext* ctx, Ref<BinaryView> dscView)
13{
14 auto getImageNames = [dscView](QVariant var) {
15 auto controller = SharedCacheController::GetController(*dscView);
16 if (!controller)
17 return QStringList();
18
19 QStringList entries = {};
20 for (const auto& img : controller->GetImages())
21 entries.push_back(QString::fromStdString(img.name));
22 return entries;
23 };
24
25 auto getChosenImage = [ctx](QVariant var) {
26 QStringList entries = var.toStringList();
27
28 auto choiceDialog = new MetadataChoiceDialog(ctx ? ctx->mainWindow() : nullptr, "Pick Image", "Select", entries);
29 choiceDialog->AddWidthRequiredByItem(ctx, 300);
30 choiceDialog->AddHeightRequiredByItem(ctx, 150);
31 choiceDialog->exec();
32
33 if (!choiceDialog->GetChosenEntry().has_value())
34 return QVariant("");
35
36 return QVariant(QString::fromStdString(entries.at((qsizetype)choiceDialog->GetChosenEntry().value().idx).toStdString()));
37 };
38
39 auto loadSelectedImage = [dscView](QVariant var) {
40 auto selectedImageName = var.toString().toStdString();
41 if (selectedImageName.empty())
42 return;
43
44 if (auto controller = SharedCacheController::GetController(*dscView))
45 {
46 if (const auto selectedImage = controller->GetImageWithName( selectedImageName))
47 {
48 controller->ApplyImage(*dscView, *selectedImage);
49 dscView->AddAnalysisOption("linearsweep");
50 dscView->UpdateAnalysis();
51 }
52 }
53 };
54
55
56 BackgroundThread::create(ctx ? ctx->mainWindow() : nullptr)
57 ->thenBackground([getImageNames](QVariant var){ return getImageNames(var); })
58 ->thenMainThread([getChosenImage](QVariant var){ return getChosenImage(var); })
59 ->thenBackground([loadSelectedImage](QVariant var){ return loadSelectedImage(var); })
60 ->start();
61}

Callers 1

OnViewChangeMethod · 0.85

Calls 9

push_backMethod · 0.80
AddAnalysisOptionMethod · 0.80
UpdateAnalysisMethod · 0.80
GetImagesMethod · 0.45
valueMethod · 0.45
emptyMethod · 0.45
GetImageWithNameMethod · 0.45
ApplyImageMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected