blob: bb953eaf2b06a2355dc6200a827a48fe3bcfcf8d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
package toolsconfig;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class flawfinder extends ToolsConfig {
public flawfinder() {
this.name = "flawfinder";
ToolsRegistry.registerTool(this.name, this);
}
@Override
protected void execute(String src) {
if (path == null) {
return;
}
Runtime runtime = Runtime.getRuntime();
Process p = null;
Runtime runtime2 = Runtime.getRuntime();
Process p2 = null;
try {
// 两个参数数组,一个是csv格式,一个是传入的参数
String[] arguments =
new String[] {"python", path, "--csv", src};
String[] arguments2 =
new String[] {"python", path, params, src};
p = runtime.exec(arguments);
p2 = runtime.exec(arguments2);
final InputStream is1 = p.getInputStream();
final InputStream is2 = p2.getInputStream();
System.out.println(arguments2[1]);
// csv结果添加到表格
new Thread() {
public void run() {
BufferedReader br1 =
new BufferedReader(new InputStreamReader(is1));
try {
String line1 = null;
while ((line1 = br1.readLine()) != null) {
uiFrame.ct.toRowsOfflawfinder(line1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
// 普通结果显示在文本框
new Thread() {
public void run() {
//flawfinder result
BufferedReader br1 =
new BufferedReader(new InputStreamReader(is2));
StringBuilder l1 = new StringBuilder();
result.setText("");
try {
String line1 = null;
while ((line1 = br1.readLine()) != null) {
l1.append(line1 + ENTERWindows);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
result.setText(
l1.substring(0, l1.length()));
is2.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
int exitCode = p.waitFor();
int exitCode2 = p2.waitFor();
if (exitCode == SUCCESS) {
System.out.println(SUCCESS_MESSAGE);
} else {
System.err.println(ERROR_MESSAGE + exitCode);
}
p.destroy();
p2.destroy();
} catch (Exception e) {
try {
p.getErrorStream().close();
p.getInputStream().close();
p.getOutputStream().close();
p2.getErrorStream().close();
p2.getInputStream().close();
p2.getOutputStream().close();
} catch (Exception ee) {
}
}
}
}
|