Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d43809e25f | ||
|
|
567dea6c60 | ||
|
|
8c388510c5 | ||
|
|
e22596819b | ||
|
|
d2cd7a0d03 | ||
|
|
67afe1f650 | ||
|
|
0602346249 | ||
|
|
953b966961 | ||
|
|
4c23d62576 | ||
|
|
6e9b8c8f37 | ||
|
|
ed58d891d5 | ||
|
|
33f5cab037 | ||
|
|
8b79c71df9 | ||
|
|
9ea0e4be9c | ||
|
|
41f197bcb2 | ||
|
|
31e419aed2 | ||
|
|
cf90a9366a | ||
|
|
6546446e4f | ||
|
|
6c4073c8ee | ||
|
|
1e1d51921d | ||
|
|
9135b8cbd2 | ||
|
|
cc7956d8dc | ||
|
|
405efdd5da | ||
|
|
0bb425f00b | ||
|
|
0bdff6fe28 | ||
|
|
6bd153d16a | ||
|
|
b12f9355fa | ||
|
|
fa9dcfc3d2 | ||
|
|
2e23388925 | ||
|
|
06fd54c9ce | ||
|
|
0707a773c8 | ||
|
|
d0f49f8e6c | ||
|
|
5404c90c00 |
@@ -21,6 +21,8 @@
|
||||
1. Linux/Mac用户的配置文件目录:`~/.config/HaE/`
|
||||
2. Windows用户的配置文件目录:`%USERPROFILE%/.config/HaE/`
|
||||
|
||||
除此之外,您也可以选择将配置文件存放在`HaE Jar包`的同级目录下的`/.config/HaE/`中,**以便于离线携带**。
|
||||
|
||||
## 优势特点
|
||||
|
||||
1. 精细配置:高度自由的配置选项,以满足各类精细化场景需求。
|
||||
|
||||
@@ -30,5 +30,4 @@ dependencies {
|
||||
compile group: 'org.yaml', name: 'snakeyaml', version: '1.28'
|
||||
compile 'net.sourceforge.jregex:jregex:1.2_01'
|
||||
compile 'dk.brics.automaton:automaton:1.11-8'
|
||||
compile 'com.squareup.okhttp:okhttp:2.7.5'
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 172 KiB |
@@ -1,17 +1,15 @@
|
||||
package burp;
|
||||
|
||||
import burp.config.ConfigLoader;
|
||||
import burp.core.processor.ColorProcessor;
|
||||
import burp.core.processor.MessageProcessor;
|
||||
import burp.ui.MainUI;
|
||||
import burp.ui.board.MessagePanel;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
@@ -22,10 +20,9 @@ import javax.swing.event.ChangeListener;
|
||||
|
||||
public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEditorTabFactory, ITab {
|
||||
private MainUI main;
|
||||
// stdout变成公开属性,便于其他类调用输出调试信息
|
||||
public static PrintWriter stdout;
|
||||
private IBurpExtenderCallbacks callbacks;
|
||||
private static IExtensionHelpers helpers;
|
||||
public static IBurpExtenderCallbacks callbacks;
|
||||
public static IExtensionHelpers helpers;
|
||||
ColorProcessor colorProcessor = new ColorProcessor();
|
||||
MessageProcessor messageProcessor = new MessageProcessor();
|
||||
private MessagePanel messagePanel;
|
||||
@@ -33,10 +30,12 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
@Override
|
||||
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
|
||||
{
|
||||
this.callbacks = callbacks;
|
||||
BurpExtender.callbacks = callbacks;
|
||||
BurpExtender.helpers = callbacks.getHelpers();
|
||||
|
||||
String version = "2.5";
|
||||
new ConfigLoader();
|
||||
|
||||
String version = "2.5.3";
|
||||
callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version));
|
||||
|
||||
// 定义输出
|
||||
@@ -92,27 +91,32 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
|
||||
IHttpService iHttpService = null;
|
||||
|
||||
String host = "";
|
||||
|
||||
try {
|
||||
iHttpService = messageInfo.getHttpService();
|
||||
host = iHttpService.getHost();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 获取请求主机信息
|
||||
assert iHttpService != null;
|
||||
String host = iHttpService.getHost();
|
||||
|
||||
String c = new String(content, StandardCharsets.UTF_8).intern();
|
||||
if (Objects.equals(host, "")) {
|
||||
List<String> requestTmpHeaders = helpers.analyzeRequest(content).getHeaders();
|
||||
host = requestTmpHeaders.get(1).split(":")[1].trim();
|
||||
}
|
||||
|
||||
List<Map<String, String>> result = null;
|
||||
|
||||
try {
|
||||
result = messageProcessor.processMessage(helpers, content, messageIsRequest, true, host);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String resComment = "";
|
||||
String resColor = "";
|
||||
String originalColor = messageInfo.getHighlight();
|
||||
String originalComment = messageInfo.getComment();
|
||||
|
||||
if (result != null && !result.isEmpty() && result.size() > 0) {
|
||||
List<String> colorList = new ArrayList<>();
|
||||
|
||||
@@ -125,19 +129,53 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
messageInfo.setHighlight(resColor);
|
||||
|
||||
String addComment = String.join(", ", result.get(1).get("comment"));
|
||||
resComment = !Objects.equals(originalComment, "") ? String.format("%s, %s", originalComment, addComment) : addComment;
|
||||
String allComment = !Objects.equals(originalComment, "") ? String.format("%s, %s", originalComment, addComment) : addComment;
|
||||
resComment = mergeComment(allComment);
|
||||
messageInfo.setComment(resComment);
|
||||
}
|
||||
|
||||
String endComment = resComment.isEmpty() ? originalComment : resComment;
|
||||
String endColor = resColor.isEmpty() ? originalColor : resColor;
|
||||
|
||||
if (!messageIsRequest && !endComment.isEmpty() && !endColor.isEmpty()) {
|
||||
if (!messageIsRequest && !Objects.equals(endComment, "") && !Objects.equals(endColor, "")) {
|
||||
messagePanel.add(messageInfo, endComment, String.valueOf(content.length), endColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String mergeComment(String comment) {
|
||||
if (!comment.contains(",")) {
|
||||
return comment;
|
||||
}
|
||||
|
||||
Map<String, Integer> itemCounts = new HashMap<>();
|
||||
String[] items = comment.split(", ");
|
||||
|
||||
for (String item : items) {
|
||||
if (item.contains("(") && item.contains(")")) {
|
||||
int openParenIndex = item.lastIndexOf("(");
|
||||
int closeParenIndex = item.lastIndexOf(")");
|
||||
String itemName = item.substring(0, openParenIndex).trim();
|
||||
int count = Integer.parseInt(item.substring(openParenIndex + 1, closeParenIndex).trim());
|
||||
itemCounts.put(itemName, itemCounts.getOrDefault(itemName, 0) + count);
|
||||
} else {
|
||||
itemCounts.put(item, 0);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder mergedItems = new StringBuilder();
|
||||
|
||||
for (Map.Entry<String, Integer> entry : itemCounts.entrySet()) {
|
||||
String itemName = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
if (count != 0) {
|
||||
mergedItems.append(itemName).append(" (").append(count).append("), ");
|
||||
}
|
||||
}
|
||||
|
||||
return mergedItems.substring(0, mergedItems.length() - 2);
|
||||
}
|
||||
|
||||
class MarkInfoTab implements IMessageEditorTab {
|
||||
private final JTabbedPane jTabbedPane = new JTabbedPane();
|
||||
private JTable jTable = new JTable();
|
||||
@@ -168,8 +206,8 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(byte[] content, boolean isRequest) {
|
||||
String c = new String(content, StandardCharsets.UTF_8).intern();
|
||||
List<Map<String, String>> result = null;
|
||||
|
||||
try {
|
||||
result = messageProcessor.processMessage(helpers, content, isRequest, false, "");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
@@ -219,7 +257,6 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
||||
*/
|
||||
@Override
|
||||
public void setMessage(byte[] content, boolean isRequest) {
|
||||
String c = new String(content, StandardCharsets.UTF_8).intern();
|
||||
if (content.length > 0) {
|
||||
if (isRequest) {
|
||||
makeTable(extractRequestMap);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package burp.config;
|
||||
|
||||
import burp.BurpExtender;
|
||||
import burp.rule.utils.RuleTool;
|
||||
import burp.rule.utils.YamlTool;
|
||||
import java.io.*;
|
||||
@@ -19,7 +20,7 @@ import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
public class ConfigLoader {
|
||||
private static final Yaml yaml = YamlTool.newStandardYaml();
|
||||
private static final String HaEConfigPath = String.format("%s/.config/HaE", System.getProperty("user.home"));
|
||||
private static final String HaEConfigPath = determineConfigPath();
|
||||
private static final String RulesFilePath = String.format("%s/%s", HaEConfigPath, "Rules.yml");
|
||||
private static final String ConfigFilePath = String.format("%s/%s", HaEConfigPath, "Config.yml");
|
||||
|
||||
@@ -31,44 +32,66 @@ public class ConfigLoader {
|
||||
}
|
||||
|
||||
File configFilePath = new File(ConfigFilePath);
|
||||
|
||||
if (!(configFilePath.exists() && configFilePath.isFile())) {
|
||||
initConfig();
|
||||
initRules();
|
||||
}
|
||||
ConfigEntry.globalRules = ConfigLoader.getRules();
|
||||
}
|
||||
|
||||
public void initConfig() {
|
||||
File rulesFilePath = new File(RulesFilePath);
|
||||
if (!(rulesFilePath.exists() && rulesFilePath.isFile())) {
|
||||
initRules();
|
||||
}
|
||||
|
||||
ConfigEntry.globalRules = getRules();
|
||||
}
|
||||
|
||||
private static String determineConfigPath() {
|
||||
// 优先级1:用户根目录
|
||||
String userConfigPath = String.format("%s/.config/HaE", System.getProperty("user.home"));
|
||||
if (isValidConfigPath(userConfigPath)) {
|
||||
return userConfigPath;
|
||||
}
|
||||
|
||||
// 优先级2:Jar包所在目录
|
||||
String jarPath = BurpExtender.callbacks.getExtensionFilename();
|
||||
String jarDirectory = new File(jarPath).getParent();
|
||||
String jarConfigPath = String.format("%s/.config/HaE", jarDirectory);
|
||||
if (isValidConfigPath(jarConfigPath)) {
|
||||
return jarConfigPath;
|
||||
}
|
||||
|
||||
return userConfigPath;
|
||||
}
|
||||
|
||||
private static boolean isValidConfigPath(String configPath) {
|
||||
File configPathFile = new File(configPath);
|
||||
return configPathFile.exists() && configPathFile.isDirectory();
|
||||
}
|
||||
|
||||
public static void initConfig() {
|
||||
Map<String, Object> r = new LinkedHashMap<>();
|
||||
r.put("rulesPath", RulesFilePath);
|
||||
r.put("excludeSuffix", getExcludeSuffix());
|
||||
try {
|
||||
Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(ConfigFilePath)), StandardCharsets.UTF_8);
|
||||
yaml.dump(r, ws);
|
||||
ws.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void initRules() {
|
||||
public static void initRules() {
|
||||
RuleTool rt = new RuleTool(RulesFilePath);
|
||||
rt.getRulesFromSite();
|
||||
}
|
||||
|
||||
public static String getRulesFilePath() {
|
||||
try {
|
||||
Map<String, Object> r = YamlTool.loadYaml(ConfigFilePath);
|
||||
return r.get("rulesPath").toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return RulesFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
public String getExcludeSuffix(){
|
||||
public static String getExcludeSuffix(){
|
||||
String excludeSuffix = "";
|
||||
File yamlSetting = new File(ConfigFilePath);
|
||||
|
||||
if (yamlSetting.exists() && yamlSetting.isFile()) {
|
||||
try {
|
||||
InputStream inorder = Files.newInputStream(Paths.get(ConfigFilePath));
|
||||
@@ -81,6 +104,7 @@ public class ConfigLoader {
|
||||
} else {
|
||||
excludeSuffix = ConfigEntry.excludeSuffix;
|
||||
}
|
||||
|
||||
return excludeSuffix;
|
||||
}
|
||||
|
||||
@@ -112,20 +136,18 @@ public class ConfigLoader {
|
||||
resRule.put(groupFields.get("group").toString(), dataArray);
|
||||
}
|
||||
}
|
||||
|
||||
return resRule;
|
||||
}
|
||||
|
||||
public void setExcludeSuffix(String excludeSuffix){
|
||||
public static void setExcludeSuffix(String excludeSuffix){
|
||||
Map<String,Object> r = new LinkedHashMap<>();
|
||||
r.put("rulesPath", getRulesFilePath());
|
||||
r.put("excludeSuffix", excludeSuffix);
|
||||
try{
|
||||
Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(RulesFilePath)), StandardCharsets.UTF_8);
|
||||
yaml.dump(r, ws);
|
||||
ws.close();
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package burp.core.processor;
|
||||
|
||||
import burp.BurpExtender;
|
||||
import burp.core.GlobalCachePool;
|
||||
import burp.core.utils.HashCalculator;
|
||||
import burp.core.utils.MatchTool;
|
||||
@@ -11,12 +12,8 @@ import dk.brics.automaton.RegExp;
|
||||
import dk.brics.automaton.RunAutomaton;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import jregex.Matcher;
|
||||
import jregex.Pattern;
|
||||
|
||||
@@ -52,7 +49,7 @@ public class DataProcessingUnit {
|
||||
|
||||
public Map<String, Map<String, Object>> matchContentByRegex(byte[] content, String headers, byte[] body, String scopeString, String host)
|
||||
throws NoSuchAlgorithmException {
|
||||
// 先从池子里判断是否有已经匹配好的结果
|
||||
// 先从缓存池里判断是否有已经匹配好的结果
|
||||
String messageIndex = HashCalculator.calculateHash(content);
|
||||
Map<String, Map<String, Object>> map = GlobalCachePool.getFromCache(messageIndex);
|
||||
if (map != null) {
|
||||
@@ -82,7 +79,7 @@ public class DataProcessingUnit {
|
||||
case "any":
|
||||
case "request":
|
||||
case "response":
|
||||
matchContent = new String(content, StandardCharsets.UTF_8).intern();
|
||||
matchContent = new String(content, StandardCharsets.UTF_8);
|
||||
break;
|
||||
case "any header":
|
||||
case "request header":
|
||||
@@ -92,7 +89,7 @@ public class DataProcessingUnit {
|
||||
case "any body":
|
||||
case "request body":
|
||||
case "response body":
|
||||
matchContent = new String(body, StandardCharsets.UTF_8).intern();
|
||||
matchContent = new String(body, StandardCharsets.UTF_8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -136,9 +133,8 @@ public class DataProcessingUnit {
|
||||
String dataStr = String.join("\n", result);
|
||||
tmpMap.put("data", dataStr);
|
||||
finalMap.put(nameAndSize, tmpMap);
|
||||
|
||||
// 添加到全局变量中,便于Databoard检索
|
||||
if (!host.isEmpty()) {
|
||||
if (!Objects.equals(host, "")) {
|
||||
List<String> dataList = Arrays.asList(dataStr.split("\n"));
|
||||
if (ConfigEntry.globalDataMap.containsKey(host)) {
|
||||
Map<String, List<String>> gRuleMap = new HashMap<>(ConfigEntry.globalDataMap.get(host));
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package burp.core.utils;
|
||||
|
||||
import burp.BurpExtender;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
||||
@@ -9,11 +9,8 @@ import burp.config.ConfigLoader;
|
||||
*/
|
||||
|
||||
public class MatchTool {
|
||||
// 匹配后缀
|
||||
ConfigLoader configLoader = new ConfigLoader();
|
||||
|
||||
public boolean matchUrlSuffix(String str) {
|
||||
Pattern pattern = new Pattern(String.format("[\\w]+[\\.](%s)", configLoader.getExcludeSuffix()), REFlags.IGNORE_CASE);
|
||||
Pattern pattern = new Pattern(String.format("[\\w]+[\\.](%s)", ConfigLoader.getExcludeSuffix()), REFlags.IGNORE_CASE);
|
||||
jregex.Matcher matcher = pattern.matcher(str);
|
||||
return matcher.find();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package burp.rule.utils;
|
||||
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import burp.*;
|
||||
import burp.config.ConfigEntry;
|
||||
import burp.config.ConfigLoader;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
@@ -17,19 +19,31 @@ public class RuleTool {
|
||||
}
|
||||
|
||||
public void getRulesFromSite() {
|
||||
String url = "https://cdn.jsdelivr.net/gh/gh0stkey/HaE@gh-pages/Rules.yml";
|
||||
OkHttpClient httpClient = new OkHttpClient();
|
||||
Request httpRequest = new Request.Builder().url(url).get().build();
|
||||
// 以独立线程使用BurpSuite官方请求接口获取规则
|
||||
Thread t = new Thread(()->{
|
||||
try {
|
||||
Response httpResponse = httpClient.newCall(httpRequest).execute();
|
||||
// 获取官方规则文件,在线更新写入
|
||||
URL url = new URL("https://cdn.jsdelivr.net/gh/gh0stkey/HaE@gh-pages/Rules.yml");
|
||||
IHttpService iHttpService = BurpExtender.helpers.buildHttpService(url.getHost(), 443, true);
|
||||
IHttpRequestResponse iHttpRequestResponse = BurpExtender.callbacks.makeHttpRequest(iHttpService, BurpExtender.helpers.buildHttpRequest(url));
|
||||
byte[] responseByte = iHttpRequestResponse.getResponse();
|
||||
IResponseInfo iResponseInfo = BurpExtender.helpers.analyzeResponse(responseByte);
|
||||
int bodyOffset = iResponseInfo.getBodyOffset();
|
||||
byte[] responseBodyByte = Arrays.copyOfRange(responseByte, bodyOffset, responseByte.length);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(this.rulesFilePath);
|
||||
fileOutputStream.write(httpResponse.body().bytes());
|
||||
JOptionPane.showMessageDialog(null, "Config file updated successfully!", "Error",
|
||||
fileOutputStream.write(responseBodyByte);
|
||||
fileOutputStream.close();
|
||||
JOptionPane.showMessageDialog(null, "Rules update successfully!", "Info",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (Exception ignored) {
|
||||
JOptionPane.showMessageDialog(null, "Please check your network!", "Error",
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(null, e, "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
try {
|
||||
t.join();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package burp.rule.utils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import java.io.FileInputStream;
|
||||
@@ -23,13 +26,11 @@ public class YamlTool {
|
||||
|
||||
public static Map<String, Object> loadYaml(String filePath) {
|
||||
try {
|
||||
InputStream inputStream = new FileInputStream(filePath);
|
||||
Yaml yaml = newStandardYaml();
|
||||
return yaml.load(inputStream);
|
||||
} catch (FileNotFoundException e) {
|
||||
InputStream inputStream = Files.newInputStream(Paths.get(filePath));
|
||||
return newStandardYaml().load(inputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package burp.ui;
|
||||
import burp.config.ConfigEntry;
|
||||
import burp.config.ConfigLoader;
|
||||
import burp.rule.RuleProcessor;
|
||||
import burp.rule.utils.RuleTool;
|
||||
import burp.ui.board.Databoard;
|
||||
import burp.ui.board.MessagePanel;
|
||||
import burp.ui.rule.RulePane;
|
||||
@@ -21,7 +20,6 @@ import java.util.Map;
|
||||
*/
|
||||
|
||||
public class MainUI extends JPanel {
|
||||
private final ConfigLoader loadConn = new ConfigLoader();
|
||||
private MessagePanel messagePanel;
|
||||
|
||||
public MainUI(MessagePanel messagePanel) {
|
||||
@@ -41,13 +39,9 @@ public class MainUI extends JPanel {
|
||||
|
||||
private void onlineUpdateActionPerformed(ActionEvent e) {
|
||||
// 添加提示框防止用户误触导致配置更新
|
||||
int retCode = JOptionPane.showConfirmDialog(null, "Do you want to update config?", "Info",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
int retCode = JOptionPane.showConfirmDialog(null, "Do you want to update rules?", "Info", JOptionPane.YES_NO_OPTION);
|
||||
if (retCode == JOptionPane.YES_OPTION) {
|
||||
String rulesFilePath = rulesPathTextField.getText();
|
||||
RuleTool rt = new RuleTool(rulesFilePath);
|
||||
rt.getRulesFromSite();
|
||||
new ConfigLoader();
|
||||
ConfigLoader.initRules();
|
||||
reloadRule();
|
||||
}
|
||||
}
|
||||
@@ -61,7 +55,6 @@ public class MainUI extends JPanel {
|
||||
i,
|
||||
new RulePane(rules.get(i), ruleTabbedPane)
|
||||
)
|
||||
|
||||
);
|
||||
ruleTabbedPane.addTab("...", new JLabel());
|
||||
ruleSwitch.setListen(true);
|
||||
@@ -72,8 +65,7 @@ public class MainUI extends JPanel {
|
||||
}
|
||||
|
||||
private void excludeSuffixSaveActionPerformed(ActionEvent e) {
|
||||
ConfigLoader loadCon = new ConfigLoader();
|
||||
loadCon.setExcludeSuffix(excludeSuffixTextField.getText());
|
||||
ConfigLoader.setExcludeSuffix(excludeSuffixTextField.getText());
|
||||
}
|
||||
private void initComponents() {
|
||||
JTabbedPane mainTabbedPane = new JTabbedPane();
|
||||
@@ -154,7 +146,7 @@ public class MainUI extends JPanel {
|
||||
ruleTabbedPane.addTab("...",new JLabel());
|
||||
|
||||
rulesPathTextField.setText(ConfigLoader.getRulesFilePath());
|
||||
excludeSuffixTextField.setText(loadConn.getExcludeSuffix());
|
||||
excludeSuffixTextField.setText(ConfigLoader.getExcludeSuffix());
|
||||
ruleSwitch = new TabTitleEditListener(ruleTabbedPane);
|
||||
ruleTabbedPane.addChangeListener(ruleSwitch);
|
||||
ruleTabbedPane.addMouseListener(ruleSwitch);
|
||||
|
||||
@@ -8,23 +8,24 @@ import java.util.Map;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
public class CustomTableCellRenderer extends DefaultTableCellRenderer {
|
||||
public class ColorRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
private List<LogEntry> log;
|
||||
private Map<String, Color> colorMap = new HashMap<>();
|
||||
private JTable table; // 保存对表格的引用
|
||||
|
||||
public CustomTableCellRenderer(List<LogEntry> log, JTable table) {
|
||||
public ColorRenderer(List<LogEntry> log, JTable table) {
|
||||
this.log = log;
|
||||
this.colorMap.put("red", Color.RED);
|
||||
this.colorMap.put("orange", Color.ORANGE);
|
||||
this.colorMap.put("yellow", Color.YELLOW);
|
||||
this.colorMap.put("green", Color.GREEN);
|
||||
this.colorMap.put("cyan", Color.CYAN);
|
||||
this.colorMap.put("blue", Color.BLUE);
|
||||
this.colorMap.put("pink", Color.PINK);
|
||||
this.colorMap.put("magenta", Color.MAGENTA);
|
||||
this.colorMap.put("gray", Color.GRAY);
|
||||
// 与BurpSuite的颜色保持一致
|
||||
this.colorMap.put("red", new Color(0xFF, 0x64, 0x64));
|
||||
this.colorMap.put("orange", new Color(0xFF, 0xC8, 0x64));
|
||||
this.colorMap.put("yellow", new Color(0xFF, 0xFF, 0x64));
|
||||
this.colorMap.put("green", new Color(0x64, 0xFF, 0x64));
|
||||
this.colorMap.put("cyan", new Color(0x64, 0xFF, 0xFF));
|
||||
this.colorMap.put("blue", new Color(0x64, 0x64, 0xFF));
|
||||
this.colorMap.put("pink", new Color(0xFF, 0xC8, 0xC8));
|
||||
this.colorMap.put("magenta", new Color(0xFF, 0x64, 0xFF));
|
||||
this.colorMap.put("gray", new Color(0xB4, 0xB4, 0xB4));
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
@@ -40,13 +41,15 @@ public class CustomTableCellRenderer extends DefaultTableCellRenderer {
|
||||
Color color = colorMap.get(colorByLog);
|
||||
|
||||
if (isSelected) {
|
||||
// 如果行被选中,设置阴影颜色
|
||||
component.setBackground(new Color(173, 216, 230)); // Light Blue
|
||||
// 通过更改RGB颜色来达成阴影效果
|
||||
component.setBackground(new Color(color.getRed()-0x20, color.getGreen()-0x20, color.getBlue()-0x20));
|
||||
} else {
|
||||
// 否则使用原始颜色
|
||||
component.setBackground(color);
|
||||
}
|
||||
|
||||
component.setForeground(Color.BLACK);
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,8 @@ package burp.ui.board;
|
||||
import burp.config.ConfigEntry;
|
||||
import burp.core.utils.StringHelper;
|
||||
import burp.ui.board.MessagePanel.Table;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
@@ -15,8 +14,7 @@ import javax.swing.table.TableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
@@ -48,6 +46,9 @@ public class Databoard extends JPanel {
|
||||
}
|
||||
|
||||
private void clearActionPerformed(ActionEvent e) {
|
||||
int retCode = JOptionPane.showConfirmDialog(null, "Do you want to clear data?", "Info",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (retCode == JOptionPane.YES_OPTION) {
|
||||
cleanUI();
|
||||
|
||||
String host = hostTextField.getText();
|
||||
@@ -61,7 +62,7 @@ public class Databoard extends JPanel {
|
||||
|
||||
messagePanel.deleteByHost(cleanedHost);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
@@ -115,6 +116,7 @@ public class Databoard extends JPanel {
|
||||
final JComboBox hostComboBox = new JComboBox(comboBoxModel) {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
setMaximumRowCount(5);
|
||||
return new Dimension(super.getPreferredSize().width, 0);
|
||||
}
|
||||
};
|
||||
@@ -130,8 +132,9 @@ public class Databoard extends JPanel {
|
||||
hostComboBox.addActionListener(e -> {
|
||||
if (!isMatchHost) {
|
||||
if (hostComboBox.getSelectedItem() != null) {
|
||||
hostTextField.setText(hostComboBox.getSelectedItem().toString());
|
||||
populateTabbedPaneByHost(hostComboBox);
|
||||
String selectedHost = hostComboBox.getSelectedItem().toString();
|
||||
hostTextField.setText(selectedHost);
|
||||
populateTabbedPaneByHost(selectedHost);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -154,7 +157,7 @@ public class Databoard extends JPanel {
|
||||
if (keyCode == KeyEvent.VK_ENTER) {
|
||||
String selectedItem = hostComboBox.getSelectedItem().toString();
|
||||
hostTextField.setText(selectedItem);
|
||||
populateTabbedPaneByHost(hostComboBox);
|
||||
populateTabbedPaneByHost(selectedItem);
|
||||
hostComboBox.setPopupVisible(false);
|
||||
return;
|
||||
}
|
||||
@@ -172,7 +175,6 @@ public class Databoard extends JPanel {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
updateList();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,9 +195,9 @@ public class Databoard extends JPanel {
|
||||
for (String host : getHostByList()) {
|
||||
String lowerCaseHost = host.toLowerCase();
|
||||
if (lowerCaseHost.contains(input)) {
|
||||
if (host.length() == input.length()){
|
||||
comboBoxModel.insertElementAt(host,0);
|
||||
comboBoxModel.setSelectedItem(host);
|
||||
if (lowerCaseHost.equals(input)) {
|
||||
comboBoxModel.insertElementAt(lowerCaseHost, 0);
|
||||
comboBoxModel.setSelectedItem(lowerCaseHost);
|
||||
} else {
|
||||
comboBoxModel.addElement(host);
|
||||
}
|
||||
@@ -225,9 +227,8 @@ public class Databoard extends JPanel {
|
||||
messagePanel.applyHostFilter(filterText);
|
||||
}
|
||||
|
||||
private void populateTabbedPaneByHost(JComboBox<String> hostComboBox) {
|
||||
if (hostComboBox.getSelectedItem() != null) {
|
||||
String selectedHost = hostComboBox.getSelectedItem().toString();
|
||||
private void populateTabbedPaneByHost(String selectedHost) {
|
||||
if (!Objects.equals(selectedHost, "")) {
|
||||
Map<String, Map<String, List<String>>> dataMap = ConfigEntry.globalDataMap;
|
||||
Map<String, List<String>> selectedDataMap;
|
||||
|
||||
@@ -281,7 +282,7 @@ public class Databoard extends JPanel {
|
||||
for (Map.Entry<String, List<String>> entrySet : entry.getValue().entrySet()) {
|
||||
Thread t = new Thread(() -> {
|
||||
String tabTitle = String.format("%s (%s)", entrySet.getKey(), entrySet.getValue().size());
|
||||
newTabbedPane.addTab(tabTitle, new JScrollPane(new DataTable(entrySet.getKey(), entrySet.getValue())));
|
||||
newTabbedPane.addTab(tabTitle, new DataTable(entrySet.getKey(), entrySet.getValue()));
|
||||
dataTabbedPaneA.addTab(entry.getKey(), newTabbedPane);
|
||||
});
|
||||
t.start();
|
||||
@@ -299,7 +300,7 @@ public class Databoard extends JPanel {
|
||||
splitPane.setLeftComponent(dataTabbedPaneB);
|
||||
for (Map.Entry<String, List<String>> entry : selectedDataMap.entrySet()) {
|
||||
String tabTitle = String.format("%s (%s)", entry.getKey(), entry.getValue().size());
|
||||
dataTabbedPaneB.addTab(tabTitle, new JScrollPane(new DataTable(entry.getKey(), entry.getValue())));
|
||||
dataTabbedPaneB.addTab(tabTitle, new DataTable(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,31 +329,100 @@ public class Databoard extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
class DataTable extends JPanel {
|
||||
private final JTable table;
|
||||
private final DefaultTableModel model;
|
||||
private final JTextField searchField;
|
||||
private TableRowSorter<DefaultTableModel> sorter;
|
||||
|
||||
class DataTable extends JTable {
|
||||
public DataTable(String tableName, List<String> list){
|
||||
DefaultTableModel model = new DefaultTableModel();
|
||||
Object[][] data = new Object[list.size()][1];
|
||||
for (int x = 0; x < list.size(); x++) {
|
||||
data[x][0] = list.get(x);
|
||||
}
|
||||
model.setDataVector(data, new Object[]{"Information"});
|
||||
setAutoCreateRowSorter(true);
|
||||
setModel(model);
|
||||
setDefaultEditor(Object.class, null);
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public DataTable(String tableName, List<String> list) {
|
||||
model = new DefaultTableModel();
|
||||
table = new JTable(model);
|
||||
sorter = new TableRowSorter<>(model);
|
||||
|
||||
table.setRowSorter(sorter);
|
||||
table.setDefaultEditor(Object.class, null);
|
||||
|
||||
// 表格内容双击事件
|
||||
table.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
int selectedRow = getSelectedRow();
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (selectedRow != -1) {
|
||||
String rowData = getValueAt(selectedRow, 0).toString();
|
||||
String rowData = table.getValueAt(selectedRow, 0).toString();
|
||||
messagePanel.applyMessageFilter(tableName, rowData);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
model.addColumn("Information");
|
||||
for (String item : list) {
|
||||
model.addRow(new Object[]{item});
|
||||
}
|
||||
|
||||
String defaultText = "Search";
|
||||
|
||||
searchField = new JTextField(defaultText);
|
||||
// 设置灰色默认文本Search
|
||||
searchField.setForeground(Color.GRAY);
|
||||
searchField.addFocusListener(new FocusListener() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
if (searchField.getText().equals(defaultText)) {
|
||||
searchField.setText("");
|
||||
searchField.setForeground(Color.BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
if (searchField.getText().isEmpty()) {
|
||||
searchField.setForeground(Color.GRAY);
|
||||
searchField.setText(defaultText);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 监听输入框内容输入、更新、删除
|
||||
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
performSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
performSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
performSearch();
|
||||
}
|
||||
|
||||
private void performSearch() {
|
||||
// 通过字体颜色来判断是否可以进行过滤
|
||||
if (searchField.getForeground() == Color.BLACK) {
|
||||
String searchText = searchField.getText();
|
||||
if (sorter == null) {
|
||||
sorter = new TableRowSorter<>(model);
|
||||
table.setRowSorter(sorter);
|
||||
}
|
||||
RowFilter<DefaultTableModel, Object> rowFilter = RowFilter.regexFilter(searchText, 0);
|
||||
sorter.setRowFilter(rowFilter);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 设置布局
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
|
||||
setLayout(new BorderLayout(0, 5));
|
||||
add(scrollPane, BorderLayout.CENTER);
|
||||
add(searchField, BorderLayout.SOUTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,18 @@ public class LogEntry {
|
||||
private final IHttpRequestResponsePersisted requestResponse;
|
||||
private final URL url;
|
||||
private final String length;
|
||||
private final String status;
|
||||
private final String color;
|
||||
private final String method;
|
||||
|
||||
LogEntry(IHttpRequestResponsePersisted requestResponse, String method, URL url, String comment, String length, String color) {
|
||||
LogEntry(IHttpRequestResponsePersisted requestResponse, String method, URL url, String comment, String length, String color, String status) {
|
||||
this.requestResponse = requestResponse;
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
this.comment = comment;
|
||||
this.length = length;
|
||||
this.color = color;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
@@ -41,6 +43,10 @@ public class LogEntry {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public IHttpRequestResponsePersisted getRequestResponse() {
|
||||
return this.requestResponse;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,14 @@ import burp.IHttpRequestResponsePersisted;
|
||||
import burp.IHttpService;
|
||||
import burp.IMessageEditor;
|
||||
import burp.IMessageEditorController;
|
||||
import burp.IRequestInfo;
|
||||
import burp.config.ConfigEntry;
|
||||
import burp.core.utils.HashCalculator;
|
||||
import burp.core.utils.StringHelper;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
@@ -46,7 +52,7 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
||||
|
||||
logTable = new Table(MessagePanel.this);
|
||||
logTable.setDefaultRenderer(Object.class, new CustomTableCellRenderer(filteredLog, logTable));
|
||||
logTable.setDefaultRenderer(Object.class, new ColorRenderer(filteredLog, logTable));
|
||||
logTable.setAutoCreateRowSorter(true);
|
||||
|
||||
// Length字段根据大小进行排序
|
||||
@@ -115,7 +121,7 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
@Override
|
||||
public int getColumnCount()
|
||||
{
|
||||
return 5;
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,8 +136,10 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
case 2:
|
||||
return "Comment";
|
||||
case 3:
|
||||
return "Length";
|
||||
return "Status";
|
||||
case 4:
|
||||
return "Length";
|
||||
case 5:
|
||||
return "Color";
|
||||
default:
|
||||
return "";
|
||||
@@ -157,8 +165,10 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
case 2:
|
||||
return logEntry.getComment();
|
||||
case 3:
|
||||
return logEntry.getLength();
|
||||
return logEntry.getStatus();
|
||||
case 4:
|
||||
return logEntry.getLength();
|
||||
case 5:
|
||||
return logEntry.getColor();
|
||||
default:
|
||||
return "";
|
||||
@@ -184,15 +194,18 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
byte[] requestByte = requestResponse.getRequest();
|
||||
byte[] responseByte = requestResponse.getResponse();
|
||||
|
||||
String requestString = new String(requestResponse.getRequest(), StandardCharsets.UTF_8);
|
||||
String responseString = new String(requestResponse.getResponse(), StandardCharsets.UTF_8);
|
||||
|
||||
List<String> requestTmpHeaders = helpers.analyzeRequest(requestByte).getHeaders();
|
||||
byte[] requestHeaders = helpers.stringToBytes(String.join("\n", requestTmpHeaders));
|
||||
String requestHeaders = new String(String.join("\n", requestTmpHeaders).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
|
||||
int requestBodyOffset = helpers.analyzeRequest(requestByte).getBodyOffset();
|
||||
byte[] requestBody = Arrays.copyOfRange(requestByte, requestBodyOffset, requestByte.length);
|
||||
String requestBody = new String(Arrays.copyOfRange(requestByte, requestBodyOffset, requestByte.length), StandardCharsets.UTF_8);
|
||||
|
||||
List<String> responseTmpHeaders = helpers.analyzeResponse(responseByte).getHeaders();
|
||||
byte[] responseHeaders = helpers.stringToBytes(String.join("\n", responseTmpHeaders));
|
||||
String responseHeaders = new String(String.join("\n", responseTmpHeaders).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
|
||||
int responseBodyOffset = helpers.analyzeResponse(responseByte).getBodyOffset();
|
||||
byte[] responseBody = Arrays.copyOfRange(responseByte, responseBodyOffset, responseByte.length);
|
||||
String responseBody = new String(Arrays.copyOfRange(responseByte, responseBodyOffset, responseByte.length), StandardCharsets.UTF_8);
|
||||
|
||||
final boolean[] isMatched = {false}; // 标志变量,表示是否满足过滤条件
|
||||
|
||||
@@ -205,31 +218,31 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
|
||||
switch (scope) {
|
||||
case "any":
|
||||
match = helpers.indexOf(requestByte, helpers.stringToBytes(filterText), true, 0, requestByte.length) != -1 || helpers.indexOf(responseByte, helpers.stringToBytes(filterText), true, 0, responseByte.length) != -1;
|
||||
match = requestString.contains(filterText) || responseString.contains(filterText);
|
||||
break;
|
||||
case "request":
|
||||
match = helpers.indexOf(requestByte, helpers.stringToBytes(filterText), true, 0, requestByte.length) != -1;
|
||||
match = requestString.contains(filterText);
|
||||
break;
|
||||
case "response":
|
||||
match = helpers.indexOf(responseByte, helpers.stringToBytes(filterText), true, 0, responseByte.length) != -1;
|
||||
match = responseString.contains(filterText);
|
||||
break;
|
||||
case "any header":
|
||||
match = helpers.indexOf(requestHeaders, helpers.stringToBytes(filterText), true, 0, requestHeaders.length) != -1 || helpers.indexOf(responseHeaders, helpers.stringToBytes(filterText), true, 0, responseHeaders.length) != -1;
|
||||
match = requestHeaders.contains(filterText) || responseHeaders.contains(filterText);
|
||||
break;
|
||||
case "request header":
|
||||
match = helpers.indexOf(requestHeaders, helpers.stringToBytes(filterText), true, 0, requestHeaders.length) != -1;
|
||||
match = requestHeaders.contains(filterText);
|
||||
break;
|
||||
case "response header":
|
||||
match = helpers.indexOf(responseHeaders, helpers.stringToBytes(filterText), true, 0, responseHeaders.length) != -1;
|
||||
match = responseHeaders.contains(filterText);
|
||||
break;
|
||||
case "any body":
|
||||
match = helpers.indexOf(requestBody, helpers.stringToBytes(filterText), true, 0, requestBody.length) != -1 || helpers.indexOf(responseBody, helpers.stringToBytes(filterText), true, 0, responseBody.length) != -1;
|
||||
match = requestBody.contains(filterText) || responseBody.contains(filterText);
|
||||
break;
|
||||
case "request body":
|
||||
match = helpers.indexOf(requestBody, helpers.stringToBytes(filterText), true, 0, requestBody.length) != -1;
|
||||
match = requestBody.contains(filterText);
|
||||
break;
|
||||
case "response body":
|
||||
match = helpers.indexOf(responseBody, helpers.stringToBytes(filterText), true, 0, responseBody.length) != -1;
|
||||
match = responseBody.contains(filterText);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -291,12 +304,56 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
}
|
||||
|
||||
public void add(IHttpRequestResponse messageInfo, String comment, String length, String color) {
|
||||
synchronized(log)
|
||||
{
|
||||
LogEntry logEntry = new LogEntry(callbacks.saveBuffersToTempFiles(messageInfo), helpers.analyzeRequest(messageInfo).getMethod(),
|
||||
helpers.analyzeRequest(messageInfo).getUrl(), comment, length, color);
|
||||
synchronized(log) {
|
||||
IRequestInfo iRequestInfo = helpers.analyzeRequest(messageInfo);
|
||||
URL url = iRequestInfo.getUrl();
|
||||
String method = iRequestInfo.getMethod();
|
||||
String status = String.valueOf(helpers.analyzeResponse(messageInfo.getResponse()).getStatusCode());
|
||||
|
||||
LogEntry logEntry = new LogEntry(callbacks.saveBuffersToTempFiles(messageInfo), method, url, comment, length, color, status);
|
||||
|
||||
try {
|
||||
// 比较Hash,如若存在重复的请求或响应,则不放入消息内容里
|
||||
String reqHashA = getMessageHash(true, messageInfo.getRequest());
|
||||
String resHashA = getMessageHash(false, messageInfo.getResponse());
|
||||
boolean isDuplicate = false;
|
||||
|
||||
for (LogEntry entry : log) {
|
||||
IHttpRequestResponsePersisted reqResMessage = entry.getRequestResponse();
|
||||
String reqHashB = getMessageHash(true, reqResMessage.getRequest());
|
||||
String resHashB = getMessageHash(false, reqResMessage.getResponse());
|
||||
|
||||
if (reqHashB.equals(reqHashA) || resHashB.equals(resHashA)) {
|
||||
if (entry.getComment().equals(comment)) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDuplicate) {
|
||||
log.add(logEntry);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getMessageHash(boolean isRequest, byte[] content)
|
||||
throws NoSuchAlgorithmException {
|
||||
String hash = "";
|
||||
|
||||
if (isRequest) {
|
||||
hash = HashCalculator.calculateHash(content);
|
||||
} else {
|
||||
int responseBodyOffset = helpers.analyzeResponse(content).getBodyOffset();
|
||||
byte[] responseBody = Arrays.copyOfRange(content, responseBodyOffset, content.length);
|
||||
hash = HashCalculator.calculateHash(responseBody);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
public class Table extends JTable {
|
||||
@@ -309,6 +366,8 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
|
||||
@Override
|
||||
public void changeSelection(int row, int col, boolean toggle, boolean extend) {
|
||||
super.changeSelection(row, col, toggle, extend);
|
||||
|
||||
logEntry = filteredLog.get(convertRowIndexToModel(row));
|
||||
requestViewer.setMessage("Loading...".getBytes(), true);
|
||||
responseViewer.setMessage("Loading...".getBytes(), false);
|
||||
@@ -330,10 +389,9 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
currentWorker = worker;
|
||||
// 启动后台线程
|
||||
worker.execute();
|
||||
super.changeSelection(row, col, toggle, extend);
|
||||
}
|
||||
|
||||
private void refreshMessage() {
|
||||
private synchronized void refreshMessage() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
requestViewer.setMessage(logEntry.getRequestResponse().getRequest(), true);
|
||||
responseViewer.setMessage(logEntry.getRequestResponse().getResponse(), false);
|
||||
@@ -342,4 +400,3 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user