Version: 3.2 Update
This commit is contained in:
77
src/main/java/hae/utils/project/ProjectProcessor.java
Normal file
77
src/main/java/hae/utils/project/ProjectProcessor.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package hae.utils.project;
|
||||
|
||||
import burp.api.montoya.MontoyaApi;
|
||||
import hae.utils.project.model.HaeFileContent;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class ProjectProcessor {
|
||||
private final MontoyaApi api;
|
||||
|
||||
public ProjectProcessor(MontoyaApi api) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public boolean createHaeFile(String haeFilePath, String host, Map<String, List<String>> dataMap, Map<String, Map<String, String>> httpMap) {
|
||||
ByteArrayOutputStream dataYamlStream = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream httpYamlStream = new ByteArrayOutputStream();
|
||||
Yaml yaml = new Yaml();
|
||||
|
||||
yaml.dump(dataMap, new OutputStreamWriter(dataYamlStream, StandardCharsets.UTF_8));
|
||||
yaml.dump(httpMap, new OutputStreamWriter(httpYamlStream, StandardCharsets.UTF_8));
|
||||
|
||||
try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(haeFilePath))) {
|
||||
zipOut.putNextEntry(new ZipEntry("info.txt"));
|
||||
zipOut.write(host.getBytes(StandardCharsets.UTF_8));
|
||||
zipOut.closeEntry();
|
||||
|
||||
zipOut.putNextEntry(new ZipEntry("data.yml"));
|
||||
zipOut.write(dataYamlStream.toByteArray());
|
||||
zipOut.closeEntry();
|
||||
|
||||
zipOut.putNextEntry(new ZipEntry("http.yml"));
|
||||
zipOut.write(httpYamlStream.toByteArray());
|
||||
zipOut.closeEntry();
|
||||
} catch (Exception e) {
|
||||
api.logging().logToOutput(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public HaeFileContent readHaeFile(String haeFilePath) {
|
||||
HaeFileContent haeFileContent = new HaeFileContent(api);
|
||||
Yaml yaml = new Yaml();
|
||||
|
||||
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(haeFilePath))) {
|
||||
ZipEntry entry;
|
||||
while ((entry = zipIn.getNextEntry()) != null) {
|
||||
switch (entry.getName()) {
|
||||
case "info.txt":
|
||||
haeFileContent.setHost(new String(zipIn.readAllBytes(), StandardCharsets.UTF_8));
|
||||
break;
|
||||
case "data.yml":
|
||||
haeFileContent.setDataMap(yaml.load(new InputStreamReader(zipIn, StandardCharsets.UTF_8)));
|
||||
break;
|
||||
case "http.yml":
|
||||
haeFileContent.setHttpMap(yaml.load(new InputStreamReader(zipIn, StandardCharsets.UTF_8)));
|
||||
break;
|
||||
}
|
||||
zipIn.closeEntry();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
api.logging().logToOutput(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
return haeFileContent;
|
||||
}
|
||||
}
|
||||
|
||||
67
src/main/java/hae/utils/project/model/HaeFileContent.java
Normal file
67
src/main/java/hae/utils/project/model/HaeFileContent.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package hae.utils.project.model;
|
||||
|
||||
import burp.api.montoya.MontoyaApi;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HaeFileContent {
|
||||
private final MontoyaApi api;
|
||||
private String host;
|
||||
private final Map<String, List<String>> dataMap;
|
||||
private final Map<String, Map<String, String>> httpMap;
|
||||
|
||||
public HaeFileContent(MontoyaApi api) {
|
||||
this.api = api;
|
||||
this.dataMap = new HashMap<>();
|
||||
this.httpMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getDataMap() {
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getHttpMap() {
|
||||
return httpMap;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public void setDataMap(Map<String, List<Object>> dataMap) {
|
||||
for (Map.Entry<String, List<Object>> entry : dataMap.entrySet()) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (Object value : entry.getValue()) {
|
||||
try {
|
||||
values.add(new String((byte[]) value, StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
values.add(value.toString());
|
||||
}
|
||||
}
|
||||
this.dataMap.put(entry.getKey(), values);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHttpMap(Map<String, Map<String, Object>> httpMap) {
|
||||
for (Map.Entry<String, Map<String, Object>> entry : httpMap.entrySet()) {
|
||||
Map<String, String> newValues = new HashMap<>();
|
||||
Map<String, Object> values = entry.getValue();
|
||||
for (String key : values.keySet()) {
|
||||
try {
|
||||
newValues.put(key, new String((byte[]) values.get(key), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
newValues.put(key, values.get(key).toString());
|
||||
}
|
||||
}
|
||||
this.httpMap.put(entry.getKey(), newValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user