From ca75ce94d5882c1dbd58ed637adc7b433e47d5e8 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 14:33:16 -0400 Subject: [PATCH 1/7] added obj-c wrappers --- lib/CMakeLists.txt | 6 +++ wrappers/obj-c/ODWSanitizer.h | 34 ++++++++++++ wrappers/obj-c/ODWSanitizer.mm | 52 +++++++++++++++++++ wrappers/obj-c/ODWSanitizerInitConfig.h | 21 ++++++++ wrappers/obj-c/ODWSanitizerInitConfig.mm | 13 +++++ wrappers/obj-c/ODWSanitizer_private.h | 28 ++++++++++ wrappers/obj-c/OneDsCppSdk.h | 1 + .../Headers/ObjCModule-Bridging-Header.h | 2 + 8 files changed, 157 insertions(+) create mode 100644 wrappers/obj-c/ODWSanitizer.h create mode 100644 wrappers/obj-c/ODWSanitizer.mm create mode 100644 wrappers/obj-c/ODWSanitizerInitConfig.h create mode 100644 wrappers/obj-c/ODWSanitizerInitConfig.mm create mode 100644 wrappers/obj-c/ODWSanitizer_private.h diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 09a6daf4a..2473b6a8f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -187,6 +187,12 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11") ../wrappers/obj-c/ODWPrivacyGuardInitConfig.mm ) endif() + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/privacyguard/ AND BUILD_SANITIZER) + list(APPEND SRCS + ../wrappers/obj-c/ODWSanitizerInitConfig.mm + ../wrappers/obj-c/ODWSanitizer.mm + ) + endif() endif() if(APPLE AND BUILD_SWIFT_WRAPPER) diff --git a/wrappers/obj-c/ODWSanitizer.h b/wrappers/obj-c/ODWSanitizer.h new file mode 100644 index 000000000..8be4f5bb6 --- /dev/null +++ b/wrappers/obj-c/ODWSanitizer.h @@ -0,0 +1,34 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#include "objc_begin.h" + +NS_ASSUME_NONNULL_BEGIN + +/*! + The ODWSanitizer class represents Sanitizer inspector. +*/ +@interface ODWSanitizer : NSObject + +#pragma mark Behavior methods +/*! + @brief Set Sanitizer Enabled state. + @param enabled A boolean representing the enabled state for the Sanitizer. + */ ++(void)setEnabled:(bool)enabled; + +/*! + @brief Check whether the Sanitizer is enabled. + @return True if Sanitizer is enabled, otherwise false. +*/ ++(bool)enabled; + +/*! + @brief Reset the Sanitizer instance. This should be used after LogManager::FlushAndTeardown is called. + */ ++(void)resetSanitizerInstance; +@end + +NS_ASSUME_NONNULL_END +#include "objc_end.h" \ No newline at end of file diff --git a/wrappers/obj-c/ODWSanitizer.mm b/wrappers/obj-c/ODWSanitizer.mm new file mode 100644 index 000000000..119a29d91 --- /dev/null +++ b/wrappers/obj-c/ODWSanitizer.mm @@ -0,0 +1,52 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#include +#include "ILogger.hpp" +#include "LogManager.hpp" +#include "Sanitizer.hpp" +#import +#import "ODWLogConfiguration.h" +#import "ODWSanitizer.h" +#import "ODWSanitizer_private.h" +#import "ODWSanitizerInitConfig.h" + +using namespace MAT; + +@implementation ODWSanitizer + +std::shared_ptr _sanitizerPtr; + ++(void)initializeSanitizer:(ILogger *)logger withODWSanitizerInitConfig:(ODWSanitizerInitConfig *)initConfigObject; +{ + SanitizerConfiguration config(logger); + + if ([initConfigObject notificationEventName] != nil) + { + config.NotificationEventName = [[initConfigObject notificationEventName] UTF8String]; + } + + _sanitizerPtr = std::make_shared(config); + LogManager::GetInstance()->SetDataInspector(_sanitizerPtr); +} + ++(void)setEnabled:(bool)enabled +{ + if(_sanitizerPtr != nullptr) + { + _sanitizerPtr->SetEnabled(enabled); + } +} + ++(bool)enabled +{ + return _sanitizerPtr != nullptr && _sanitizerPtr->IsEnabled(); +} + ++(void)resetSanitizerInstance +{ + _sanitizerPtr = nullptr; +} + +@end \ No newline at end of file diff --git a/wrappers/obj-c/ODWSanitizerInitConfig.h b/wrappers/obj-c/ODWSanitizerInitConfig.h new file mode 100644 index 000000000..4e526815b --- /dev/null +++ b/wrappers/obj-c/ODWSanitizerInitConfig.h @@ -0,0 +1,21 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#include "objc_begin.h" + +NS_ASSUME_NONNULL_BEGIN +/*! + @brief Sanitizer Initialization Configuration + */ +@interface ODWSanitizerInitConfig : NSObject + +/*! + @brief (OPTIONAL) Custom event name to use when logging concerns from the sanitizer. Default value is `SanitizerConcerns`. + */ +@property(readwrite, copy, nonatomic) NSString* notificationEventName; + +@end +NS_ASSUME_NONNULL_END + +#include "objc_end.h" diff --git a/wrappers/obj-c/ODWSanitizerInitConfig.mm b/wrappers/obj-c/ODWSanitizerInitConfig.mm new file mode 100644 index 000000000..32739c75d --- /dev/null +++ b/wrappers/obj-c/ODWSanitizerInitConfig.mm @@ -0,0 +1,13 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#import +#import "ODWSanitizerInitConfig.h" + +/*! + @brief Sanitizer Initialization Configuration + */ +@implementation ODWSanitizerInitConfig : NSObject + +@end diff --git a/wrappers/obj-c/ODWSanitizer_private.h b/wrappers/obj-c/ODWSanitizer_private.h new file mode 100644 index 000000000..435e4afab --- /dev/null +++ b/wrappers/obj-c/ODWSanitizer_private.h @@ -0,0 +1,28 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +#include "objc_begin.h" +#include "ILogger.hpp" +#import "ODWSanitizer.h" +#import "ODWSanitizerInitConfig.h" + +NS_ASSUME_NONNULL_BEGIN + +/*! + The ODWPrivacyGuard class represents Privacy Guard Hook. +*/ +@interface ODWSanitizer (Private) + +#pragma mark Initialization methods + +/*! + @brief Initializes Privacy Guard + @param logger Logger used for reporting concerns + @param initConfigObject the configuration + */ ++(void)initializeSanitizer:(ILogger *)logger withODWSanitizerInitConfig:(ODWSanitizerInitConfig *)initConfigObject; +@end + +NS_ASSUME_NONNULL_END +#include "objc_end.h" diff --git a/wrappers/obj-c/OneDsCppSdk.h b/wrappers/obj-c/OneDsCppSdk.h index 51eff5b9c..c7da249db 100644 --- a/wrappers/obj-c/OneDsCppSdk.h +++ b/wrappers/obj-c/OneDsCppSdk.h @@ -12,6 +12,7 @@ #import "ODWLogger.h" #import "ODWLogManager.h" #import "ODWPrivacyGuard.h" +#import "ODWSanitizer.h" #import "ODWSemanticContext.h" #endif diff --git a/wrappers/swift/Headers/ObjCModule-Bridging-Header.h b/wrappers/swift/Headers/ObjCModule-Bridging-Header.h index c0e11bcb8..2de4f6a56 100644 --- a/wrappers/swift/Headers/ObjCModule-Bridging-Header.h +++ b/wrappers/swift/Headers/ObjCModule-Bridging-Header.h @@ -14,4 +14,6 @@ #import "../../obj-c/ODWLogManager.h" #import "../../obj-c/ODWPrivacyGuard.h" #import "../../obj-c/ODWPrivacyGuardInitConfig.h" +#import "../../obj-c/ODWSanitizer.h" +#import "../../obj-c/ODWSanitizerInitConfig.h" #import "../../obj-c/ODWSemanticContext.h" From 9cbb5366026f5a47febc139f7b603f51e60dcf4f Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 14:43:31 -0400 Subject: [PATCH 2/7] fixed cmakelists --- lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2473b6a8f..f6204d60d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -187,7 +187,7 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11") ../wrappers/obj-c/ODWPrivacyGuardInitConfig.mm ) endif() - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/privacyguard/ AND BUILD_SANITIZER) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/sanitizer/ AND BUILD_SANITIZER) list(APPEND SRCS ../wrappers/obj-c/ODWSanitizerInitConfig.mm ../wrappers/obj-c/ODWSanitizer.mm From 979f933348668bd53f9c23e46f716d7ae37dda98 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 15:58:09 -0400 Subject: [PATCH 3/7] fixed spacing cmakelists --- lib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f6204d60d..e9ed262c0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -191,7 +191,7 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11") list(APPEND SRCS ../wrappers/obj-c/ODWSanitizerInitConfig.mm ../wrappers/obj-c/ODWSanitizer.mm - ) + ) endif() endif() From 1f82cf054b3df423d1bb27c04d11dc397c0f8ecd Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 17:06:27 -0400 Subject: [PATCH 4/7] added swift wrappers --- wrappers/obj-c/ODWSanitizer.mm | 5 +++ .../swift/Sources/OneDSSwift/Sanitizer.swift | 30 ++++++++++++++++ .../OneDSSwift/SanitizerInitConfig.swift | 35 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 wrappers/swift/Sources/OneDSSwift/Sanitizer.swift create mode 100644 wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift diff --git a/wrappers/obj-c/ODWSanitizer.mm b/wrappers/obj-c/ODWSanitizer.mm index 119a29d91..2cf83fe84 100644 --- a/wrappers/obj-c/ODWSanitizer.mm +++ b/wrappers/obj-c/ODWSanitizer.mm @@ -20,6 +20,11 @@ @implementation ODWSanitizer +(void)initializeSanitizer:(ILogger *)logger withODWSanitizerInitConfig:(ODWSanitizerInitConfig *)initConfigObject; { + if (_sanitizerPtr != nullptr) + { + return; + } + SanitizerConfiguration config(logger); if ([initConfigObject notificationEventName] != nil) diff --git a/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift b/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift new file mode 100644 index 000000000..764ce427f --- /dev/null +++ b/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift @@ -0,0 +1,30 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// + +import ObjCModule + +/// Wrapper to `ODWSanitizer` representing the Sanitizer. +public final class Sanitizer { + + /** + Set Sanitizer enabled. + + - Parameters: + - enable: `True` to enable the Sanitizer, `False` otherwise. + */ + public static func setEnabled(_ enable: Bool) { + ODWSanitizer.setEnabled(enable) + } + + /// Checks if the Sanitizer is enabled, returns `True` if it is, `False` otherwise. + public static func enabled() -> Bool { + return ODWSanitizer.enabled() + } + + /// Resets the Sanitizer instance. + public static func resetPrivacyGuardInstance() { + ODWSanitizer.resetSanitizerInstance() + } +} diff --git a/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift b/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift new file mode 100644 index 000000000..1c4a61e48 --- /dev/null +++ b/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift @@ -0,0 +1,35 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// + +import ObjCModule + +public final class PrivacyGuardInitConfig { + let odwSanitizerInitConfig: ODWSanitizerInitConfig + + /// Default constructor. + public init() { + odwSanitizerInitConfig = ODWSanitizerInitConfig() + } + + /// (OPTIONAL) Custom event name to use when logging privacy concerns. Default value is `PrivacyConcern`. + public var notificationEventName: String { + get { + odwSanitizerInitConfig.notificationEventName + } + set { + odwSanitizerInitConfig.notificationEventName = newValue + } + } + + /** + Returns the Obj-C object of the wrapper. + + - Return: + `ODWPrivacyGuardInitConfig` object which class is wrapped around. + */ + func getODWSanitizerInitConfig() -> ODWSanitizerInitConfig { + return odwSanitizerInitConfig + } +} \ No newline at end of file From 4b2a0e528bb12aacbe2fa094e55c370dd493b2ec Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 17:08:58 -0400 Subject: [PATCH 5/7] fix santizerconfig --- wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift b/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift index 1c4a61e48..294d013ff 100644 --- a/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift +++ b/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift @@ -5,7 +5,7 @@ import ObjCModule -public final class PrivacyGuardInitConfig { +public final class SanitizerInitConfig { let odwSanitizerInitConfig: ODWSanitizerInitConfig /// Default constructor. @@ -27,7 +27,7 @@ public final class PrivacyGuardInitConfig { Returns the Obj-C object of the wrapper. - Return: - `ODWPrivacyGuardInitConfig` object which class is wrapped around. + `ODWSanitizerInitConfig` object which class is wrapped around. */ func getODWSanitizerInitConfig() -> ODWSanitizerInitConfig { return odwSanitizerInitConfig From e6f7f0abd5733e152705d5d2ef4ade25b3d47e53 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 17:10:32 -0400 Subject: [PATCH 6/7] fix santizerconfig --- wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift b/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift index 294d013ff..5882e4a64 100644 --- a/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift +++ b/wrappers/swift/Sources/OneDSSwift/SanitizerInitConfig.swift @@ -13,7 +13,7 @@ public final class SanitizerInitConfig { odwSanitizerInitConfig = ODWSanitizerInitConfig() } - /// (OPTIONAL) Custom event name to use when logging privacy concerns. Default value is `PrivacyConcern`. + /// (OPTIONAL) Custom event name to use when logging concerns from the sanitizer. Default value is `SanitizerConcerns`. public var notificationEventName: String { get { odwSanitizerInitConfig.notificationEventName From 3bad483f4579eddba23f705291be0ddfd97dadf1 Mon Sep 17 00:00:00 2001 From: fmarasco Date: Thu, 17 Apr 2025 17:35:42 -0400 Subject: [PATCH 7/7] fixed comments --- wrappers/obj-c/ODWSanitizer.h | 6 +++--- wrappers/obj-c/ODWSanitizerInitConfig.mm | 2 +- wrappers/obj-c/ODWSanitizer_private.h | 6 +++--- wrappers/swift/Sources/OneDSSwift/Sanitizer.swift | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wrappers/obj-c/ODWSanitizer.h b/wrappers/obj-c/ODWSanitizer.h index 8be4f5bb6..eb536e606 100644 --- a/wrappers/obj-c/ODWSanitizer.h +++ b/wrappers/obj-c/ODWSanitizer.h @@ -7,20 +7,20 @@ NS_ASSUME_NONNULL_BEGIN /*! - The ODWSanitizer class represents Sanitizer inspector. + The ODWSanitizer class represents the Sanitizer inspector. */ @interface ODWSanitizer : NSObject #pragma mark Behavior methods /*! - @brief Set Sanitizer Enabled state. + @brief Set the Sanitizer enabled state. @param enabled A boolean representing the enabled state for the Sanitizer. */ +(void)setEnabled:(bool)enabled; /*! @brief Check whether the Sanitizer is enabled. - @return True if Sanitizer is enabled, otherwise false. + @return True if the Sanitizer is enabled, otherwise false. */ +(bool)enabled; diff --git a/wrappers/obj-c/ODWSanitizerInitConfig.mm b/wrappers/obj-c/ODWSanitizerInitConfig.mm index 32739c75d..cc3790cf5 100644 --- a/wrappers/obj-c/ODWSanitizerInitConfig.mm +++ b/wrappers/obj-c/ODWSanitizerInitConfig.mm @@ -10,4 +10,4 @@ */ @implementation ODWSanitizerInitConfig : NSObject -@end +@end \ No newline at end of file diff --git a/wrappers/obj-c/ODWSanitizer_private.h b/wrappers/obj-c/ODWSanitizer_private.h index 435e4afab..291c71f25 100644 --- a/wrappers/obj-c/ODWSanitizer_private.h +++ b/wrappers/obj-c/ODWSanitizer_private.h @@ -10,14 +10,14 @@ NS_ASSUME_NONNULL_BEGIN /*! - The ODWPrivacyGuard class represents Privacy Guard Hook. + The ODWSanitizer class represents the sanitizer. */ @interface ODWSanitizer (Private) #pragma mark Initialization methods /*! - @brief Initializes Privacy Guard + @brief Initializes the sanitizer @param logger Logger used for reporting concerns @param initConfigObject the configuration */ @@ -25,4 +25,4 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END -#include "objc_end.h" +#include "objc_end.h" \ No newline at end of file diff --git a/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift b/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift index 764ce427f..3aefd3563 100644 --- a/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift +++ b/wrappers/swift/Sources/OneDSSwift/Sanitizer.swift @@ -27,4 +27,4 @@ public final class Sanitizer { public static func resetPrivacyGuardInstance() { ODWSanitizer.resetSanitizerInstance() } -} +} \ No newline at end of file