Skip to content

Commit 95c5034

Browse files
committed
1. Frida detection issue resolved.
2. printStackTrace() method removed
1 parent 87ff48f commit 95c5034

File tree

7 files changed

+35
-39
lines changed

7 files changed

+35
-39
lines changed

protect/src/main/java/com/webileapps/safeguard/CyberUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ public static void checkApplicationSpoofing(Context context, SecurityChecker sec
129129
onChecked.accept(true);
130130
}
131131
}
132-
133132
public static void checkKeyLoggerDetection(Context context, SecurityChecker securityChecker, Consumer<Boolean> onChecked) {
134133
SecurityChecker.SecurityCheck result = securityChecker.checkKeyLoggerDetection();
135134
if (result instanceof SecurityChecker.SecurityCheck.Warning) {

protect/src/main/java/com/webileapps/safeguard/DevicePolicyEnforcement.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public static boolean enforceDevicePolicy(Context context) {
1616
// showPolicyViolationDialog(context);
1717
return isDevOptionsEnabled || isUSBDebuggingEnabled || isMockLocationEnabled || isTimeManipulated;
1818
}
19-
2019
private static boolean isDeveloperOptionsEnabled(Context context) {
2120
try {
2221
int devOptions = Settings.Global.getInt(
@@ -25,11 +24,10 @@ private static boolean isDeveloperOptionsEnabled(Context context) {
2524
);
2625
return devOptions == 1;
2726
} catch (Settings.SettingNotFoundException e) {
28-
e.printStackTrace();
27+
2928
return false;
3029
}
3130
}
32-
3331
private static boolean isUSBDebuggingEnabled(Context context) {
3432
try {
3533
int adbEnabled = Settings.Global.getInt(
@@ -38,11 +36,10 @@ private static boolean isUSBDebuggingEnabled(Context context) {
3836
);
3937
return adbEnabled == 1;
4038
} catch (Settings.SettingNotFoundException e) {
41-
e.printStackTrace();
39+
4240
return false;
4341
}
4442
}
45-
4643
private static boolean isTimeManipulated(Context context) {
4744
try {
4845
int autoTime = Settings.Global.getInt(
@@ -55,7 +52,7 @@ private static boolean isTimeManipulated(Context context) {
5552
);
5653
return autoTime == 0 || autoTimeZone == 0;
5754
} catch (Settings.SettingNotFoundException e) {
58-
e.printStackTrace();
55+
5956
return false;
6057
}
6158
}

protect/src/main/java/com/webileapps/safeguard/FridaDetection.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.BufferedReader;
66
import java.io.File;
77
import java.io.FileInputStream;
8+
import java.io.IOException;
89
import java.io.InputStreamReader;
910
import java.util.Arrays;
1011
import java.util.List;
@@ -19,33 +20,47 @@ public boolean detectFridaServer() {
1920
if (files == null) return false;
2021

2122
for (File file : files) {
22-
if (file.getName().matches("\\d+")) { // Check only PID directories
23+
String fileName = file.getName();
24+
25+
// Avoid regex - check if name is numeric (PID)
26+
if (isNumeric(fileName)) {
2327
FileInputStream fis = null;
2428
try {
25-
fis = new FileInputStream(new File("/proc/" + file.getName() + "/cmdline"));
29+
File cmdlineFile = new File("/proc/" + fileName + "/cmdline");
30+
if (!cmdlineFile.exists()) continue;
31+
32+
fis = new FileInputStream(cmdlineFile);
2633
byte[] data = new byte[fis.available()];
2734
fis.read(data);
28-
String cmdline = new String(data);
35+
36+
String cmdline = new String(data).trim();
2937
for (String suspiciousProcess : suspiciousProcesses) {
3038
if (cmdline.contains(suspiciousProcess)) {
3139
Log.e("Security", "Frida detected: " + cmdline);
3240
return true;
3341
}
3442
}
3543
} catch (Exception e) {
36-
e.printStackTrace();
44+
// Likely a permissions issue; ignore
3745
} finally {
3846
if (fis != null) {
39-
fis.close();
47+
try { fis.close(); } catch (IOException ignored) {}
4048
}
4149
}
4250
}
4351
}
44-
return false;
45-
} catch (Exception e) {
46-
e.printStackTrace();
47-
return false;
52+
} catch (Exception ignored) {
53+
4854
}
55+
return false;
56+
}
57+
58+
private boolean isNumeric(String str) {
59+
if (str == null || str.isEmpty()) return false;
60+
for (int i = 0; i < str.length(); i++) {
61+
if (!Character.isDigit(str.charAt(i))) return false;
62+
}
63+
return true;
4964
}
5065

5166
public boolean detectFridaPort() {
@@ -54,7 +69,7 @@ public boolean detectFridaPort() {
5469
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
5570
return reader.lines().anyMatch(line -> line.contains("27042") || line.contains("frida"));
5671
} catch (Exception e) {
57-
e.printStackTrace();
72+
5873
return false;
5974
}
6075
}
@@ -73,15 +88,13 @@ public boolean detectFridaLibrary() {
7388
}
7489
return false;
7590
} catch (Exception e) {
76-
e.printStackTrace();
7791
return false;
7892
} finally {
7993
if (fis != null) {
8094
fis.close();
8195
}
8296
}
8397
} catch (Exception e) {
84-
e.printStackTrace();
8598
return false;
8699
}
87100
}
@@ -103,15 +116,13 @@ public boolean detectFridaTracer() {
103116
}
104117
return false;
105118
} catch (Exception e) {
106-
e.printStackTrace();
107119
return false;
108120
} finally {
109121
if (fis != null) {
110122
fis.close();
111123
}
112124
}
113125
} catch (Exception e) {
114-
e.printStackTrace();
115126
return false;
116127
}
117128
}

protect/src/main/java/com/webileapps/safeguard/KeyloggerDetection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public static boolean isAccessibilityServiceEnabled(Context context) {
1313
if (enabledServices != null && enabledServices.contains(context.getPackageName())) {
1414
return true;
1515
}
16-
} catch (Exception e) {
17-
e.printStackTrace();
16+
} catch (Exception ignored) {
1817
}
1918
return false;
2019
}

protect/src/main/java/com/webileapps/safeguard/MockLocationDetection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public static boolean isMockLocationEnabled(Context context) {
2828
}
2929
}
3030
}
31-
} catch (Exception e) {
32-
e.printStackTrace();
31+
} catch (Exception ignored) {
3332
}
3433
return false;
3534
}

protect/src/main/java/com/webileapps/safeguard/NetworkUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public static boolean isVPNActive(Context context) {
1717
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(activeNetwork);
1818
return capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN);
1919
}
20-
2120
public static boolean isProxySet(Context context) {
2221
try {
2322
ConnectivityManager connectivityManager =
@@ -29,7 +28,6 @@ public static boolean isProxySet(Context context) {
2928
return false;
3029
}
3130
}
32-
3331
public static boolean isWifiSecure(Context context) {
3432
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
3533
try {

protect/src/main/java/com/webileapps/safeguard/SecurityChecker.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ private void setupModernCallMonitoring() {
288288
callStateListener
289289
);
290290
telephonyCallback = callStateListener;
291-
} catch (SecurityException e) {
292-
e.printStackTrace();
291+
} catch (SecurityException ignored) {
293292
}
294293
}
295294

@@ -303,8 +302,7 @@ public void onCallStateChanged(int state, String phoneNumber) {
303302
}
304303
};
305304
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
306-
} catch (SecurityException e) {
307-
e.printStackTrace();
305+
} catch (SecurityException ignored) {
308306
}
309307
}
310308

@@ -505,8 +503,7 @@ public SecurityCheck checkDeveloperOptions() {
505503
if (developerMode) {
506504
return createDevOptionsResponse(context.getString(R.string.developer_options_warning));
507505
}
508-
} catch (Settings.SettingNotFoundException e) {
509-
e.printStackTrace();
506+
} catch (Settings.SettingNotFoundException ignored) {
510507
}
511508

512509
try {
@@ -517,8 +514,7 @@ public SecurityCheck checkDeveloperOptions() {
517514
if (usbDebugging) {
518515
return createDevOptionsResponse("USB debugging is enabled.");
519516
}
520-
} catch (Settings.SettingNotFoundException e) {
521-
e.printStackTrace();
517+
} catch (Settings.SettingNotFoundException ignored) {
522518
}
523519

524520
try {
@@ -532,8 +528,7 @@ public SecurityCheck checkDeveloperOptions() {
532528
} else if (isTimeManipulated()) {
533529
return createDevOptionsResponse(context.getString(R.string.auto_time_warning));
534530
}
535-
} catch (Exception e) {
536-
e.printStackTrace();
531+
} catch (Exception ignored) {
537532
}
538533

539534
return new SecurityCheck.Success();
@@ -556,7 +551,6 @@ private boolean isTimeManipulated() {
556551
int autoTimeZone = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE);
557552
return autoTime == 0 || autoTimeZone == 0;
558553
} catch (Settings.SettingNotFoundException e) {
559-
e.printStackTrace();
560554
return false;
561555
}
562556
}
@@ -810,7 +804,6 @@ public String generateFileChecksum(File file, String algorithm) {
810804
}
811805
return hexString.toString();
812806
} catch (Exception e) {
813-
e.printStackTrace();
814807
return null;
815808
}
816809
}

0 commit comments

Comments
 (0)