11
11
import com .security .smithloader .log .SmithAgentLogger ;
12
12
13
13
import java .lang .instrument .Instrumentation ;
14
+ import java .lang .reflect .Constructor ;
14
15
import java .lang .reflect .Method ;
15
16
import java .util .concurrent .locks .ReentrantLock ;
16
17
@@ -74,32 +75,34 @@ private static boolean loadSmithProber(String proberPath, Instrumentation inst)
74
75
try {
75
76
xLoader = new SmithLoader (proberPath , null );
76
77
SmithProberClazz = xLoader .loadClass ("com.security.smith.SmithProbe" );
77
- Method [] methods = SmithProberClazz .getDeclaredMethods ();
78
- for (Method method : methods ) {
79
- if (method .isSynthetic ()) {
80
- System .out .println ("Lambda method: " + method .getName ());
81
- }
82
- else {
83
- System .out .println ("method: " + method .getName ());
84
- }
85
- }
86
78
87
79
Class <?>[] emptyArgTypes = new Class []{};
88
80
//SmithProberObj = Reflection.invokeStaticMethod(SmithProberClazz,"getInstance", emptyArgTypes);
89
- SmithProberObj = SmithProberClazz .newInstance ();
90
-
91
- Class <?>[] objArgTypes = new Class []{Object .class };
92
- Reflection .invokeMethod (SmithProberObj ,"setClassLoader" ,objArgTypes ,xLoader );
93
- Class <?>[] argType = new Class []{Instrumentation .class };
94
- Reflection .invokeMethod (SmithProberObj ,"setInst" ,argType ,inst );
95
- Reflection .invokeMethod (SmithProberObj ,"init" ,emptyArgTypes );
96
- SmithProberProxyObj = Reflection .invokeMethod (SmithProberObj ,"getSmithProbeProxy" , emptyArgTypes );
97
- binited = true ;
98
-
99
-
100
- Reflection .invokeMethod (SmithProberObj ,"start" ,emptyArgTypes );
101
-
102
- bret = true ;
81
+ if (SmithProberClazz != null ) {
82
+ Constructor <?> constructor = SmithProberClazz .getDeclaredConstructor ();
83
+ constructor .setAccessible (true );
84
+ SmithProberObj = constructor .newInstance ();
85
+ if (SmithProberObj != null ) {
86
+ Class <?>[] objArgTypes = new Class []{Object .class };
87
+ Reflection .invokeMethod (SmithProberObj ,"setClassLoader" ,objArgTypes ,xLoader );
88
+ Class <?>[] argType = new Class []{Instrumentation .class };
89
+ Reflection .invokeMethod (SmithProberObj ,"setInst" ,argType ,inst );
90
+ Reflection .invokeMethod (SmithProberObj ,"init" ,emptyArgTypes );
91
+ SmithProberProxyObj = Reflection .invokeMethod (SmithProberObj ,"getSmithProbeProxy" , emptyArgTypes );
92
+ binited = true ;
93
+
94
+
95
+ Reflection .invokeMethod (SmithProberObj ,"start" ,emptyArgTypes );
96
+
97
+ bret = true ;
98
+ } else {
99
+ SmithAgentLogger .logger .info ("call SmithProbe init failed" );
100
+ }
101
+ } else {
102
+ SmithAgentLogger .logger .info ("load com.security.smith.SmithProbe failed" );
103
+ bret = false ;
104
+ }
105
+
103
106
}
104
107
catch (Exception e ) {
105
108
SmithAgentLogger .exception (e );
@@ -135,7 +138,7 @@ private static Boolean unLoadSmithProber() {
135
138
SmithAgentLogger .logger .info ("unLoadSmithProber Entry" );
136
139
137
140
try {
138
- if (SmithProberObj != null ) {
141
+ if (SmithProberObj != null ) {
139
142
SmithAgentLogger .logger .info ("Start unload prober" );
140
143
Class <?>[] emptyArgTypes = new Class []{};
141
144
Reflection .invokeMethod (SmithProberObj ,"stop" ,emptyArgTypes );
@@ -151,8 +154,7 @@ private static Boolean unLoadSmithProber() {
151
154
SmithAgentLogger .logger .info ("unload prober end" );
152
155
153
156
bret = true ;
154
- }
155
- else {
157
+ } else {
156
158
bret = true ;
157
159
}
158
160
}
@@ -253,8 +255,8 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
253
255
else {
254
256
System .setProperty ("smith.rasp" , probeVersion +"-" +checksumStr );
255
257
System .setProperty ("smith.status" , "attach" );
258
+ System .setProperty ("rasp.probe" , "smith" );
256
259
}
257
- System .setProperty ("rasp.probe" , "smith" );
258
260
}
259
261
}
260
262
finally {
0 commit comments