-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathdebugadapterscriptingprovider.cpp
More file actions
143 lines (115 loc) · 3.96 KB
/
Copy pathdebugadapterscriptingprovider.cpp
File metadata and controls
143 lines (115 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright 2020-2026 Vector 35 Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "debugadapterscriptingprovider.h"
using namespace BinaryNinja;
using namespace BinaryNinjaDebuggerAPI;
static DebugAdapterScriptingProvider* g_debugAdapterScriptingProvider = nullptr;
DebugAdapterScriptingProvider::DebugAdapterScriptingProvider() : ScriptingProvider("Debugger", "debugger") {}
Ref<ScriptingInstance> DebugAdapterScriptingProvider::CreateNewInstance()
{
return new DebugAdapterScriptingInstance(this);
}
bool DebugAdapterScriptingProvider::LoadModule(const std::string& repository, const std::string& module, bool force)
{
return false;
}
bool DebugAdapterScriptingProvider::InstallModules(const std::string& modules)
{
return false;
}
DebugAdapterScriptingInstance::DebugAdapterScriptingInstance(ScriptingProvider* provider) : ScriptingInstance(provider)
{
m_readyStatus = NotReadyForInput;
}
DebugAdapterScriptingInstance::~DebugAdapterScriptingInstance()
{
if (m_controller)
m_controller->RemoveEventCallback(m_debuggerEventCallback);
}
void DebugAdapterScriptingInstance::SetCurrentBinaryView(BinaryNinja::BinaryView* view)
{
if (m_data != view)
{
m_data = view;
if (m_data)
{
if (m_controller)
m_controller->RemoveEventCallback(m_debuggerEventCallback);
m_controller = DebuggerController::GetController(view);
if (m_controller)
{
// A scripting instance is NOT a Qt widget, so it is fine to not do things on the main thread
m_debuggerEventCallback = m_controller->RegisterEventCallback(
[&](const DebuggerEvent& event) {
if (event.type == BackendMessageEventType)
{
const std::string message = event.data.messageData.message;
Output(message);
}
},
"Debugger Console");
}
}
else
{
if (m_controller)
{
m_controller->RemoveEventCallback(m_debuggerEventCallback);
m_controller = nullptr;
m_debuggerEventCallback = -1;
}
}
}
BNScriptingProviderInputReadyState newReadyStatus = NotReadyForInput;
if (m_data && m_controller)
newReadyStatus = ReadyForScriptExecution;
else
newReadyStatus = NotReadyForInput;
if (newReadyStatus != m_readyStatus)
{
m_readyStatus = newReadyStatus;
InputReadyStateChanged(m_readyStatus);
}
}
BNScriptingProviderExecuteResult DebugAdapterScriptingInstance::ExecuteScriptInput(const std::string& input)
{
if (m_controller)
{
// The UI component adds a trailing '\n' to the input, which must be removed before we send it to the backend
auto trimmedInput = input;
trimmedInput.erase(trimmedInput.find_last_not_of('\n') + 1);
auto ret = m_controller->InvokeBackendCommand(trimmedInput);
// Do not output the returned string if it is DbgEng, since the output from DbgEng backend is already handled
// by the BackendMessageEventType event
if ((m_controller->GetAdapterType() != "DBGENG") && (m_controller->GetAdapterType() != "DBGENG_TTD")
&& (m_controller->GetAdapterType() != "LOCAL_WINDOWS_KERNEL")
&& (m_controller->GetAdapterType() != "WINDOWS_KERNEL")
&& (m_controller->GetAdapterType() != "WINDOWS_DUMP_FILE"))
{
Output(ret);
}
return SuccessfulScriptExecution;
}
return InvalidScriptInput;
}
BNScriptingProviderExecuteResult DebugAdapterScriptingInstance::ExecuteScriptInputFromFilename(
const std::string& filename)
{
return SuccessfulScriptExecution;
}
void RegisterDebugAdapterScriptingProvider()
{
static DebugAdapterScriptingProvider provider;
ScriptingProvider::Register(&provider);
g_debugAdapterScriptingProvider = &provider;
}