Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion api/debuggerapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,23 @@ namespace BinaryNinjaDebuggerAPI {
TTDMemoryEvent() : threadId(0), uniqueThreadId(0), accessType(TTDMemoryRead), address(0), size(0), memoryAddress(0), instructionAddress(0), value(0) {}
};

struct TTDPositionRangeIndexedMemoryEvent{
TTDPosition position; // Position of the memory event
uint32_t threadId; // Thread ID that performed the access
uint32_t uniqueThreadId; // Unique thread ID that performed the access
uint64_t address; // Memory address accessed
uint64_t instructionAddress; // Instruction pointer at time of access
uint64_t size; // Size of memory access
TTDMemoryAccessType accessType; // Type of memory access (parsed from object)
uint64_t value; // Value that was read/written/executed
uint8_t data[8]; // The next 8 bytes of data at the memory address

TTDPositionRangeIndexedMemoryEvent() : threadId(0), uniqueThreadId(0), address(0), size(0), accessType(TTDMemoryRead), value(0)
{
memset(data, 0, sizeof(data));
}
};

struct TTDCallEvent
{
std::string eventType; // Event type (always "Call" for TTD.Calls objects)
Expand Down Expand Up @@ -799,6 +816,7 @@ namespace BinaryNinjaDebuggerAPI {

// TTD Memory Analysis Methods
std::vector<TTDMemoryEvent> GetTTDMemoryAccessForAddress(uint64_t address, uint64_t endAddress, TTDMemoryAccessType accessType = TTDMemoryRead);
std::vector<TTDPositionRangeIndexedMemoryEvent> GetTTDMemoryAccessForPositionRange(uint64_t startAddress, uint64_t endAddress, TTDMemoryAccessType accessType, const TTDPosition startTime, const TTDPosition endTime);
std::vector<TTDCallEvent> GetTTDCallsForSymbols(const std::string& symbols, uint64_t startReturnAddress = 0, uint64_t endReturnAddress = 0);
std::vector<TTDEvent> GetTTDEvents(TTDEventType eventType);
std::vector<TTDEvent> GetAllTTDEvents();
Expand All @@ -807,7 +825,7 @@ namespace BinaryNinjaDebuggerAPI {

// TTD Code Coverage Analysis Methods
bool IsInstructionExecuted(uint64_t address);
bool RunCodeCoverageAnalysis(uint64_t startAddress, uint64_t endAddress);
bool RunCodeCoverageAnalysis(uint64_t startAddress, uint64_t endAddress, TTDPosition startTime, TTDPosition endTime);
size_t GetExecutedInstructionCount() const;
bool SaveCodeCoverageToFile(const std::string& filePath) const;
bool LoadCodeCoverageFromFile(const std::string& filePath);
Expand Down
46 changes: 44 additions & 2 deletions api/debuggercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,43 @@ bool DebuggerController::IsTTD()
return BNDebuggerIsTTD(m_object);
}

std::vector<TTDPositionRangeIndexedMemoryEvent> DebuggerController::GetTTDMemoryAccessForPositionRange(uint64_t address, uint64_t endAddress, TTDMemoryAccessType accessType, const TTDPosition startTime, const TTDPosition endTime)
{
std::vector<TTDPositionRangeIndexedMemoryEvent> result;

BNDebuggerTTDMemoryAccessType type = static_cast<BNDebuggerTTDMemoryAccessType>(accessType);
BNDebuggerTTDPosition bnStartTime = {startTime.sequence, startTime.step};
BNDebuggerTTDPosition bnEndTime = {endTime.sequence, endTime.step};

size_t count = 0;
BNDebuggerTTDPositionRangeIndexedMemoryEvent* events = BNDebuggerGetTTDMemoryAccessForPositionRange(m_object, address, endAddress, type, bnStartTime, bnEndTime, &count);

if (events && count > 0)
{
result.reserve(count);
for (size_t i = 0; i < count; i++)
{
TTDPositionRangeIndexedMemoryEvent event;
event.threadId = events[i].threadId;
event.uniqueThreadId = events[i].uniqueThreadId;
event.position.sequence = events[i].position.sequence;
event.position.step = events[i].position.step;
event.accessType = static_cast<TTDMemoryAccessType>(events[i].accessType);
event.address = events[i].address;
event.size = events[i].size;
event.instructionAddress = events[i].instructionAddress;
event.value = events[i].value;
for (size_t j = 0; j < 8; j++)
{
event.data[j] = events[i].data[j];
}
result.push_back(event);
}
BNDebuggerFreeTTDPositionRangeIndexedMemoryEvents(events, count);
}

return result;
}

std::vector<TTDMemoryEvent> DebuggerController::GetTTDMemoryAccessForAddress(uint64_t address, uint64_t endAddress, TTDMemoryAccessType accessType)
{
Expand Down Expand Up @@ -1325,9 +1362,14 @@ bool DebuggerController::IsInstructionExecuted(uint64_t address)
}


bool DebuggerController::RunCodeCoverageAnalysis(uint64_t startAddress, uint64_t endAddress)
bool DebuggerController::RunCodeCoverageAnalysis(uint64_t startAddress, uint64_t endAddress, TTDPosition startTime, TTDPosition endTime)
{
return BNDebuggerRunCodeCoverageAnalysisRange(m_object, startAddress, endAddress);
BNDebuggerTTDPosition startPos, endPos;
startPos.sequence = startTime.sequence;
startPos.step = startTime.step;
endPos.sequence = endTime.sequence;
endPos.step = endTime.step;
return BNDebuggerRunCodeCoverageAnalysisRange(m_object, startAddress, endAddress, startPos, endPos);
}


Expand Down
19 changes: 18 additions & 1 deletion api/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ extern "C"
BNDebuggerTTDMemoryAccessType accessType;
} BNDebuggerTTDMemoryEvent;

typedef struct BNDebuggerTTDPositionRangeIndexedMemoryEvent
{
BNDebuggerTTDPosition position;
uint32_t threadId;
uint32_t uniqueThreadId;
uint64_t address;
uint64_t instructionAddress;
uint64_t size;
BNDebuggerTTDMemoryAccessType accessType;
uint64_t value;
uint8_t data[8];
} BNDebuggerTTDPositionRangeIndexedMemoryEvent;

typedef struct BNDebuggerTTDCallEvent
{
char* eventType; // Event type (always "Call" for TTD.Calls objects)
Expand Down Expand Up @@ -665,6 +678,9 @@ extern "C"
// TTD Memory Analysis Functions
DEBUGGER_FFI_API BNDebuggerTTDMemoryEvent* BNDebuggerGetTTDMemoryAccessForAddress(BNDebuggerController* controller,
uint64_t address, uint64_t endAddress, BNDebuggerTTDMemoryAccessType accessType, size_t* count);
DEBUGGER_FFI_API BNDebuggerTTDPositionRangeIndexedMemoryEvent* BNDebuggerGetTTDMemoryAccessForPositionRange(BNDebuggerController* controller,
uint64_t address, uint64_t endAddress, BNDebuggerTTDMemoryAccessType accessType ,BNDebuggerTTDPosition startPosition, BNDebuggerTTDPosition endPosition,
size_t* count);
DEBUGGER_FFI_API BNDebuggerTTDCallEvent* BNDebuggerGetTTDCallsForSymbols(BNDebuggerController* controller,
const char* symbols, uint64_t startReturnAddress, uint64_t endReturnAddress, size_t* count);
DEBUGGER_FFI_API BNDebuggerTTDEvent* BNDebuggerGetTTDEvents(BNDebuggerController* controller,
Expand All @@ -673,12 +689,13 @@ extern "C"
DEBUGGER_FFI_API BNDebuggerTTDPosition BNDebuggerGetCurrentTTDPosition(BNDebuggerController* controller);
DEBUGGER_FFI_API bool BNDebuggerSetTTDPosition(BNDebuggerController* controller, BNDebuggerTTDPosition position);
DEBUGGER_FFI_API void BNDebuggerFreeTTDMemoryEvents(BNDebuggerTTDMemoryEvent* events, size_t count);
DEBUGGER_FFI_API void BNDebuggerFreeTTDPositionRangeIndexedMemoryEvents(BNDebuggerTTDPositionRangeIndexedMemoryEvent* events, size_t count);
DEBUGGER_FFI_API void BNDebuggerFreeTTDCallEvents(BNDebuggerTTDCallEvent* events, size_t count);
DEBUGGER_FFI_API void BNDebuggerFreeTTDEvents(BNDebuggerTTDEvent* events, size_t count);

// TTD Code Coverage Analysis Functions
DEBUGGER_FFI_API bool BNDebuggerIsInstructionExecuted(BNDebuggerController* controller, uint64_t address);
DEBUGGER_FFI_API bool BNDebuggerRunCodeCoverageAnalysisRange(BNDebuggerController* controller, uint64_t startAddress, uint64_t endAddress);
DEBUGGER_FFI_API bool BNDebuggerRunCodeCoverageAnalysisRange(BNDebuggerController* controller, uint64_t startAddress, uint64_t endAddress, BNDebuggerTTDPosition startTime, BNDebuggerTTDPosition endTime);
DEBUGGER_FFI_API size_t BNDebuggerGetExecutedInstructionCount(BNDebuggerController* controller);
DEBUGGER_FFI_API bool BNDebuggerSaveCodeCoverageToFile(BNDebuggerController* controller, const char* filePath);
DEBUGGER_FFI_API bool BNDebuggerLoadCodeCoverageFromFile(BNDebuggerController* controller, const char* filePath);
Expand Down
Loading