- 23 Oct 2024
- 2 Minutes à lire
- SombreLumière
Start the analysis (s method)
- Mis à jour le 23 Oct 2024
- 2 Minutes à lire
- SombreLumière
The s method starts the analysis process, which detects whether a device is rooted or jailbroken. As of version 4.4 of the Root Detection SDK, this method also checks the version of the signature file. The signature file version must be higher than or equal to the version defined in the Root Detection SDK (indicated by the constant t). The aim is to prevent anyone from using signature files that may contain deprecated verification rules.
For Android platforms, another signature for this method exists: public static S s(String c), which does not use the Android context. However, the Android context is necessary to improve the root detection process. As a result, the deprecated method must only be used for backward-compatibility to manage earlier client integrations (Root Detection SDK 4.3 or earlier versions).
Syntax
Android
publicstatic S s(String c, Context a)
iOS
+(s) s: (NSData*) c
Parameters
Start the analysis parameters lists the available signatures for this function:
Start the analysis parameters | |||
Parameter name | Data type | Use | Description |
---|---|---|---|
c | String/NSData* | I (mandatory) | Signature file content. |
a | Context | I (mandatory) | Android context (Android only). |
Return values
This method returns the S response object, which contains the following:
Android:
A return code that indicates the result of the analysis.
An exception if an unknown error occurs.
iOS:
A return code that indicates the result of the analysis.
An exception if an unknown error occurs.
A cause string if the return code indicates that the device is jailbroken. Could be used for debugging when there is a doubt for a false positive.
Exceptions
Start the analysis exceptions lists the possible error codes for this function.
Start the analysis exceptions | ||
Name | Value | Error message |
---|---|---|
n | 0 | Indicates that the device is not rooted/jailbroken. |
z | –4600 | Indicates an unknown error. |
r | –4601 | Indicates that the device is rooted/jailbroken. |
e | –4602 | Indicates that the signature file is null. |
l | –4603 | Indicates that the signature file length is incorrect—it must be at least 256 characters. |
f | –4604 | Indicates that the signature file format is incorrect—only hexadecimal characters are allowed. |
i | –4605 | Indicates that the signature file is invalid: wrong signature or XML parsing error. |
a | –4606 | Indicates that the version of the signature file is too old to be used by the Root Detection SDK. |
Examples
This section illustrates how to integrate and use the s method to start the analysis. For more information, refer to the Root Detection SDK sample project in the OneSpan Mobile Security Suite package.
Android
// Retrieve the signature file
InputStream ins = assetManager.open(path);
// Start analysis process
S response = P.s(convertInsToString(ins),
this.getApplicationContext());
int returnCode = response.r();
// Check the result from the analysis process
if (returnCode == O.n)
{
System.out.println("Device is not rooted.");
}
else if (returnCode == O.r)
{
System.out.println("Device is rooted.");
}
else
{
System.out.println(getMsgFromReturnCode(returnCode));
System.out.println("Error code: " + returnCode);
}
iOS
// Get file signature path
NSString * filePath = [[NSBundlemainBundle] pathForResource:@"signature" ofType:nil];
// Load signature file
NSData * d = [NSData dataWithContentsOfFile:filePath];
// Call s method: check if phone is rooted
s response = [P s:d];
NSString * resultText = @"";
// Parse result
switch(response.r){
case P_r:
resultText = @"** Device is rooted **";
break;
case P_n:
resultText = @"** Device is not rooted **";
break;
...
...