MCPcopy Index your code
hub / github.com/10cks/fofaEX / executeCommand

Method executeCommand

src/main/java/plugins/FofaPlugin.java:112–218  ·  view source on GitHub ↗
(String searchStr, String endcount, JTextArea resultArea)

Source from the content-addressed store, hash-verified

110 }
111
112 private void executeCommand(String searchStr, String endcount, JTextArea resultArea) {
113 try {
114
115 // 从配置文件中读取设置
116 Properties properties = new Properties();
117 properties.load(new FileInputStream("./plugins/fofahack/FofaHackSetting.txt"));
118
119 String path = properties.getProperty("Path").replace("\"", ""); // 移除引号
120 String level = properties.getProperty("level").trim();
121 String outputname = properties.getProperty("outputname").trim();
122
123 // 构建 plugins/data 的文件路径对象
124 File dataDirectory = new File("./plugins/fofahack/data");
125
126 // 检查该路径表示的目录是否存在
127 if (!dataDirectory.exists()) {
128 // 不存在,则尝试创建该目录
129 boolean wasSuccessful = dataDirectory.mkdirs(); // 使用 mkdirs 而不是 mkdir 以创建任何必需的父目录
130
131 if (wasSuccessful) {
132 System.out.println("[+] FofaHack: The 'data' directory was created successfully.");
133 } else {
134 System.out.println("Failed to create the 'data' directory.");
135 }
136 }
137
138 // 构建完整的命令
139 String command = String.format("%s -k %s -on %s -e %s -l %s", path, searchStr, outputname, endcount, level);
140
141 ProcessBuilder builder = new ProcessBuilder(command.split("\\s+"));
142 builder.redirectErrorStream(true); // 合并标准错误和标准输出
143 process = builder.start();
144 writer = new PrintWriter(new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8), true);
145 // 处理输出流
146 Thread outputThread = new Thread(() -> {
147 try (BufferedReader reader = new BufferedReader(
148 new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
149 String line;
150 while ((line = reader.readLine()) != null) {
151 final String lineCopy = line;
152 SwingUtilities.invokeLater(() -> {
153 resultArea.append(lineCopy + "\n");
154 });
155 }
156 } catch (IOException e) {
157 SwingUtilities.invokeLater(() -> {
158 resultArea.append("Error reading output: " + e.getMessage() + "\n");
159 });
160 } finally {
161 try {
162 process.waitFor();
163 } catch (InterruptedException ex) {
164 SwingUtilities.invokeLater(() -> {
165 resultArea.append("Process was interrupted: " + ex.getMessage() + "\n");
166 });
167 }
168 SwingUtilities.invokeLater(() -> {
169 resultArea.append("\n程序运行结束\n");

Callers 1

actionPerformedMethod · 0.95

Calls 1

checkMakeFileMethod · 0.95

Tested by

no test coverage detected