Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allocate one EventRecordMetadata^ and reuse it for RawProvider events #250

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions Microsoft.O365.Security.Native.ETW/EventRecordMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ namespace Microsoft { namespace O365 { namespace Security { namespace ETW {
: record_(&record)
, header_(&record.EventHeader) { }

EventRecordMetadata() { }

/// <summary>
/// Updates this instance to point to the specified event record.
/// </summary>
virtual void Update(const EVENT_RECORD& record)
{
record_ = &record;
header_ = &record.EventHeader;
}

public:
// For container ID's, we are expecting format "00000000-0000-0000-0000-0000000000000",
// 32 hex digits with 4 hyphens, no braces.
Expand Down
7 changes: 6 additions & 1 deletion Microsoft.O365.Security.Native.ETW/RawProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ namespace Microsoft { namespace O365 { namespace Security { namespace ETW {
NativePtr<krabs::provider<>> provider_;
GCHandle delegateHookHandle_;
GCHandle delegateHandle_;
EventRecordMetadata^ data_;
void SetUpProvider();
};

Expand All @@ -148,6 +149,8 @@ namespace Microsoft { namespace O365 { namespace Security { namespace ETW {
delegateHookHandle_ = GCHandle::Alloc(bridged);

provider_->add_on_event_callback((krabs::c_provider_callback)bridged.ToPointer());

data_ = gcnew EventRecordMetadata();
}

inline RawProvider::~RawProvider()
Expand All @@ -165,6 +168,8 @@ namespace Microsoft { namespace O365 { namespace Security { namespace ETW {

inline void RawProvider::EventNotification(const EVENT_RECORD &record)
{
OnEvent(gcnew EventRecordMetadata(record));
data_->Update(record);

OnEvent(data_);
}
} } } }
Loading