Check attributes let you configure Dotfuscator Checks directly in your source code.
Dotfuscator recognizes these attributes and uses them to inject the corresponding Check into the annotated method. The annotated method becomes the Check location, which means the Check runs when that method is called at runtime.
You can also configure Checks outside of source code by using the Checks tab in the Config Editor.
Reference the Attributes
The Check attributes are available in the public NuGet package PreEmptive.Protection.Checks.Attributes.
The package includes targeted versions of PreEmptive.Attributes.dll for:
- .NET Standard 2.0
- .NET Framework 1.1
To use PreEmptive.Attributes.dll, add a reference to the NuGet package by using one of the following methods:
PackageReferencepackages.config
If you use Visual Studio integration with attributes and the Strip Check Attributes input option is enabled, PreEmptive.Attributes.dll may be present in your project output directory, such as bin/Release.
Because this file is not needed after the project is built, you can remove it from the output directory.
Attribute Requirements
For Dotfuscator to recognize a Check attribute and inject the corresponding Check, all of the following must be true:
- The Disable Checks option must be set to No.
- The Honor Check Attributes input option must be enabled for the input assembly that contains the attribute.
The Honor Check Attributes input option is enabled by default.
For Dotfuscator to remove Check attributes from the protected assembly, the Strip Check Attributes input option must be enabled for the input assembly that contains the attribute.
The Strip Check Attributes input option is enabled by default.
Available Check Attributes
Dotfuscator recognizes the following Check attributes:
| Attribute | Injected Check |
|---|---|
TamperCheckAttribute |
Tamper Check |
DebuggingCheckAttribute |
Debugging Check |
ShelfLifeCheckAttribute |
Shelf Life Check |
RootCheckAttribute |
Root Check |
Each attribute applies to methods. Multiple Check attributes of the same type are not allowed on the same code element.
TamperCheckAttribute
TamperCheckAttribute instructs Dotfuscator to inject a Tamper Check with the annotated method as its only location.
In earlier versions of Dotfuscator, this attribute was named InsertTamperCheckAttribute. That attribute is now deprecated. Use TamperCheckAttribute instead.
| Item | Value |
|---|---|
| Namespace | PreEmptive.Attributes |
| Applies to | Method |
| Multiple allowed on one code element | No |
Properties
| Property | Description | Default |
|---|---|---|
Action |
The Check Action the Check takes if it detects a tampered application. | None |
ActionProbability |
The probability that the Check Action occurs when tampering is detected. Use a value between 0.00 and 1.00. |
1.00 |
ApplicationNotificationSinkElement |
The kind of code element the Check uses to inform the application of the Check result. | None |
ApplicationNotificationSinkName |
The name of the Application Notification sink. Required unless ApplicationNotificationSinkElement is None or DefaultAction. |
Not applicable |
ApplicationNotificationSinkOwner |
The name of the type that declares the Application Notification sink. | The type that defines the annotated method |
If ApplicationNotificationSinkElement is Method, MethodArgument, or Delegate, the Check calls a method, delegate method argument, or delegate field with the signature void(bool).
If ApplicationNotificationSinkElement is Field or Property, the Check sets a bool field or property.
DebuggingCheckAttribute
DebuggingCheckAttribute instructs Dotfuscator to inject a Debugging Check with the annotated method as its only location.
| Item | Value |
|---|---|
| Namespace | PreEmptive.Attributes |
| Applies to | Method |
| Multiple allowed on one code element | No |
Properties
| Property | Description | Default |
|---|---|---|
Action |
The Check Action the Check takes if it detects that a debugger is attached to the application. | None |
ActionProbability |
The probability that the Check Action occurs when debugging is detected. Use a value between 0.00 and 1.00. |
1.00 |
ApplicationNotificationSinkElement |
The kind of code element the Check uses to inform the application of the Check result. | None |
ApplicationNotificationSinkName |
The name of the Application Notification sink. Required unless ApplicationNotificationSinkElement is None or DefaultAction. |
Not applicable |
ApplicationNotificationSinkOwner |
The name of the type that declares the Application Notification sink. | The type that defines the annotated method |
If ApplicationNotificationSinkElement is Method, MethodArgument, or Delegate, the Check calls a method, delegate method argument, or delegate field with the signature void(bool).
If ApplicationNotificationSinkElement is Field or Property, the Check sets a bool field or property.
ShelfLifeCheckAttribute
ShelfLifeCheckAttribute instructs Dotfuscator to inject a Shelf Life Check with the annotated method as its only location.
A Shelf Life Activation Key is required to use this attribute.
In earlier versions of Dotfuscator, this attribute was named InsertShelfLifeAttribute. That attribute is now deprecated. Use ShelfLifeCheckAttribute instead.
| Item | Value |
|---|---|
| Namespace | PreEmptive.Attributes |
| Applies to | Method |
| Multiple allowed on one code element | No |
Additional requirements
For Dotfuscator to recognize ShelfLifeCheckAttribute and inject a Shelf Life Check, the attribute must also meet the following requirements:
- The
ActivationKeyFileproperty must refer to a valid Shelf Life Activation Key. - Either
ExpirationDateorShelfLifeTokenSourcemust be set.
Use ExpirationDate to embed the Shelf Life Token with the Check.
Use ShelfLifeTokenSource to have the Check retrieve the Shelf Life Token at runtime.
Properties
| Property | Description | Default |
|---|---|---|
ActivationKeyFile |
The path to a valid Shelf Life Activation Key file at build time. The file is not needed after Dotfuscator processes the assembly. | Always required |
ExpirationDate |
The application expiration date. Use an absolute date in YYYY-MM-DD format or a number of days from the date Dotfuscator processes the application. |
Required if ShelfLifeTokenSource is None
|
ExpirationNotificationSinkElement |
The kind of code element the Check uses to notify the application whether it is expired or to provide the warning and expiration dates. | None |
ExpirationNotificationSinkName |
The name of the Expiration Notification sink. Required unless ExpirationNotificationSinkElement is None or DefaultAction. |
Not applicable |
ExpirationNotificationSinkOwner |
The name of the type that declares the Expiration Notification sink. | The type that defines the annotated method |
WarningDate |
The application warning date. Use an absolute date in YYYY-MM-DD format or a number of days from the date Dotfuscator processes the application. If specified, it must be before ExpirationDate. |
No warning date |
WarningNotificationSinkElement |
The kind of code element the Check uses to notify the application whether it is in the warning period or to provide the warning and expiration dates. | None |
WarningNotificationSinkName |
The name of the Warning Notification sink. Required unless WarningNotificationSinkElement is None or DefaultAction. |
Not applicable |
WarningNotificationSinkOwner |
The name of the type that declares the Warning Notification sink. | The type that defines the annotated method |
PrivateKeyFile |
The path to a private key file in PKCS #12 format at build time. Only used when ExpirationDate is set. |
Token is not signed |
PrivateKeyFilePassword |
The password for the private key file. Only used if PrivateKeyFile is specified. |
No password |
ShelfLifeTokenSourceElement |
The kind of code element that contains an externally stored Shelf Life Token. | None |
ShelfLifeTokenSourceName |
The name of the Shelf Life Token source. Required unless ShelfLifeTokenSourceElement is None or DefaultAction. |
Not applicable |
ShelfLifeTokenSourceOwner |
The name of the type that declares the Shelf Life Token source. | The type that defines the annotated method |
Expiration and Warning Notification Sinks
To report whether the application has expired or is in the warning period:
- If the sink element is
Method,MethodArgument, orDelegate, the Check calls a method, delegate method argument, or delegate field with the signaturevoid(bool). - If the sink element is
FieldorProperty, the Check sets aboolfield or property.
To report the Shelf Life warning and expiration dates:
- If the sink element is
Method,MethodArgument, orDelegate, the Check calls a method, delegate method argument, or delegate field with the signaturevoid(string, string). -
FieldandPropertyare not supported for this mode.
If ExpirationNotificationSinkElement is DefaultAction, the Check exits the application if the application is expired.
Shelf Life Token source
If ShelfLifeTokenSourceElement is MethodArgument, Field, or Property, the Check uses a Shelf Life Token provided in a string method argument, field, or property.
If ShelfLifeTokenSourceElement is Method, the Check uses a Shelf Life Token returned by a method with the signature string().
RootCheckAttribute
RootCheckAttribute instructs Dotfuscator to inject a Root Check with the annotated method as its only location.
| Item | Value |
|---|---|
| Namespace | PreEmptive.Attributes |
| Applies to | Method |
| Multiple allowed on one code element | No |
Properties
| Property | Description | Default |
|---|---|---|
Action |
The Check Action the Check takes if it detects that the application is running on a rooted Android device. | None |
ActionProbability |
The probability that the Check Action occurs when root is detected. Use a value between 0.00 and 1.00. |
1.00 |
ApplicationNotificationSinkElement |
The kind of code element the Check uses to inform the application of the Check result. | None |
ApplicationNotificationSinkName |
The name of the Application Notification sink. Required unless ApplicationNotificationSinkElement is None or DefaultAction. |
Not applicable |
ApplicationNotificationSinkOwner |
The name of the type that declares the Application Notification sink. | The type that defines the annotated method |
If ApplicationNotificationSinkElement is Method, MethodArgument, or Delegate, the Check calls a method, delegate method argument, or delegate field with the signature void(bool).
If ApplicationNotificationSinkElement is Field or Property, the Check sets a bool field or property.