Skip to content

Commit 6ae9f43

Browse files
committed
cleaned up TalsecPlugin to use switch and removed malware callback from AndroidThreatDetectedCallback
1 parent 862e302 commit 6ae9f43

6 files changed

Lines changed: 82 additions & 90 deletions

File tree

Plugins/Android/freeRASP.androidlib/src/main/java/com/unity/free/rasp/Controller.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public void onTamperDetected() {
5454

5555
@Override
5656
public void onMalwareDetected(List<SuspiciousAppInfo> list) {
57-
String result = list.toString();
58-
UnityPlayer.UnitySendMessage(this.gameObjectName, "scanResultAndroid", result);
57+
// not implemented yet
5958
}
6059

6160
@Override

Plugins/Android/freeRASP.androidlib/src/main/java/com/unity/free/rasp/SuspiciousAppUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
public class SuspiciousAppUtils {
1212

13-
public static String SuspiciousAppToJSON(SuspiciousAppInfo suspiciousAppInfo) throws JSONException {
13+
public static String suspiciousAppToJSON(SuspiciousAppInfo suspiciousAppInfo) throws JSONException {
1414
JSONObject jsonObject = new JSONObject();
1515
jsonObject.put("package_name", suspiciousAppInfo.getPackageInfo().packageName);
1616
jsonObject.put("reason", suspiciousAppInfo.getReason());
1717
return jsonObject.toString();
1818
}
1919

20-
public static String SuspiciousAppToJSON(List<SuspiciousAppInfo> suspiciousAppInfos) throws JSONException {
20+
public static String suspiciousAppToJSON(List<SuspiciousAppInfo> suspiciousAppInfos) throws JSONException {
2121
JSONArray result = new JSONArray();
2222
for(int i=0; i<suspiciousAppInfos.size(); i++) {
23-
result.put(SuspiciousAppToJSON(suspiciousAppInfos.get(i)));
23+
result.put(suspiciousAppToJSON(suspiciousAppInfos.get(i)));
2424
}
2525
return result.toString();
2626
}

Plugins/freeRASP/AndroidThreatDetectedCallback.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public interface AndroidThreatDetectedCallback
1111
void onHookDetected();
1212
void onDeviceBindingDetected();
1313
void onObfuscationIssuesDetected();
14-
void onMalwareDetected(List<SuspiciousAppInfo> malwareList);
1514
void onScreenshotDetected();
1615
void onScreenRecordingDetected();
1716
}

Plugins/freeRASP/Talsec.cs

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TalsecPlugin : MonoBehaviour
2424
private static extern void _initTalsec(string[] appBundleIds, int appBundleIdsCount, string appTeamId, string watcherMailAddress, bool isProd);
2525
#endif
2626

27-
readonly string ControllerName = "com.unity.free.rasp.Controller";
27+
private readonly string ControllerName = "com.unity.free.rasp.Controller";
2828

2929
// Singleton instance
3030
private static TalsecPlugin _instance;
@@ -105,91 +105,90 @@ public void setiOSCallback(IOSThreatDetectedCallback callback) {
105105
public void scanResultIOS(string threatType)
106106
{
107107
if(this.iosCallback != null) {
108-
109-
if(threatType == "signature") {
110-
this.iosCallback.signatureDetected();
111-
}
112-
if(threatType == "jailbreak") {
113-
this.iosCallback.jailbreakDetected();
114-
}
115-
if(threatType == "debugger") {
116-
this.iosCallback.debuggerDetected();
117-
}
118-
if(threatType == "runtimeManipulation") {
119-
this.iosCallback.runtimeManipulationDetected();
120-
}
121-
if(threatType == "passcode") {
122-
this.iosCallback.passcodeDetected();
123-
}
124-
if(threatType == "passcodeChange") {
125-
this.iosCallback.passcodeChangeDetected();
126-
}
127-
if(threatType == "simulator") {
128-
this.iosCallback.simulatorDetected();
129-
}
130-
if(threatType == "missingSecureEnclave") {
131-
this.iosCallback.missingSecureEnclaveDetected();
132-
}
133-
if(threatType == "deviceChange") {
134-
this.iosCallback.deviceBindingDetected();
135-
}
136-
if(threatType == "deviceID") {
137-
this.iosCallback.deviceIDDetected();
138-
}
139-
if(threatType == "unofficialStore") {
140-
this.iosCallback.unofficialStoreDetected();
141-
}
142-
if(threatType == "systemVPN") {
143-
this.iosCallback.systemVPNDetected();
144-
}
145-
if(threatType == "screenshot") {
146-
this.iosCallback.screenshotDetected();
147-
}
148-
if(threatType == "screenRecording") {
149-
this.iosCallback.screenRecordingDetected();
108+
switch(threatType) {
109+
case "signature":
110+
this.iosCallback.signatureDetected();
111+
break;
112+
case "jailbreak":
113+
this.iosCallback.jailbreakDetected();
114+
break;
115+
case "debugger":
116+
this.iosCallback.debuggerDetected();
117+
break;
118+
case "runtimeManipulation":
119+
this.iosCallback.runtimeManipulationDetected();
120+
break;
121+
case "passcode":
122+
this.iosCallback.passcodeDetected();
123+
break;
124+
case "passcodeChange":
125+
this.iosCallback.passcodeChangeDetected();
126+
break;
127+
case "simulator":
128+
this.iosCallback.simulatorDetected();
129+
break;
130+
case "missingSecureEnclave":
131+
this.iosCallback.missingSecureEnclaveDetected();
132+
break;
133+
case "deviceChange":
134+
this.iosCallback.deviceBindingDetected();
135+
break;
136+
case "deviceID":
137+
this.iosCallback.deviceIDDetected();
138+
break;
139+
case "unofficialStore":
140+
this.iosCallback.unofficialStoreDetected();
141+
break;
142+
case "systemVPN":
143+
this.iosCallback.systemVPNDetected();
144+
break;
145+
case "screenshot":
146+
this.iosCallback.screenshotDetected();
147+
break;
148+
case "screenRecording":
149+
this.iosCallback.screenRecordingDetected();
150+
break;
150151
}
151152
}
152-
153153
}
154154

155155
// this method is called by the java side module
156156
public void scanResultAndroid(string talsecScanResultCallbackName) {
157157
// Debug.Log("Scan Result Callback Name: " + talsecScanResultCallbackName);
158158
if (Application.platform == RuntimePlatform.Android)
159159
{
160-
if(talsecScanResultCallbackName == "onRootDetected") {
161-
this.androidCallback.onRootDetected();
162-
}
163-
if(talsecScanResultCallbackName == "onTamperDetected") {
164-
this.androidCallback.onTamperDetected();
165-
}
166-
if(talsecScanResultCallbackName == "onDebuggerDetected") {
167-
this.androidCallback.onDebuggerDetected();
168-
}
169-
if(talsecScanResultCallbackName == "onEmulatorDetected") {
170-
this.androidCallback.onEmulatorDetected();
171-
}
172-
if(talsecScanResultCallbackName == "onObfuscationIssuesDetected") {
173-
this.androidCallback.onObfuscationIssuesDetected();
174-
}
175-
if(talsecScanResultCallbackName == "onScreenshotDetected") {
176-
this.androidCallback.onScreenshotDetected();
177-
}
178-
if(talsecScanResultCallbackName == "onScreenRecordingDetected") {
179-
this.androidCallback.onScreenRecordingDetected();
180-
}
181-
if(talsecScanResultCallbackName == "onUntrustedInstallationSourceDetected") {
182-
this.androidCallback.onUntrustedInstallationSourceDetected();
160+
switch(talsecScanResultCallbackName) {
161+
case "onRootDetected":
162+
this.androidCallback.onRootDetected();
163+
break;
164+
case "onTamperDetected":
165+
this.androidCallback.onTamperDetected();
166+
break;
167+
case "onDebuggerDetected":
168+
this.androidCallback.onDebuggerDetected();
169+
break;
170+
case "onEmulatorDetected":
171+
this.androidCallback.onEmulatorDetected();
172+
break;
173+
case "onObfuscationIssuesDetected":
174+
this.androidCallback.onObfuscationIssuesDetected();
175+
break;
176+
case "onScreenshotDetected":
177+
this.androidCallback.onScreenshotDetected();
178+
break;
179+
case "onScreenRecordingDetected":
180+
this.androidCallback.onScreenRecordingDetected();
181+
break;
182+
case "onUntrustedInstallationSourceDetected":
183+
this.androidCallback.onUntrustedInstallationSourceDetected();
184+
break;
185+
case "onHookDetected":
186+
this.androidCallback.onHookDetected();
187+
break;
188+
case "onDeviceBindingDetected":
189+
this.androidCallback.onDeviceBindingDetected();
190+
break;
183191
}
184192
}
185193
}
186-
187-
// this method is called by the java side module
188-
public void onMalwareDetected(string result) {
189-
// Debug.Log("C# onMalwareDetected " + result);
190-
List<SuspiciousAppInfo> malwareList = JsonUtility.FromJson<SuspiciousAppInfoList>(
191-
"{ \"items\": " + result + "}"
192-
).items;
193-
this.androidCallback.onMalwareDetected(malwareList);
194-
}
195194
}

Samples/freeRASPTestApp/Scripts/AndroidGame.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ void Start()
2424
string[] supportedAlternativeStores = new string[] { "com.sec.android.app.samsungapps" };
2525

2626
// initialize talsec
27+
TalsecPlugin.Instance.setAndroidCallback(this); // set Android callback
2728
TalsecPlugin.Instance.initAndroidTalsec(expectedPackageName, expectedSigningCertificateHashBase64,
2829
supportedAlternativeStores, watcherMailAddress, isProd);
29-
TalsecPlugin.Instance.setAndroidCallback(this); // set Android callback
3030
}
3131

32-
// Implementation of IAndroidCallback interface
32+
// Implementation of AndroidThreatDetectedCallback interface
3333
public void onRootDetected()
3434
{
3535
Debug.Log("Unity - Root detected");
@@ -75,10 +75,5 @@ public void onHookDetected() {
7575
public void onDeviceBindingDetected() {
7676
Debug.Log("Unity - Device binding detected");
7777
}
78-
79-
public void onMalwareDetected(List<SuspiciousAppInfo> malwareList)
80-
{
81-
Debug.Log("Unity - Malware detected " + malwareList);
82-
}
8378
}
8479
}

Samples/freeRASPTestApp/Scripts/IOSGame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ void Start()
2020
string teamId = "TEAM ID";
2121

2222
// initialize talsec
23-
TalsecPlugin.Instance.initiOSTalsec(appBundleIds, teamId, watcherMailAddress, isProd);
2423
TalsecPlugin.Instance.setiOSCallback(this); // set callback
24+
TalsecPlugin.Instance.initiOSTalsec(appBundleIds, teamId, watcherMailAddress, isProd);
2525
}
2626

2727
// Implementation of IOSThreatDetectedCallback interface

0 commit comments

Comments
 (0)