-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathesrevenadapter.h
More file actions
217 lines (165 loc) · 8.12 KB
/
esrevenadapter.h
File metadata and controls
217 lines (165 loc) · 8.12 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
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.
*/
#pragma once
#include "../debugadapter.h"
#include "../debugadaptertype.h"
#include "rspconnector.h"
#include <map>
#include <queue>
#include "../semaphore.h"
namespace BinaryNinjaDebugger
{
class EsrevenAdapter : public DebugAdapter
{
protected:
struct RegisterInfo
{
std::uint32_t m_bitSize{};
std::uint32_t m_regNum{};
std::uint32_t m_offset{};
};
struct PendingBreakpoint
{
ModuleNameAndOffset address;
unsigned long type;
PendingBreakpoint(ModuleNameAndOffset address, unsigned long type) : address(address), type(type) {}
};
DebugStopReason m_lastStopReason{};
using register_pair = std::pair<std::string, RegisterInfo>;
Socket* m_socket;
RspConnector* m_rspConnector{};
std::map<std::string, RegisterInfo> m_registerInfo{};
std::optional<std::unordered_map<std::string, DebugRegister>> m_regCache;
std::uint32_t m_internalBreakpointId{};
// THis is the breakpoint that is active on the gdbserver side
std::vector<DebugBreakpoint> m_debugBreakpoints{};
std::vector<PendingBreakpoint> m_pendingBreakpoints {};
std::vector<PendingHardwareBreakpoint> m_pendingHardwareBreakpoints {};
std::optional<std::vector<DebugModule>> m_moduleCache{};
// Cache for thread list with frames (from rvn:list-threads)
struct ThreadFrameCache
{
std::uint32_t tid;
std::uintptr_t rip;
std::vector<DebugFrame> frames;
};
std::optional<std::vector<ThreadFrameCache>> m_threadCache{};
std::uint32_t m_lastActiveThreadId{};
std::uint32_t m_processPid{};
uint8_t m_exitCode{};
std::string GetGDBServerPath();
std::string ExecuteShellCommand(const std::string& command);
virtual bool LoadRegisterInfo();
// This name is confusing. It actually means whether the target is running, so certain operations, e.g.,
// reading memory, adding breakpoint, cannot be carried out at the moment.
bool m_isTargetRunning;
// Cache the name of the remote architecture, so there is no need to read it repeatedly.
// However, this does not handle the case when the remote arch changes. Though other changes are also needed to
// support the case -- so we do not really lose a lot anyways.
std::string m_remoteArch;
// Whether the target uses big-endian byte order. Determined from target XML <endian> element
// or inferred from architecture name.
bool m_isBigEndian = false;
bool m_canReverseContinue = false;
bool m_canReverseStep = false;
void InvalidateCache();
virtual DebugStopReason SignalToStopReason(std::unordered_map<std::string, std::uint64_t>& map);
bool GetModuleBase(const std::string& moduleName, uint64_t& base);
void CheckApplyPendingBreakpoints();
void ClearCachedBreakpoints() { m_debugBreakpoints.clear(); }
public:
EsrevenAdapter(BinaryView* data, bool redirectGDBServer = true);
~EsrevenAdapter();
bool Execute(const std::string& path, const LaunchConfigurations& configs) override;
bool ExecuteWithArgs(const std::string &path, const std::string &args, const std::string &workingDir,
const LaunchConfigurations &configs) override;
bool Attach(std::uint32_t pid) override;
bool Connect(const std::string& server, std::uint32_t port) override;
bool ConnectToDebugServer(const std::string& server, std::uint32_t port) override;
bool DisconnectDebugServer() override;
bool Detach() override;
bool Quit() override;
std::vector<DebugThread> GetThreadList() override;
DebugThread GetActiveThread() const override;
std::uint32_t GetActiveThreadId() const override;
bool SetActiveThread(const DebugThread& thread) override;
bool SetActiveThreadId(std::uint32_t tid) override;
std::vector<DebugFrame> GetFramesOfThread(std::uint32_t tid) override;
DebugBreakpoint AddBreakpoint(std::uintptr_t address, unsigned long breakpoint_type = 0) override;
bool RemoveBreakpoint(const DebugBreakpoint& breakpoint) override;
std::vector<DebugBreakpoint> GetBreakpointList() const override;
bool BreakpointExists(uint64_t address) const;
std::unordered_map<std::string, DebugRegister> ReadAllRegisters() override;
DebugRegister ReadRegister(const std::string& reg) override;
bool WriteRegister(const std::string& reg, intx::uint512 value) override;
DataBuffer ReadMemory(std::uintptr_t address, std::size_t size) override;
bool WriteMemory(std::uintptr_t address, const DataBuffer& buffer) override;
std::string GetRemoteFile(const std::string& path);
std::vector<DebugModule> GetModuleList() override;
// TTD Memory Access support
std::vector<TTDMemoryEvent> GetTTDMemoryAccessForAddress(uint64_t startAddress, uint64_t endAddress, TTDMemoryAccessType accessType = TTDMemoryRead) override;
std::vector<TTDPositionRangeIndexedMemoryEvent> GetTTDMemoryAccessForPositionRange(uint64_t startAddress, uint64_t endAddress, TTDMemoryAccessType accessType, const TTDPosition startTime, const TTDPosition endTime) override;
std::string GetTargetArchitecture() override;
DebugStopReason StopReason() override;
uint64_t ExitCode() override { return m_exitCode; }
bool BreakInto() override;
DebugStopReason GenericGo(const std::string& goCommand, bool notifyStopped = true);
bool Go() override;
bool StepInto() override;
bool StepOver() override;
bool StepReturn() override;
bool GoReverse() override;
bool StepIntoReverse() override;
bool StepOverReverse() override;
bool StepReturnReverse() override;
std::string InvokeBackendCommand(const std::string& command) override;
std::string RunMonitorCommand(const std::string& command);
uint64_t GetInstructionOffset() override;
uint64_t GetStackPointer() override;
std::uint32_t GetActivePID() override;
DebugStopReason ResponseHandler(bool notifyStopped = true);
bool SupportFeature(DebugAdapterCapacity feature) override;
void HandleAsyncPacket(const RspData& data);
std::vector<DebugProcess> GetProcessList() override;
bool SuspendThread(std::uint32_t tid) override;
bool ResumeThread(std::uint32_t tid) override;
DebugBreakpoint AddBreakpoint(const ModuleNameAndOffset& address, unsigned long breakpoint_type = 0) override;
// Hardware breakpoint and watchpoint support
bool AddHardwareBreakpoint(uint64_t address, DebugBreakpointType type, size_t size = 1) override;
bool RemoveHardwareBreakpoint(uint64_t address, DebugBreakpointType type, size_t size = 1) override;
bool AddHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size = 1) override;
bool RemoveHardwareBreakpoint(const ModuleNameAndOffset& location, DebugBreakpointType type, size_t size = 1) override;
// Legacy methods - kept for backward compatibility
bool AddHardwareWriteBreakpoint(uint64_t address);
bool RemoveHardwareWriteBreakpoint(uint64_t address);
// TTD (Time Travel Debugging) support
TTDPosition GetCurrentTTDPosition() override;
bool SetTTDPosition(const TTDPosition& position) override;
std::vector<TTDCallEvent> GetTTDCallsForSymbols(const std::string& symbols, uint64_t startReturnAddress = 0, uint64_t endReturnAddress = 0) override;
std::vector<TTDStringEntry> GetTTDStrings(const std::string& pattern = "", uint64_t maxResults = 0) override;
void GenerateDefaultAdapterSettings(BinaryView* data);
Ref<Settings> GetAdapterSettings() override;
};
class EsrevenAdapterType: public DebugAdapterType
{
static Ref<Settings> RegisterAdapterSettings();
public:
EsrevenAdapterType();
virtual DebugAdapter* Create(BinaryNinja::BinaryView* data);
virtual bool IsValidForData(BinaryNinja::BinaryView* data);
virtual bool CanExecute(BinaryNinja::BinaryView* data);
virtual bool CanConnect(BinaryNinja::BinaryView* data);
static Ref<Settings> GetAdapterSettings();
};
void InitEsrevenAdapterType();
};