|
| 1 | +/* |
| 2 | +Copyright 2020-2022 Vector 35 Inc. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#include "remoteprocess.h" |
| 18 | + |
| 19 | +using namespace BinaryNinjaDebuggerAPI; |
| 20 | +using namespace BinaryNinja; |
| 21 | +using namespace std; |
| 22 | + |
| 23 | +RemoteProcessSettingsDialog::RemoteProcessSettingsDialog(QWidget* parent, DebuggerController* controller): QDialog() |
| 24 | +{ |
| 25 | + setWindowTitle("Remote Process Settings"); |
| 26 | + setMinimumSize(UIContext::getScaledWindowSize(400, 130)); |
| 27 | + setAttribute(Qt::WA_DeleteOnClose); |
| 28 | + |
| 29 | + m_controller = controller; |
| 30 | + |
| 31 | + setModal(true); |
| 32 | + QVBoxLayout* layout = new QVBoxLayout; |
| 33 | + layout->setSpacing(0); |
| 34 | + |
| 35 | + QHBoxLayout* titleLayout = new QHBoxLayout; |
| 36 | + titleLayout->setContentsMargins(0, 0, 0, 0); |
| 37 | + |
| 38 | + m_pluginEntry = new QComboBox(this); |
| 39 | + auto pluginsMetadata = m_controller->GetAdapterProperty("process_plugins"); |
| 40 | + if (pluginsMetadata->IsStringList()) |
| 41 | + { |
| 42 | + auto plugins = pluginsMetadata->GetStringList(); |
| 43 | + for (const auto& plugin: plugins) |
| 44 | + m_pluginEntry->addItem(QString::fromStdString(plugin)); |
| 45 | + } |
| 46 | + |
| 47 | + auto currentPluginMetadata = m_controller->GetAdapterProperty("current_process_plugin"); |
| 48 | + if (currentPluginMetadata && currentPluginMetadata->IsString()) |
| 49 | + { |
| 50 | + const auto currentPlugin = currentPluginMetadata->GetString(); |
| 51 | + m_pluginEntry->setCurrentText(QString::fromStdString(currentPlugin)); |
| 52 | + } |
| 53 | + |
| 54 | + m_addressEntry = new QLineEdit(this); |
| 55 | + m_portEntry = new QLineEdit(this); |
| 56 | + |
| 57 | + QFormLayout* formLayout = new QFormLayout; |
| 58 | + formLayout->addRow("Plugin", m_pluginEntry); |
| 59 | + formLayout->addRow("Host", m_addressEntry); |
| 60 | + formLayout->addRow("Port", m_portEntry); |
| 61 | + |
| 62 | + QHBoxLayout* buttonLayout = new QHBoxLayout; |
| 63 | + buttonLayout->setContentsMargins(0, 0, 0, 0); |
| 64 | + |
| 65 | + QPushButton* cancelButton = new QPushButton("Cancel"); |
| 66 | + connect(cancelButton, &QPushButton::clicked, [&](){ reject(); }); |
| 67 | + QPushButton* acceptButton = new QPushButton("Accept"); |
| 68 | + connect(acceptButton, &QPushButton::clicked, [&](){ apply(); }); |
| 69 | + acceptButton->setDefault(true); |
| 70 | + |
| 71 | + buttonLayout->addStretch(1); |
| 72 | + buttonLayout->addWidget(cancelButton); |
| 73 | + buttonLayout->addWidget(acceptButton); |
| 74 | + |
| 75 | + layout->addLayout(titleLayout); |
| 76 | + layout->addSpacing(10); |
| 77 | + layout->addLayout(formLayout); |
| 78 | + layout->addStretch(1); |
| 79 | + layout->addSpacing(10); |
| 80 | + layout->addLayout(buttonLayout); |
| 81 | + setLayout(layout); |
| 82 | + |
| 83 | + m_addressEntry->setText(QString::fromStdString(m_controller->GetRemoteHost())); |
| 84 | + m_portEntry->setText(QString::number(m_controller->GetRemotePort())); |
| 85 | +} |
| 86 | + |
| 87 | + |
| 88 | +void RemoteProcessSettingsDialog::apply() |
| 89 | +{ |
| 90 | + std::string host = m_addressEntry->text().toStdString(); |
| 91 | + m_controller->SetRemoteHost(host); |
| 92 | + auto data = new Metadata(host); |
| 93 | + m_controller->GetData()->StoreMetadata("debugger.remote_host", data); |
| 94 | + |
| 95 | + std::string portString = m_portEntry->text().toStdString(); |
| 96 | + uint64_t port; |
| 97 | + try |
| 98 | + { |
| 99 | + port = stoull(portString); |
| 100 | + } |
| 101 | + catch(const std::exception&) |
| 102 | + { |
| 103 | + port = 31337; |
| 104 | + } |
| 105 | + |
| 106 | + m_controller->SetRemotePort(port); |
| 107 | + data = new Metadata(port); |
| 108 | + m_controller->GetData()->StoreMetadata("debugger.remote_port", data); |
| 109 | + |
| 110 | + const auto platform = m_pluginEntry->currentText().toStdString(); |
| 111 | + if (!platform.empty()) |
| 112 | + { |
| 113 | + m_controller->SetAdapterProperty("current_process_plugin", new Metadata(platform)); |
| 114 | + m_controller->GetData()->StoreMetadata("debugger.process_plugin", new Metadata(platform)); |
| 115 | + } |
| 116 | + |
| 117 | + accept(); |
| 118 | +} |
0 commit comments