diff options
| author | Mason Reed <mason@vector35.com> | 2025-10-07 14:32:48 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-10-07 14:33:34 -0400 |
| commit | 4a227e0523391bc026bf96c3c31d44a39cac1701 (patch) | |
| tree | cc603b899a446fb469a0be3ae4c2c77e6351c091 /plugins/warp/ui/shared/fetcher.cpp | |
| parent | 3e24f6ab0b373d8718e26a19ac296044cc0d19c6 (diff) | |
[WARP] Format UI plugin
Diffstat (limited to 'plugins/warp/ui/shared/fetcher.cpp')
| -rw-r--r-- | plugins/warp/ui/shared/fetcher.cpp | 115 |
1 files changed, 58 insertions, 57 deletions
diff --git a/plugins/warp/ui/shared/fetcher.cpp b/plugins/warp/ui/shared/fetcher.cpp index 299050a5..1a262878 100644 --- a/plugins/warp/ui/shared/fetcher.cpp +++ b/plugins/warp/ui/shared/fetcher.cpp @@ -2,89 +2,90 @@ WarpFetcher::WarpFetcher() { - m_logger = new BinaryNinja::Logger("WARP Fetcher"); + m_logger = new BinaryNinja::Logger("WARP Fetcher"); } -void WarpFetcher::AddPendingFunction(const FunctionRef &func) +void WarpFetcher::AddPendingFunction(const FunctionRef& func) { - std::lock_guard<std::mutex> lock(m_requestMutex); - const auto guid = Warp::GetAnalysisFunctionGUID(*func); - if (!guid.has_value() || m_processedGuids.contains(*guid)) - return; - m_pendingRequests.push_back(func); + std::lock_guard<std::mutex> lock(m_requestMutex); + const auto guid = Warp::GetAnalysisFunctionGUID(*func); + if (!guid.has_value() || m_processedGuids.contains(*guid)) + return; + m_pendingRequests.push_back(func); } std::vector<FunctionRef> WarpFetcher::FlushPendingFunctions() { - std::lock_guard<std::mutex> lock(m_requestMutex); - std::vector<FunctionRef> requests = std::move(m_pendingRequests); - m_pendingRequests.clear(); - return requests; + std::lock_guard<std::mutex> lock(m_requestMutex); + std::vector<FunctionRef> requests = std::move(m_pendingRequests); + m_pendingRequests.clear(); + return requests; } void WarpFetcher::ExecuteCompletionCallback() { - BinaryNinja::ExecuteOnMainThread([this]() { - // TODO: Holding the mutex here is dangerous! - std::lock_guard<std::mutex> lock(m_requestMutex); - m_completionCallbacks.erase( - std::ranges::remove_if(m_completionCallbacks, - [](const auto &cb) { return cb() == RemoveCallback; }).begin(), - m_completionCallbacks.end()); - }); + BinaryNinja::ExecuteOnMainThread([this]() { + // TODO: Holding the mutex here is dangerous! + std::lock_guard<std::mutex> lock(m_requestMutex); + m_completionCallbacks.erase( + std::ranges::remove_if(m_completionCallbacks, [](const auto& cb) { return cb() == RemoveCallback; }) + .begin(), + m_completionCallbacks.end()); + }); } std::shared_ptr<WarpFetcher> WarpFetcher::Global() { - static auto global = std::make_shared<WarpFetcher>(); - return global; + static auto global = std::make_shared<WarpFetcher>(); + return global; } void WarpFetcher::FetchPendingFunctions(const std::vector<Warp::SourceTag>& allowedTags) { - m_requestInProgress = true; - const auto requests = FlushPendingFunctions(); - if (requests.empty()) - { - m_logger->LogDebug("No pending requests to fetch... skipping"); - m_requestInProgress = false; - return; - } + m_requestInProgress = true; + const auto requests = FlushPendingFunctions(); + if (requests.empty()) + { + m_logger->LogDebug("No pending requests to fetch... skipping"); + m_requestInProgress = false; + return; + } - const auto start_time = std::chrono::high_resolution_clock::now(); + const auto start_time = std::chrono::high_resolution_clock::now(); - // Because we must fetch for a single target we map the function guids to the associated platform to perform fetches for each. - std::map<PlatformRef, std::vector<Warp::FunctionGUID>> platformMappedGuids; - for (const auto &func: requests) - { - const auto guid = Warp::GetAnalysisFunctionGUID(*func); - if (!guid.has_value()) - continue; - auto platform = func->GetPlatform(); - platformMappedGuids[platform].push_back(guid.value()); - } + // Because we must fetch for a single target we map the function guids to the associated platform to perform fetches + // for each. + std::map<PlatformRef, std::vector<Warp::FunctionGUID>> platformMappedGuids; + for (const auto& func : requests) + { + const auto guid = Warp::GetAnalysisFunctionGUID(*func); + if (!guid.has_value()) + continue; + auto platform = func->GetPlatform(); + platformMappedGuids[platform].push_back(guid.value()); + } - for (const auto &[platform, guids] : platformMappedGuids) - { - m_logger->LogDebugF("Fetching {} functions for platform {}", guids.size(), platform->GetName()); - auto target = Warp::Target::FromPlatform(*platform); - for (const auto &container: Warp::Container::All()) - container->FetchFunctions(*target, guids, allowedTags); + for (const auto& [platform, guids] : platformMappedGuids) + { + m_logger->LogDebugF("Fetching {} functions for platform {}", guids.size(), platform->GetName()); + auto target = Warp::Target::FromPlatform(*platform); + for (const auto& container : Warp::Container::All()) + container->FetchFunctions(*target, guids, allowedTags); - std::lock_guard<std::mutex> lock(m_requestMutex); - for (const auto &guid: guids) - m_processedGuids.insert(guid); - } + std::lock_guard<std::mutex> lock(m_requestMutex); + for (const auto& guid : guids) + m_processedGuids.insert(guid); + } - m_requestInProgress = false; - ExecuteCompletionCallback(); - const auto end_time = std::chrono::high_resolution_clock::now(); - const std::chrono::duration<double> elapsed_time = end_time - start_time; - m_logger->LogDebug("Fetch batch took %f seconds", elapsed_time.count()); + m_requestInProgress = false; + ExecuteCompletionCallback(); + const auto end_time = std::chrono::high_resolution_clock::now(); + const std::chrono::duration<double> elapsed_time = end_time - start_time; + m_logger->LogDebug("Fetch batch took %f seconds", elapsed_time.count()); } void WarpFetcher::ClearProcessed() { - m_logger->LogInfoF("Clearing {} processed functions from cache...", m_processedGuids.size()); - m_processedGuids.clear(); + m_logger->LogInfoF("Clearing {} processed functions from cache...", m_processedGuids.size()); + m_processedGuids.clear(); } |
