4
4
5
5
import java .io .BufferedReader ;
6
6
import java .io .File ;
7
+ import java .io .FileInputStream ;
7
8
import java .io .InputStreamReader ;
8
9
import java .util .Arrays ;
9
10
import java .util .List ;
@@ -19,11 +20,23 @@ public boolean detectFridaServer() {
19
20
20
21
for (File file : files ) {
21
22
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 ();
27
40
}
28
41
}
29
42
}
@@ -48,12 +61,25 @@ public boolean detectFridaPort() {
48
61
49
62
public boolean detectFridaLibrary () {
50
63
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
+ }
55
82
}
56
- return false ;
57
83
} catch (Exception e ) {
58
84
e .printStackTrace ();
59
85
return false ;
@@ -62,14 +88,28 @@ public boolean detectFridaLibrary() {
62
88
63
89
public boolean detectFridaTracer () {
64
90
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 ();
70
111
}
71
112
}
72
- return false ;
73
113
} catch (Exception e ) {
74
114
e .printStackTrace ();
75
115
return false ;
0 commit comments