Skip to content

Commit 6a4f0e8

Browse files
Copilotxusheng6
andcommitted
Add TTDHeapEvent structure and core API implementation
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
1 parent c3f27a1 commit 6a4f0e8

File tree

8 files changed

+600
-57
lines changed

8 files changed

+600
-57
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ api/python/__pycache__
6969
# TTD files
7070
*.run
7171
*.idx
72-
*.bndb
72+
*.bndb
73+
74+
__pycache__/

api/debuggerapi.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ namespace BinaryNinjaDebuggerAPI {
538538
uint64_t size; // Size of the module in bytes
539539
uint32_t checksum; // Checksum of the module
540540
uint32_t timestamp; // Timestamp of the module
541-
541+
542542
TTDModule() : address(0), size(0), checksum(0), timestamp(0) {}
543543
};
544544

@@ -551,7 +551,7 @@ namespace BinaryNinjaDebuggerAPI {
551551
TTDPosition lifetimeEnd; // Lifetime end position
552552
TTDPosition activeTimeStart; // Active time start position
553553
TTDPosition activeTimeEnd; // Active time end position
554-
554+
555555
TTDThread() : uniqueId(0), id(0) {}
556556
};
557557

@@ -571,7 +571,7 @@ namespace BinaryNinjaDebuggerAPI {
571571
uint32_t flags; // Exception flags
572572
uint64_t recordAddress; // Where in memory the exception record is found
573573
TTDPosition position; // Position where exception occurred
574-
574+
575575
TTDException() : type(TTDExceptionSoftware), programCounter(0), code(0), flags(0), recordAddress(0) {}
576576
};
577577

@@ -580,16 +580,41 @@ namespace BinaryNinjaDebuggerAPI {
580580
{
581581
TTDEventType type; // Type of event
582582
TTDPosition position; // Position where event occurred
583-
583+
584584
// Optional child objects - existence depends on event type
585585
std::optional<TTDModule> module; // For ModuleLoaded/ModuleUnloaded events
586586
std::optional<TTDThread> thread; // For ThreadCreated/ThreadTerminated events
587587
std::optional<TTDException> exception; // For Exception events
588-
588+
589589
TTDEvent() : type(TTDEventThreadCreated) {}
590590
TTDEvent(TTDEventType eventType) : type(eventType) {}
591591
};
592592

593+
struct TTDHeapEvent
594+
{
595+
std::string eventType; // Event type (always "Heap" for TTD.Heap objects)
596+
std::string action; // Heap action: Alloc, ReAlloc, Free, Create, Protect, Lock, Unlock, Destroy
597+
uint32_t threadId; // OS thread ID of thread that made the heap call
598+
uint32_t uniqueThreadId; // Unique ID for the thread across the trace
599+
uint64_t heap; // Handle for the Win32 heap
600+
uint64_t address; // Address of the allocated object (if applicable)
601+
uint64_t previousAddress; // Address before reallocation (for ReAlloc)
602+
uint64_t size; // Size of allocated object (if applicable)
603+
uint64_t baseAddress; // Base address of allocated object (if applicable)
604+
uint64_t flags; // Heap API flags (meaning depends on API)
605+
uint64_t result; // Result of heap API call (non-zero = success)
606+
uint64_t reserveSize; // Amount of memory to reserve (for Create)
607+
uint64_t commitSize; // Initial committed size (for Create)
608+
uint64_t makeReadOnly; // Non-zero = make heap read-only (for Protect)
609+
std::vector<std::string> parameters; // Raw parameters from the heap call
610+
TTDPosition timeStart; // Position when heap operation started
611+
TTDPosition timeEnd; // Position when heap operation ended
612+
613+
TTDHeapEvent() : threadId(0), uniqueThreadId(0), heap(0), address(0), previousAddress(0),
614+
size(0), baseAddress(0), flags(0), result(0), reserveSize(0),
615+
commitSize(0), makeReadOnly(0) {}
616+
};
617+
593618

594619
typedef BNDebugAdapterConnectionStatus DebugAdapterConnectionStatus;
595620
typedef BNDebugAdapterTargetStatus DebugAdapterTargetStatus;
@@ -764,6 +789,7 @@ namespace BinaryNinjaDebuggerAPI {
764789
std::vector<TTDCallEvent> GetTTDCallsForSymbols(const std::string& symbols, uint64_t startReturnAddress = 0, uint64_t endReturnAddress = 0);
765790
std::vector<TTDEvent> GetTTDEvents(TTDEventType eventType);
766791
std::vector<TTDEvent> GetAllTTDEvents();
792+
std::vector<TTDHeapEvent> GetTTDHeapObjects();
767793
TTDPosition GetCurrentTTDPosition();
768794
bool SetTTDPosition(const TTDPosition& position);
769795

0 commit comments

Comments
 (0)