Skip to content

Commit 8ee7ac7

Browse files
Fix API level compatibility in FridaDetection.java
1 parent 0a631a6 commit 8ee7ac7

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

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

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.BufferedReader;
66
import java.io.File;
7+
import java.io.FileInputStream;
78
import java.io.InputStreamReader;
89
import java.util.Arrays;
910
import java.util.List;
@@ -19,11 +20,23 @@ public boolean detectFridaServer() {
1920

2021
for (File file : files) {
2122
if (file.getName().matches("\\d+")) { // Check only PID directories
22-
String cmdline = new String(java.nio.file.Files.readAllBytes(new File("/proc/" + file.getName() + "/cmdline").toPath()));
23-
for (String suspiciousProcess : suspiciousProcesses) {
24-
if (cmdline.contains(suspiciousProcess)) {
25-
Log.e("Security", "Frida detected: " + cmdline);
26-
return true;
23+
FileInputStream fis = null;
24+
try {
25+
fis = new FileInputStream(new File("/proc/" + file.getName() + "/cmdline"));
26+
byte[] data = new byte[fis.available()];
27+
fis.read(data);
28+
String cmdline = new String(data);
29+
for (String suspiciousProcess : suspiciousProcesses) {
30+
if (cmdline.contains(suspiciousProcess)) {
31+
Log.e("Security", "Frida detected: " + cmdline);
32+
return true;
33+
}
34+
}
35+
} catch (Exception e) {
36+
e.printStackTrace();
37+
} finally {
38+
if (fis != null) {
39+
fis.close();
2740
}
2841
}
2942
}
@@ -48,12 +61,25 @@ public boolean detectFridaPort() {
4861

4962
public boolean detectFridaLibrary() {
5063
try {
51-
String maps = new String(java.nio.file.Files.readAllBytes(new File("/proc/self/maps").toPath()));
52-
if (maps.contains("frida") || maps.contains("gum-js")) {
53-
Log.e("Security", "Frida detected in memory!");
54-
return true;
64+
FileInputStream fis = null;
65+
try {
66+
fis = new FileInputStream(new File("/proc/self/maps"));
67+
byte[] data = new byte[fis.available()];
68+
fis.read(data);
69+
String maps = new String(data);
70+
if (maps.contains("frida") || maps.contains("gum-js")) {
71+
Log.e("Security", "Frida detected in memory!");
72+
return true;
73+
}
74+
return false;
75+
} catch (Exception e) {
76+
e.printStackTrace();
77+
return false;
78+
} finally {
79+
if (fis != null) {
80+
fis.close();
81+
}
5582
}
56-
return false;
5783
} catch (Exception e) {
5884
e.printStackTrace();
5985
return false;
@@ -62,14 +88,28 @@ public boolean detectFridaLibrary() {
6288

6389
public boolean detectFridaTracer() {
6490
try {
65-
List<String> statusLines = java.nio.file.Files.readAllLines(new File("/proc/self/status").toPath());
66-
for (String line : statusLines) {
67-
if (line.startsWith("TracerPid")) {
68-
int tracerPid = Integer.parseInt(line.split("\t")[1].trim());
69-
return tracerPid > 0;
91+
FileInputStream fis = null;
92+
try {
93+
fis = new FileInputStream(new File("/proc/self/status"));
94+
byte[] data = new byte[fis.available()];
95+
fis.read(data);
96+
String status = new String(data);
97+
String[] statusLines = status.split("\n");
98+
for (String line : statusLines) {
99+
if (line.startsWith("TracerPid")) {
100+
int tracerPid = Integer.parseInt(line.split("\t")[1].trim());
101+
return tracerPid > 0;
102+
}
103+
}
104+
return false;
105+
} catch (Exception e) {
106+
e.printStackTrace();
107+
return false;
108+
} finally {
109+
if (fis != null) {
110+
fis.close();
70111
}
71112
}
72-
return false;
73113
} catch (Exception e) {
74114
e.printStackTrace();
75115
return false;

0 commit comments

Comments
 (0)