When App Shielding performs security checks, it can either be configured to exit the application when a security problem is detected (e.g., Exit on hooking frameworks), or it can be configured to notify the application via a callback. By handling the callback, you can, for instance, inform the user about the possible security threat.
Callbacks currently occur when the application registers an event handler with the Shield SDK’s prm_event_handler_add() function, when the application launches, and when the application is moved to the foreground.
To implement callbacks
Ensure the relevant security feature is enabled in the configuration (e.g., Check jailbreak), and is not configured to exit the application when the security problem is detected (e.g., Exit on jailbreak).
Ensure that
SDK/C/ShieldSDK.xcframeworkis included in the project.Include the
ShieldSDK/event_manager.hheader in any source files that will interact with the callback APIs.Define a
struct prm_event_cbsand assign a function to each event you want to handle.NULLmembers are skipped when the corresponding event occurs.Pair the callbacks with a context pointer in a
struct prm_event_handlerand register it by callingprm_event_handler_add(). Thectxpointer is passed back to every callback, so you can use it to carry your own state. It must remain valid for as long as the handler is registered. Registration should be performed as early as possible, because many security checks are performed right after the application has launched.
prm_event_handler_add() returns 0 on success and a non-zero value if the handler could not be registered. You can add as many handlers as you like, and each one receives callbacks for as long as the app is running or until the handler is removed. Handlers are removed with prm_event_handler_del(). The handler is matched on both the context pointer and every function pointer in the callback struct, so you must pass a struct prm_event_handler that is identical to the one you registered.
To avoid a deadlock in the application, a callback must not add or remove handlers, either directly or indirectly. This means any function assigned to a member of
struct prm_event_cbsmust never callprm_event_handler_add()orprm_event_handler_del(), and must never call any code of your own that does so.
Example implementations
The following example sets up handlers for jailbreak and screenshot checks.
#include <ShieldSDK/event_manager.h>
...
static void
on_jailbreak(void *ctx, bool isjb)
{
(void)ctx;
if (isjb)
handle_device_is_jailbroken();
}
static void
on_screenshot(void *ctx)
{
(void)ctx;
handle_screenshot_detected();
}
__attribute__((constructor))
static void
shield_callbacks_init(void)
{
struct prm_event_handler handler = {
.ctx = NULL,
.cbs = {
.jailbreak = on_jailbreak,
.screenshot = on_screenshot,
},
};
prm_event_handler_add(handler);
}Some callbacks, like
jailbreak, are always triggered and provide a boolean value that indicates whether the security check is positive. Other callbacks, likescreenshot, are only triggered when the offending event is detected and thus provide nosuch value.
List of callbacks on iOS
The following members of struct prm_event_cbs are called after App Shielding has performed its security checks, where every callback receives the registered context pointer as its first argument:
Callback | Description |
|---|---|
| Provides a boolean that indicates whether the device on which the application is running is jailbroken. Some detectors for Dopamine RootHide jailbreaks currently do not trigger a callback. |
| Provides a boolean that indicates whether the app is running on a Mac with System Integrity Protection (SIP) disabled. |
| Provides a boolean that indicates whether the app has been repackaged. If the application is running in a simulator, then this callback is never called. |
| Provides a boolean that indicates whether one or more screens that the app is using are being recorded. |
| Provides a boolean that indicates whether Developer Mode is enabled on the device. Developer Mode was added in iOS 16, so this callback always provides |
| Provides a boolean that indicates whether a debugger is attached to the host application. If App Shielding is configured to block debuggers, then this callback is never called. |
| Provides a boolean that indicates whether one of the device’s network connections has a virtual private network (VPN) enabled. |
| Called when App Shielding has detected that the application is being run in an emulator. |
| Called when App Shielding discovers that a screenshot of the application has been taken. If the application is running in a simulator, this callback is never called. |
| Called when App Shielding has prevented an untrusted library from being injected into the process during runtime. This callback is deprecated and does not trigger on iOS/tvOS 17 or higher and macOS 14 or higher. Instead, the app terminates unexpectedly. |
| Called when App Shielding has detected that there are untrusted libraries in the process. A repackaged app can also trigger this callback in addition to the repackaging callback. In production, you should configure App Shielding to use the Exit On Library Injection option and not rely on handling a callback. |
| Called when App Shielding has detected that there are hooking frameworks in the process. In production, however, you should configure App Shielding to use the the Exit On Hooking Frameworks option and not rely on handling a callback. |
Exit on... security options like Exit on Jailbreak will cause the application to immediately exit before the corresponding callback is triggered. Also note that some of these options, like Exit on Repackaging, are always enabled in release mode.
Debugging: manual triggering of callbacks
For debugging purposes, most callbacks can be manually triggered using the functions declared in the event_trigger.h header. Each function takes the delay, in seconds, before the event is delivered. The following example triggers the jailbreak callback with a status of true (i.e., the device is jailbroken) after a delay of two second:
#include <ShieldSDK/event_trigger.h>
...
#ifdef DEBUG
prm_event_trigger_jailbreak(true, 2);
#endifTo immediately trigger the callback, set afterDelay to 0.
Callback triggers are designed for debugging purposes only and should be conditionally applied to debug builds or removed from the app code entirely before running the Shielding Tool on the app. The app will terminate unexpectedly if callback triggers are present in the App Shielding-protected version of the app.
Available callback triggers
The following functions accept a boolean status value as the first argument and a delay in seconds as the second argument:
void prm_event_trigger_jailbreak(bool status, int64_t delay);
void prm_event_trigger_repackaging(bool status, int64_t delay);
void prm_event_trigger_recording(bool status, int64_t delay);
void prm_event_trigger_debugger(bool status, int64_t delay);
void prm_event_trigger_vpn(bool status, int64_t delay);
void prm_event_trigger_developer_mode(bool status, int64_t delay);The following functions only accept a delay argument:
void prm_event_trigger_emulator(int64_t delay);
void prm_event_trigger_library_prevented(int64_t delay);
void prm_event_trigger_library_detected(int64_t delay);
void prm_event_trigger_hooking(int64_t delay);
void prm_event_trigger_screenshot(int64_t delay);The prm_event_trigger_library_prevented() function is deprecated and will be removed in a future release of App Shielding.
When App Shielding performs security checks, it can either be configured to exit the application when a security problem is detected (e.g., Exit on hooking frameworks), or it can be configured to notify the application via a callback. By handling the callback, you can, for instance, inform the user about the possible security threat.
Callbacks currently occur when the application registers an event handler with the Shield SDK’s prm_event_handler_add() function, when the application launches, and when the application is moved to the foreground.
To implement callbacks
Ensure the relevant security feature is enabled in the configuration (e.g., Check jailbreak), and is not configured to exit the application when the security problem is detected (e.g., Exit on jailbreak).
Ensure that
SDK/C/ShieldSDK.xcframeworkis included in the project.Include the
ShieldSDK/event_manager.hheader in any source files that will interact with the callback APIs.Define a
struct prm_event_cbsand assign a function to each event you want to handle.NULLmembers are skipped when the corresponding event occurs.Pair the callbacks with a context pointer in a
struct prm_event_handlerand register it by callingprm_event_handler_add(). Thectxpointer is passed back to every callback, so you can use it to carry your own state. It must remain valid for as long as the handler is registered. Registration should be performed as early as possible, because many security checks are performed right after the application has launched.
prm_event_handler_add() returns 0 on success and a non-zero value if the handler could not be registered. You can add as many handlers as you like, and each one receives callbacks for as long as the app is running or until the handler is removed. Handlers are removed with prm_event_handler_del(). The handler is matched on both the context pointer and every function pointer in the callback struct, so you must pass a struct prm_event_handler that is identical to the one you registered.
Example implementations
The following example sets up handlers for jailbreak and screenshot checks.
#include <ShieldSDK/event_manager.h>
...
static void
on_jailbreak(void *ctx, bool isjb)
{
(void)ctx;
if (isjb)
handle_device_is_jailbroken();
}
static void
on_screenshot(void *ctx)
{
(void)ctx;
handle_screenshot_detected();
}
__attribute__((constructor))
static void
shield_callbacks_init(void)
{
struct prm_event_handler handler = {
.ctx = NULL,
.cbs = {
.jailbreak = on_jailbreak,
.screenshot = on_screenshot,
},
};
prm_event_handler_add(handler);
}Some callbacks, like
jailbreak, are always triggered and provide a boolean value that indicates whether the security check is positive. Other callbacks, likescreenshot, are only triggered when the offending event is detected and thus provide nosuch value.
List of callbacks on iOS
The following members of struct prm_event_cbs are called after Shield has performed its security checks, where every callback receives the registered context pointer as its first argument:
Callback | Description |
|---|---|
| Provides a boolean that indicates whether the device on which the application is running is jailbroken. Some detectors for Dopamine RootHide jailbreaks currently do not trigger a callback. |
| Provides a boolean that indicates whether the app is running on a Mac with System Integrity Protection (SIP) disabled. |
| Provides a boolean that indicates whether the app has been repackaged. If the application is running in a simulator, then this callback is never called. |
| Provides a boolean that indicates whether one or more screens that the app is using are being recorded. |
| Provides a boolean that indicates whether Developer Mode is enabled on the device. Developer Mode was added in iOS 16, so this callback always provides |
| Provides a boolean that indicates whether a debugger is attached to the host application. If App Shielding is configured to block debuggers, then this callback is never called. |
| Provides a boolean that indicates whether one of the device’s network connections has a virtual private network (VPN) enabled. |
| Called when App Shielding has detected that the application is being run in an emulator. |
| Called when App Shielding discovers that a screenshot of the application has been taken. If the application is running in a simulator, this callback is never called. |
| Called when App Shielding has prevented an untrusted library from being injected into the process during runtime. This callback is deprecated and does not trigger on iOS/tvOS 17 or higher and macOS 14 or higher. Instead, the app terminates unexpectedly. |
| Called when App Shielding has detected that there are untrusted libraries in the process. A repackaged app can also trigger this callback in addition to the repackaging callback. In production, you should configure App Shielding to use the Exit On Library Injection option and not rely on handling a callback. |
| Called when App Shielding has detected that there are hooking frameworks in the process. In production, however, you should configure App Shielding to use the the Exit On Hooking Frameworks option and not rely on handling a callback. |
Exit on... security options like Exit on Jailbreak will cause the application to immediately exit before the corresponding callback is triggered. Also note that some of these options, like Exit on Repackaging, are always enabled in release mode.
Debugging: manual triggering of callbacks
For debugging purposes, most callbacks can be manually triggered using the functions declared in the event_trigger.h header. Each function takes the delay, in seconds, before the event is delivered. The following example triggers the jailbreak callback with a status of true (i.e., the device is jailbroken) after a delay of two second:
#include <ShieldSDK/event_trigger.h>
...
#ifdef DEBUG
prm_event_trigger_jailbreak(true, 2);
#endifTo immediately trigger the callback, set afterDelay to 0.
Callback triggers are designed for debugging purposes only and should be conditionally applied to debug builds or removed from the app code entirely before running the Shielding Tool on the app. The app will terminate unexpectedly if callback triggers are present in the App Shielding-protected version of the app.
Available callback triggers
The following functions accept a boolean status value as the first argument and a delay in seconds as the second argument:
void prm_event_trigger_jailbreak(bool status, int64_t delay);
void prm_event_trigger_repackaging(bool status, int64_t delay);
void prm_event_trigger_recording(bool status, int64_t delay);
void prm_event_trigger_debugger(bool status, int64_t delay);
void prm_event_trigger_vpn(bool status, int64_t delay);
void prm_event_trigger_developer_mode(bool status, int64_t delay);The following functions only accept a delay argument:
void prm_event_trigger_emulator(int64_t delay);
void prm_event_trigger_library_prevented(int64_t delay);
void prm_event_trigger_library_detected(int64_t delay);
void prm_event_trigger_hooking(int64_t delay);
void prm_event_trigger_screenshot(int64_t delay);The prm_event_trigger_library_prevented() function is deprecated and will be removed in a future release of App Shielding.