| 20 | |
| 21 | |
| 22 | void UINotifications::OnViewChange(UIContext* context, ViewFrame* frame, const QString& type) |
| 23 | { |
| 24 | if (!frame) |
| 25 | return; |
| 26 | |
| 27 | // FIXME there is a bv func for this |
| 28 | static std::function<bool(Ref<BinaryView>, uint64_t)> isAddrMapped = [](Ref<BinaryView> view, uint64_t addr) { |
| 29 | if (view && view->GetTypeName() == KC_VIEW_NAME) |
| 30 | { |
| 31 | for (const auto& seg : view->GetSegments()) |
| 32 | { |
| 33 | if (seg->GetStart() <= addr && seg->GetEnd() > addr) |
| 34 | return true; |
| 35 | } |
| 36 | } |
| 37 | return false; |
| 38 | }; |
| 39 | |
| 40 | auto view = frame->getCurrentBinaryView(); |
| 41 | if (view && view->GetTypeName() == KC_VIEW_NAME) |
| 42 | { |
| 43 | if (auto viewInt = frame->getCurrentViewInterface()) |
| 44 | { |
| 45 | auto ah = viewInt->actionHandler(); |
| 46 | if (!ah->isBoundAction("KC Load IMGHERE")) |
| 47 | { |
| 48 | ah->bindAction("KC Load IMGHERE", |
| 49 | UIAction( |
| 50 | [](const UIActionContext& ctx) { |
| 51 | Ref<BinaryView> view = ctx.binaryView; |
| 52 | Ref<KernelCacheAPI::KernelCache> cache = new KernelCacheAPI::KernelCache(view); |
| 53 | uint64_t addr = ctx.token.token.value; |
| 54 | if (addr) |
| 55 | { |
| 56 | BackgroundThread::create(ctx.context->mainWindow())->thenBackground( |
| 57 | [cache=cache, addr=addr]() { |
| 58 | cache->LoadImageContainingAddress(addr); |
| 59 | })->start(); |
| 60 | } |
| 61 | }, |
| 62 | [](const UIActionContext& ctx) { |
| 63 | Ref<KernelCacheAPI::KernelCache> cache = new KernelCacheAPI::KernelCache(ctx.binaryView); |
| 64 | uint64_t addr = ctx.token.token.value; |
| 65 | if (isAddrMapped(ctx.binaryView, addr)) |
| 66 | return false; |
| 67 | return addr && cache->GetImageNameForAddress(addr) != ""; // bool |
| 68 | })); |
| 69 | ah->setActionDisplayName("KC Load IMGHERE", [](const UIActionContext& ctx) { |
| 70 | Ref<KernelCacheAPI::KernelCache> cache = new KernelCacheAPI::KernelCache(ctx.binaryView); |
| 71 | uint64_t addr = ctx.token.token.value; |
| 72 | if (addr) |
| 73 | return QString("Load ") + cache->GetImageNameForAddress(addr).c_str(); |
| 74 | return QString("Error"); |
| 75 | }); |
| 76 | if (auto linearView = qobject_cast<LinearView*>(viewInt->widget())) |
| 77 | { |
| 78 | linearView->contextMenu().addAction("KC Load IMGHERE", KC_VIEW_NAME); |
| 79 | linearView->contextMenu().setGroupOrdering(KC_VIEW_NAME, 0); |
nothing calls this directly
no test coverage detected