Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
765807de6e | ||
|
|
548315e163 | ||
|
|
d3ab207825 | ||
|
|
44260dd4ff | ||
|
|
cf3ac4978f | ||
|
|
9c8dad8ac0 | ||
|
|
5cd216e45d | ||
|
|
87c5f713fa | ||
|
|
a0946bb723 | ||
|
|
bcb5177b54 | ||
|
|
0225c00f69 | ||
|
|
eafae602b8 |
27
.github/ISSUE_TEMPLATE/问题反馈.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/问题反馈.md
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: 问题反馈
|
||||||
|
about: 尽可能详细的描述问题并反馈
|
||||||
|
title: "[BUG] "
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 使用环境
|
||||||
|
|
||||||
|
```
|
||||||
|
HaE版本:
|
||||||
|
BurpSuite版本:
|
||||||
|
JDK版本:
|
||||||
|
操作系统版本:
|
||||||
|
```
|
||||||
|
|
||||||
|
## 问题详情
|
||||||
|
|
||||||
|
问题描述:
|
||||||
|
|
||||||
|
出现的场景:
|
||||||
|
|
||||||
|
## 解决建议
|
||||||
|
|
||||||
|
无。
|
||||||
16
README.md
16
README.md
@@ -23,6 +23,22 @@
|
|||||||
|
|
||||||
除此之外,您也可以选择将配置文件存放在`HaE Jar包`的同级目录下的`/.config/HaE/`中,**以便于离线携带**。
|
除此之外,您也可以选择将配置文件存放在`HaE Jar包`的同级目录下的`/.config/HaE/`中,**以便于离线携带**。
|
||||||
|
|
||||||
|
### 规则释义
|
||||||
|
|
||||||
|
HaE目前的规则一共有6个字段,分别是规则名称、规则正则、规则作用域、正则引擎、规则匹配颜色、规则敏感性。
|
||||||
|
|
||||||
|
详细的含义如下所示:
|
||||||
|
|
||||||
|
| 字段 | 含义 |
|
||||||
|
|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| Name | 规则名称,主要用于简短概括当前规则的作用。 |
|
||||||
|
| Regex | 规则正则,主要用于填写正则表达式。在HaE中所需提取匹配的内容需要用`(`、`)`将正则表达式进行包裹。 |
|
||||||
|
| Scope | 规则作用域,主要用于表示当前规则作用与HTTP报文的哪个部分。 |
|
||||||
|
| Engine | 正则引擎,主要用于表示当前规则的正则表达式所使用的引擎。**DFA引擎**:对于文本串里的每一个字符只需扫描一次,速度快、特性少;**NFA引擎**:要翻来覆去标注字符、取消标注字符,速度慢,但是特性(如:分组、替换、分割)丰富。 |
|
||||||
|
| Color | 规则匹配颜色,主要用于表示当前规则匹配到对应HTTP报文时所需标记的高亮颜色。 |
|
||||||
|
| Sensitive | 规则敏感性,主要用于表示当前规则对于大小写字母是否敏感,敏感(`True`)则严格按照大小写要求匹配,不敏感(`False`)则反之。 |
|
||||||
|
|
||||||
|
|
||||||
## 优势特点
|
## 优势特点
|
||||||
|
|
||||||
1. 精细配置:高度自由的配置选项,以满足各类精细化场景需求。
|
1. 精细配置:高度自由的配置选项,以满足各类精细化场景需求。
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import burp.config.ConfigLoader;
|
|||||||
import burp.core.processor.ColorProcessor;
|
import burp.core.processor.ColorProcessor;
|
||||||
import burp.core.processor.MessageProcessor;
|
import burp.core.processor.MessageProcessor;
|
||||||
import burp.ui.MainUI;
|
import burp.ui.MainUI;
|
||||||
|
import burp.ui.board.DatatablePanel;
|
||||||
import burp.ui.board.MessagePanel;
|
import burp.ui.board.MessagePanel;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -38,7 +38,7 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
|
|
||||||
new ConfigLoader();
|
new ConfigLoader();
|
||||||
|
|
||||||
String version = "2.5.4";
|
String version = "2.5.8";
|
||||||
callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version));
|
callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version));
|
||||||
|
|
||||||
// 定义输出
|
// 定义输出
|
||||||
@@ -120,42 +120,18 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo) {
|
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo) {
|
||||||
// 判断是否是响应,且该代码作用域为:REPEATER、INTRUDER、PROXY(分别对应toolFlag 64、32、4)
|
// 判断是否是响应,且该代码作用域为:REPEATER、INTRUDER、PROXY(分别对应toolFlag 64、32、4)
|
||||||
if (toolFlag == 64 || toolFlag == 32 || toolFlag == 4) {
|
if (toolFlag == 64 || toolFlag == 32 || toolFlag == 4) {
|
||||||
byte[] content;
|
if (!messageIsRequest) {
|
||||||
|
IHttpService iHttpService = messageInfo.getHttpService();
|
||||||
if (messageIsRequest) {
|
String host = iHttpService.getHost();
|
||||||
content = messageInfo.getRequest();
|
|
||||||
} else {
|
|
||||||
content = messageInfo.getResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
IHttpService iHttpService = null;
|
|
||||||
|
|
||||||
String host = "";
|
|
||||||
|
|
||||||
try {
|
|
||||||
iHttpService = messageInfo.getHttpService();
|
|
||||||
host = iHttpService.getHost();
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Objects.equals(host, "")) {
|
|
||||||
List<String> requestTmpHeaders = helpers.analyzeRequest(content).getHeaders();
|
|
||||||
host = requestTmpHeaders.get(1).split(":")[1].trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Map<String, String>> result = null;
|
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 originalColor = messageInfo.getHighlight();
|
||||||
String originalComment = messageInfo.getComment();
|
String originalComment = messageInfo.getComment();
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = messageProcessor.processMessage(helpers, messageInfo, host, true);
|
||||||
|
|
||||||
if (result != null && !result.isEmpty() && result.size() > 0) {
|
if (result != null && !result.isEmpty() && result.size() > 0) {
|
||||||
List<String> colorList = new ArrayList<>();
|
List<String> colorList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -164,21 +140,21 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
}
|
}
|
||||||
|
|
||||||
colorList.add(result.get(0).get("color"));
|
colorList.add(result.get(0).get("color"));
|
||||||
resColor = colorProcessor.retrieveFinalColor(colorProcessor.retrieveColorIndices(colorList));
|
String resColor = colorProcessor.retrieveFinalColor(colorProcessor.retrieveColorIndices(colorList));
|
||||||
messageInfo.setHighlight(resColor);
|
messageInfo.setHighlight(resColor);
|
||||||
|
|
||||||
String addComment = String.join(", ", result.get(1).get("comment"));
|
String addComment = String.join(", ", result.get(1).get("comment"));
|
||||||
String allComment = !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);
|
String resComment = mergeComment(allComment);
|
||||||
messageInfo.setComment(resComment);
|
messageInfo.setComment(resComment);
|
||||||
|
|
||||||
|
messagePanel.add(messageInfo, resComment, resColor);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String endComment = resComment.isEmpty() ? originalComment : resComment;
|
|
||||||
String endColor = resColor.isEmpty() ? originalColor : resColor;
|
|
||||||
|
|
||||||
if (!messageIsRequest && !Objects.equals(endComment, "") && !Objects.equals(endColor, "")) {
|
|
||||||
messagePanel.add(messageInfo, endComment, String.valueOf(content.length), endColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +193,8 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
|
|
||||||
class MarkInfoTab implements IMessageEditorTab {
|
class MarkInfoTab implements IMessageEditorTab {
|
||||||
private final JTabbedPane jTabbedPane = new JTabbedPane();
|
private final JTabbedPane jTabbedPane = new JTabbedPane();
|
||||||
private JTable jTable = new JTable();
|
private DatatablePanel dataPanel;
|
||||||
|
private JTable dataTable;
|
||||||
private final IMessageEditorController controller;
|
private final IMessageEditorController controller;
|
||||||
private Map<String, String> extractRequestMap;
|
private Map<String, String> extractRequestMap;
|
||||||
private Map<String, String> extractResponseMap;
|
private Map<String, String> extractResponseMap;
|
||||||
@@ -237,10 +214,10 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
jTabbedPane.addChangeListener(new ChangeListener() {
|
jTabbedPane.addChangeListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent arg0) {
|
public void stateChanged(ChangeEvent arg0) {
|
||||||
jTable = (JTable) ((JScrollPane)jTabbedPane.getSelectedComponent()).getViewport().getView();
|
dataTable = ((DatatablePanel)jTabbedPane.getSelectedComponent()).getTable();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return this.jTabbedPane;
|
return jTabbedPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -248,9 +225,13 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
List<Map<String, String>> result = null;
|
List<Map<String, String>> result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = messageProcessor.processMessage(helpers, content, isRequest, false, "");
|
if (isRequest) {
|
||||||
} catch (NoSuchAlgorithmException e) {
|
result = messageProcessor.processRequestMessage(helpers, content, "", false);
|
||||||
throw new RuntimeException(e);
|
} else {
|
||||||
|
result = messageProcessor.processResponseMessage(helpers, content, "", false);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != null && !result.isEmpty()) {
|
if (result != null && !result.isEmpty()) {
|
||||||
@@ -262,6 +243,7 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,15 +262,7 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] getSelectedData() {
|
public byte[] getSelectedData() {
|
||||||
int[] selectRows = jTable.getSelectedRows();
|
return helpers.stringToBytes(dataPanel.getSelectedData(dataTable));
|
||||||
StringBuilder selectData = new StringBuilder();
|
|
||||||
for (int row : selectRows) {
|
|
||||||
selectData.append(jTable.getValueAt(row, 0).toString()).append("\n");
|
|
||||||
}
|
|
||||||
// 便于单行复制,去除最后一个换行符
|
|
||||||
String revData = selectData.reverse().toString().replaceFirst("\n", "");
|
|
||||||
StringBuilder retData = new StringBuilder(revData).reverse();
|
|
||||||
return helpers.stringToBytes(retData.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,18 +284,12 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
*/
|
*/
|
||||||
public void makeTable(Map<String, String> dataMap) {
|
public void makeTable(Map<String, String> dataMap) {
|
||||||
ArrayList<String> lTitleList = new ArrayList<>();
|
ArrayList<String> lTitleList = new ArrayList<>();
|
||||||
|
|
||||||
dataMap.keySet().forEach(i->{
|
dataMap.keySet().forEach(i->{
|
||||||
String[] extractData = dataMap.get(i).split("\n");
|
String[] extractData = dataMap.get(i).split("\n");
|
||||||
Object[][] data = new Object[extractData.length][1];
|
|
||||||
for (int x = 0; x < extractData.length; x++) {
|
|
||||||
data[x][0] = extractData[x];
|
|
||||||
}
|
|
||||||
JTable infoTable = new JTable(data, new Object[]{"Information"});
|
|
||||||
infoTable.setAutoCreateRowSorter(true);
|
|
||||||
JScrollPane jScrollPane = new JScrollPane(infoTable);
|
|
||||||
|
|
||||||
lTitleList.add(i);
|
lTitleList.add(i);
|
||||||
this.jTabbedPane.addTab(i, jScrollPane);
|
dataPanel = new DatatablePanel(i, Arrays.asList(extractData));
|
||||||
|
jTabbedPane.addTab(i, dataPanel);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -329,9 +297,9 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
|
|||||||
* 采用全局ArrayList的方式遍历删除Tab,以此应对BurpSuite缓存机制导致的MarkInfo UI错误展示。
|
* 采用全局ArrayList的方式遍历删除Tab,以此应对BurpSuite缓存机制导致的MarkInfo UI错误展示。
|
||||||
*/
|
*/
|
||||||
titleList.forEach(t->{
|
titleList.forEach(t->{
|
||||||
int indexOfTab = this.jTabbedPane.indexOfTab(t);
|
int indexOfTab = jTabbedPane.indexOfTab(t);
|
||||||
if (indexOfTab != -1) {
|
if (indexOfTab != -1) {
|
||||||
this.jTabbedPane.removeTabAt(indexOfTab);
|
jTabbedPane.removeTabAt(indexOfTab);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package burp.core.processor;
|
package burp.core.processor;
|
||||||
|
|
||||||
import burp.BurpExtender;
|
|
||||||
import burp.core.GlobalCachePool;
|
import burp.core.GlobalCachePool;
|
||||||
import burp.core.utils.HashCalculator;
|
import burp.core.utils.HashCalculator;
|
||||||
import burp.core.utils.MatchTool;
|
import burp.core.utils.MatchTool;
|
||||||
@@ -57,10 +56,9 @@ public class DataProcessingUnit {
|
|||||||
} else {
|
} else {
|
||||||
// 最终返回的结果
|
// 最终返回的结果
|
||||||
Map<String, Map<String, Object>> finalMap = new HashMap<>();
|
Map<String, Map<String, Object>> finalMap = new HashMap<>();
|
||||||
ConfigEntry.globalRules.keySet().forEach(i -> {
|
ConfigEntry.globalRules.keySet().parallelStream().forEach(i -> {
|
||||||
for (Object[] objects : ConfigEntry.globalRules.get(i)) {
|
for (Object[] objects : ConfigEntry.globalRules.get(i)) {
|
||||||
// 多线程执行,一定程度上减少阻塞现象
|
// 多线程执行,一定程度上减少阻塞现象
|
||||||
Thread t = new Thread(() -> {
|
|
||||||
String matchContent = "";
|
String matchContent = "";
|
||||||
// 遍历获取规则
|
// 遍历获取规则
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
@@ -134,7 +132,7 @@ public class DataProcessingUnit {
|
|||||||
tmpMap.put("data", dataStr);
|
tmpMap.put("data", dataStr);
|
||||||
finalMap.put(nameAndSize, tmpMap);
|
finalMap.put(nameAndSize, tmpMap);
|
||||||
// 添加到全局变量中,便于Databoard检索
|
// 添加到全局变量中,便于Databoard检索
|
||||||
if (!Objects.equals(host, "")) {
|
if (!Objects.equals(host, "") && host != null) {
|
||||||
List<String> dataList = Arrays.asList(dataStr.split("\n"));
|
List<String> dataList = Arrays.asList(dataStr.split("\n"));
|
||||||
if (ConfigEntry.globalDataMap.containsKey(host)) {
|
if (ConfigEntry.globalDataMap.containsKey(host)) {
|
||||||
Map<String, List<String>> gRuleMap = new HashMap<>(ConfigEntry.globalDataMap.get(host));
|
Map<String, List<String>> gRuleMap = new HashMap<>(ConfigEntry.globalDataMap.get(host));
|
||||||
@@ -179,14 +177,6 @@ public class DataProcessingUnit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
t.start();
|
|
||||||
try {
|
|
||||||
t.join();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
GlobalCachePool.addToCache(messageIndex, finalMap);
|
GlobalCachePool.addToCache(messageIndex, finalMap);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package burp.core.processor;
|
package burp.core.processor;
|
||||||
|
|
||||||
import burp.IExtensionHelpers;
|
import burp.IExtensionHelpers;
|
||||||
|
import burp.IHttpRequestResponse;
|
||||||
|
import burp.IRequestInfo;
|
||||||
|
import burp.IResponseInfo;
|
||||||
import burp.core.utils.MatchTool;
|
import burp.core.utils.MatchTool;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -10,51 +12,78 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MessageProcessor {
|
public class MessageProcessor {
|
||||||
MatchTool matcher = new MatchTool();
|
private MatchTool matcher = new MatchTool();
|
||||||
DataProcessingUnit dataProcessingUnit = new DataProcessingUnit();
|
private DataProcessingUnit dataProcessingUnit = new DataProcessingUnit();
|
||||||
ColorProcessor colorProcessor = new ColorProcessor();
|
private ColorProcessor colorProcessor = new ColorProcessor();
|
||||||
|
|
||||||
public List<Map<String, String>> processMessage(IExtensionHelpers helpers, byte[] content, boolean isRequest, boolean messageInfo, String host)
|
public List<Map<String, String>> processMessage(IExtensionHelpers helpers, IHttpRequestResponse messageInfo, String host, boolean actionFlag) throws Exception {
|
||||||
throws NoSuchAlgorithmException {
|
|
||||||
List<Map<String, String>> result = new ArrayList<>();
|
byte[] requestByte = messageInfo.getRequest();
|
||||||
|
byte[] responseByte = messageInfo.getResponse();
|
||||||
|
|
||||||
|
List<Map<String, String>> reqObj = processRequestMessage(helpers, requestByte, host, actionFlag);
|
||||||
|
List<Map<String, String>> resObj = processResponseMessage(helpers, responseByte, host, actionFlag);
|
||||||
|
|
||||||
|
List<Map<String, String>> mergedList = new ArrayList<>(reqObj);
|
||||||
|
mergedList.addAll(resObj);
|
||||||
|
|
||||||
|
return mergedList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map<String, String>> processRequestMessage(IExtensionHelpers helpers, byte[] content, String host, boolean actionFlag) throws Exception {
|
||||||
Map<String, Map<String, Object>> obj;
|
Map<String, Map<String, Object>> obj;
|
||||||
|
|
||||||
if (isRequest) {
|
IRequestInfo requestInfo = helpers.analyzeRequest(content);
|
||||||
List<String> requestTmpHeaders = helpers.analyzeRequest(content).getHeaders();
|
List<String> requestTmpHeaders = requestInfo.getHeaders();
|
||||||
String requestHeaders = String.join("\n", requestTmpHeaders);
|
String requestHeaders = String.join("\n", requestTmpHeaders);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String urlString = requestTmpHeaders.get(0).split(" ")[1];
|
String urlString = requestTmpHeaders.get(0).split(" ")[1];
|
||||||
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
||||||
if (matcher.matchUrlSuffix(urlString)) {
|
if (matcher.matchUrlSuffix(urlString)) {
|
||||||
return result;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return result;
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int requestBodyOffset = helpers.analyzeRequest(content).getBodyOffset();
|
int requestBodyOffset = requestInfo.getBodyOffset();
|
||||||
byte[] requestBody = Arrays.copyOfRange(content, requestBodyOffset, content.length);
|
byte[] requestBody = Arrays.copyOfRange(content, requestBodyOffset, content.length);
|
||||||
obj = dataProcessingUnit.matchContentByRegex(content, requestHeaders, requestBody, "request", host);
|
obj = dataProcessingUnit.matchContentByRegex(content, requestHeaders, requestBody, "request", host);
|
||||||
} else {
|
|
||||||
try {
|
return getDataList(obj, actionFlag);
|
||||||
String inferredMimeType = String.format("hae.%s", helpers.analyzeResponse(content).getInferredMimeType().toLowerCase());
|
|
||||||
String statedMimeType = String.format("hae.%s", helpers.analyzeResponse(content).getStatedMimeType().toLowerCase());
|
|
||||||
if (matcher.matchUrlSuffix(statedMimeType) || matcher.matchUrlSuffix(inferredMimeType)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
List<String> responseTmpHeaders = helpers.analyzeResponse(content).getHeaders();
|
|
||||||
String responseHeaders = String.join("\n", responseTmpHeaders);
|
|
||||||
int responseBodyOffset = helpers.analyzeResponse(content).getBodyOffset();
|
|
||||||
byte[] responseBody = Arrays.copyOfRange(content, responseBodyOffset, content.length);
|
|
||||||
obj = dataProcessingUnit.matchContentByRegex(content, responseHeaders, responseBody, "response", host);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Map<String, String>> processResponseMessage(IExtensionHelpers helpers, byte[] content, String host, boolean actionFlag) throws Exception {
|
||||||
|
Map<String, Map<String, Object>> obj;
|
||||||
|
|
||||||
|
IResponseInfo responseInfo = helpers.analyzeResponse(content);
|
||||||
|
try {
|
||||||
|
String inferredMimeType = String.format("hae.%s", responseInfo.getInferredMimeType().toLowerCase());
|
||||||
|
String statedMimeType = String.format("hae.%s", responseInfo.getStatedMimeType().toLowerCase());
|
||||||
|
if (matcher.matchUrlSuffix(statedMimeType) || matcher.matchUrlSuffix(inferredMimeType)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<String> responseTmpHeaders = responseInfo.getHeaders();
|
||||||
|
String responseHeaders = String.join("\n", responseTmpHeaders);
|
||||||
|
int responseBodyOffset = responseInfo.getBodyOffset();
|
||||||
|
byte[] responseBody = Arrays.copyOfRange(content, responseBodyOffset, content.length);
|
||||||
|
obj = dataProcessingUnit.matchContentByRegex(content, responseHeaders, responseBody, "response", host);
|
||||||
|
|
||||||
|
return getDataList(obj, actionFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, String>> getDataList(Map<String, Map<String, Object>> obj, boolean actionFlag) {
|
||||||
|
List<Map<String, String>> highlightList = new ArrayList<>();
|
||||||
|
List<Map<String, String>> extractList = new ArrayList<>();
|
||||||
|
|
||||||
if (obj.size() > 0) {
|
if (obj.size() > 0) {
|
||||||
if (messageInfo) {
|
if (actionFlag) {
|
||||||
List<List<String>> resultList = dataProcessingUnit.extractColorsAndComments(obj);
|
List<List<String>> resultList = dataProcessingUnit.extractColorsAndComments(obj);
|
||||||
List<String> colorList = resultList.get(0);
|
List<String> colorList = resultList.get(0);
|
||||||
List<String> commentList = resultList.get(1);
|
List<String> commentList = resultList.get(1);
|
||||||
@@ -66,13 +95,14 @@ public class MessageProcessor {
|
|||||||
Map<String, String> commentMap = new HashMap<String, String>() {{
|
Map<String, String> commentMap = new HashMap<String, String>() {{
|
||||||
put("comment", String.join(", ", commentList));
|
put("comment", String.join(", ", commentList));
|
||||||
}};
|
}};
|
||||||
result.add(colorMap);
|
highlightList.add(colorMap);
|
||||||
result.add(commentMap);
|
highlightList.add(commentMap);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.add(dataProcessingUnit.extractDataFromMap(obj));
|
extractList.add(dataProcessingUnit.extractDataFromMap(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
return actionFlag ? highlightList : extractList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package burp.rule.utils;
|
package burp.rule.utils;
|
||||||
|
|
||||||
import burp.*;
|
import burp.*;
|
||||||
import burp.config.ConfigEntry;
|
|
||||||
import burp.config.ConfigLoader;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -13,6 +11,7 @@ import javax.swing.JOptionPane;
|
|||||||
*/
|
*/
|
||||||
public class RuleTool {
|
public class RuleTool {
|
||||||
private String rulesFilePath;
|
private String rulesFilePath;
|
||||||
|
private boolean isSuccess;
|
||||||
|
|
||||||
public RuleTool(String rulesFilePath) {
|
public RuleTool(String rulesFilePath) {
|
||||||
this.rulesFilePath = rulesFilePath;
|
this.rulesFilePath = rulesFilePath;
|
||||||
@@ -32,18 +31,22 @@ public class RuleTool {
|
|||||||
FileOutputStream fileOutputStream = new FileOutputStream(this.rulesFilePath);
|
FileOutputStream fileOutputStream = new FileOutputStream(this.rulesFilePath);
|
||||||
fileOutputStream.write(responseBodyByte);
|
fileOutputStream.write(responseBodyByte);
|
||||||
fileOutputStream.close();
|
fileOutputStream.close();
|
||||||
JOptionPane.showMessageDialog(null, "Rules update successfully!", "Info",
|
isSuccess = true;
|
||||||
JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
JOptionPane.showMessageDialog(null, e, "Error",
|
isSuccess = false;
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
try {
|
try {
|
||||||
t.join();
|
t.join(10000);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
isSuccess = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Rules update successfully!", "Info", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Rule update failed, please check the network!", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public class MainUI extends JPanel {
|
|||||||
private void excludeSuffixSaveActionPerformed(ActionEvent e) {
|
private void excludeSuffixSaveActionPerformed(ActionEvent e) {
|
||||||
ConfigLoader.setExcludeSuffix(excludeSuffixTextField.getText());
|
ConfigLoader.setExcludeSuffix(excludeSuffixTextField.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
JTabbedPane mainTabbedPane = new JTabbedPane();
|
JTabbedPane mainTabbedPane = new JTabbedPane();
|
||||||
ruleTabbedPane = new JTabbedPane();
|
ruleTabbedPane = new JTabbedPane();
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import burp.ui.board.MessagePanel.Table;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import javax.swing.table.DefaultTableModel;
|
|
||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import javax.swing.table.TableModel;
|
import javax.swing.table.TableModel;
|
||||||
@@ -27,14 +26,28 @@ public class Databoard extends JPanel {
|
|||||||
private static Boolean isMatchHost = false;
|
private static Boolean isMatchHost = false;
|
||||||
private JLabel hostLabel;
|
private JLabel hostLabel;
|
||||||
private JTextField hostTextField;
|
private JTextField hostTextField;
|
||||||
private JTabbedPane dataTabbedPaneA;
|
private JTabbedPane dataTabbedPane;
|
||||||
private JTabbedPane dataTabbedPaneB;
|
|
||||||
private JButton clearButton;
|
private JButton clearButton;
|
||||||
private JSplitPane splitPane;
|
private JSplitPane splitPane;
|
||||||
private MessagePanel messagePanel;
|
private MessagePanel messagePanel;
|
||||||
private Table table;
|
private Table table;
|
||||||
DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
|
private SwingWorker<Object, Void> currentWorker;
|
||||||
JComboBox hostComboBox = new JComboBox(comboBoxModel);
|
private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
|
||||||
|
private JComboBox hostComboBox = new JComboBox(comboBoxModel);
|
||||||
|
private ChangeListener changeListenerInstance = new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
int selectedIndex = dataTabbedPane.getSelectedIndex();
|
||||||
|
String selectedTitle = "";
|
||||||
|
|
||||||
|
if (selectedIndex != -1) {
|
||||||
|
selectedTitle = dataTabbedPane.getTitleAt(selectedIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyHostFilter(selectedTitle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public Databoard(MessagePanel messagePanel) {
|
public Databoard(MessagePanel messagePanel) {
|
||||||
this.messagePanel = messagePanel;
|
this.messagePanel = messagePanel;
|
||||||
@@ -42,8 +55,7 @@ public class Databoard extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUI() {
|
private void cleanUI() {
|
||||||
dataTabbedPaneA.removeAll();
|
dataTabbedPane.removeAll();
|
||||||
dataTabbedPaneB.removeAll();
|
|
||||||
splitPane.setVisible(false);
|
splitPane.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +69,7 @@ public class Databoard extends JPanel {
|
|||||||
String cleanedHost = StringHelper.replaceFirstOccurrence(host, "*.", "");
|
String cleanedHost = StringHelper.replaceFirstOccurrence(host, "*.", "");
|
||||||
|
|
||||||
if (host.contains("*")) {
|
if (host.contains("*")) {
|
||||||
ConfigEntry.globalDataMap.keySet().removeIf(i -> i.contains(cleanedHost) || cleanedHost.equals("**"));
|
ConfigEntry.globalDataMap.keySet().removeIf(i -> i.contains(cleanedHost) || cleanedHost.contains("*"));
|
||||||
} else {
|
} else {
|
||||||
ConfigEntry.globalDataMap.remove(host);
|
ConfigEntry.globalDataMap.remove(host);
|
||||||
}
|
}
|
||||||
@@ -70,8 +82,7 @@ public class Databoard extends JPanel {
|
|||||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||||
hostLabel = new JLabel();
|
hostLabel = new JLabel();
|
||||||
hostTextField = new JTextField();
|
hostTextField = new JTextField();
|
||||||
dataTabbedPaneA = new JTabbedPane(JTabbedPane.TOP);
|
dataTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||||
dataTabbedPaneB = new JTabbedPane(JTabbedPane.TOP);
|
|
||||||
clearButton = new JButton();
|
clearButton = new JButton();
|
||||||
|
|
||||||
//======== this ========
|
//======== this ========
|
||||||
@@ -130,28 +141,55 @@ public class Databoard extends JPanel {
|
|||||||
* 设置输入自动匹配
|
* 设置输入自动匹配
|
||||||
*/
|
*/
|
||||||
private void setAutoMatch() {
|
private void setAutoMatch() {
|
||||||
isMatchHost = false;
|
populateComboBoxModel();
|
||||||
|
|
||||||
|
hostComboBox.setSelectedItem(null);
|
||||||
|
hostComboBox.addActionListener(this::handleComboBoxAction);
|
||||||
|
|
||||||
|
hostTextField.addKeyListener(new KeyAdapter() {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
handleKeyEvents(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
hostTextField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
@Override
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
update(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
update(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
update(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(DocumentEvent e) {
|
||||||
|
filterComboBoxList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateComboBoxModel() {
|
||||||
for (String host : getHostByList()) {
|
for (String host : getHostByList()) {
|
||||||
comboBoxModel.addElement(host);
|
comboBoxModel.addElement(host);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hostComboBox.setSelectedItem(null);
|
private void handleComboBoxAction(ActionEvent e) {
|
||||||
|
if (!isMatchHost && hostComboBox.getSelectedItem() != null) {
|
||||||
hostComboBox.addActionListener(e -> {
|
|
||||||
if (!isMatchHost) {
|
|
||||||
if (hostComboBox.getSelectedItem() != null) {
|
|
||||||
String selectedHost = hostComboBox.getSelectedItem().toString();
|
String selectedHost = hostComboBox.getSelectedItem().toString();
|
||||||
hostTextField.setText(selectedHost);
|
hostTextField.setText(selectedHost);
|
||||||
populateTabbedPaneByHost(selectedHost);
|
populateTabbedPaneByHost(selectedHost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// 事件监听
|
private void handleKeyEvents(KeyEvent e) {
|
||||||
hostTextField.addKeyListener(new KeyAdapter() {
|
|
||||||
@Override
|
|
||||||
public void keyPressed(KeyEvent e) {
|
|
||||||
isMatchHost = true;
|
isMatchHost = true;
|
||||||
int keyCode = e.getKeyCode();
|
int keyCode = e.getKeyCode();
|
||||||
|
|
||||||
@@ -159,16 +197,13 @@ public class Databoard extends JPanel {
|
|||||||
e.setKeyCode(KeyEvent.VK_ENTER);
|
e.setKeyCode(KeyEvent.VK_ENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) {
|
if (Arrays.asList(KeyEvent.VK_ENTER, KeyEvent.VK_UP, KeyEvent.VK_DOWN).contains(keyCode)) {
|
||||||
e.setSource(hostComboBox);
|
e.setSource(hostComboBox);
|
||||||
hostComboBox.dispatchEvent(e);
|
hostComboBox.dispatchEvent(e);
|
||||||
|
|
||||||
if (keyCode == KeyEvent.VK_ENTER) {
|
if (keyCode == KeyEvent.VK_ENTER) {
|
||||||
String selectedItem = hostComboBox.getSelectedItem().toString();
|
updateTextFieldFromComboBox();
|
||||||
hostTextField.setText(selectedItem);
|
|
||||||
populateTabbedPaneByHost(selectedItem);
|
|
||||||
hostComboBox.setPopupVisible(false);
|
hostComboBox.setPopupVisible(false);
|
||||||
return;
|
e.consume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,29 +213,22 @@ public class Databoard extends JPanel {
|
|||||||
|
|
||||||
isMatchHost = false;
|
isMatchHost = false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
hostTextField.getDocument().addDocumentListener(new DocumentListener() {
|
private void updateTextFieldFromComboBox() {
|
||||||
@Override
|
Object selectedItem = hostComboBox.getSelectedItem();
|
||||||
public void insertUpdate(DocumentEvent e) {
|
if (selectedItem != null) {
|
||||||
updateList();
|
String selectedHost = selectedItem.toString();
|
||||||
|
hostTextField.setText(selectedHost);
|
||||||
|
populateTabbedPaneByHost(selectedHost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void filterComboBoxList() {
|
||||||
public void removeUpdate(DocumentEvent e) {
|
|
||||||
updateList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void changedUpdate(DocumentEvent e) {
|
|
||||||
updateList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateList() {
|
|
||||||
isMatchHost = true;
|
isMatchHost = true;
|
||||||
comboBoxModel.removeAllElements();
|
comboBoxModel.removeAllElements();
|
||||||
String input = hostTextField.getText().toLowerCase();
|
String input = hostTextField.getText().toLowerCase();
|
||||||
if (!input.isEmpty()){
|
|
||||||
|
if (!input.isEmpty()) {
|
||||||
for (String host : getHostByList()) {
|
for (String host : getHostByList()) {
|
||||||
String lowerCaseHost = host.toLowerCase();
|
String lowerCaseHost = host.toLowerCase();
|
||||||
if (lowerCaseHost.contains(input)) {
|
if (lowerCaseHost.contains(input)) {
|
||||||
@@ -213,19 +241,20 @@ public class Databoard extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hostComboBox.setPopupVisible(comboBoxModel.getSize() > 0);
|
hostComboBox.setPopupVisible(comboBoxModel.getSize() > 0);
|
||||||
isMatchHost = false;
|
isMatchHost = false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyHostFilter(String filterText) {
|
private void applyHostFilter(String filterText) {
|
||||||
TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) table.getRowSorter();
|
TableRowSorter<TableModel> sorter = (TableRowSorter<TableModel>) table.getRowSorter();
|
||||||
|
|
||||||
if (filterText.contains("*.")) {
|
if (filterText.contains("*.")) {
|
||||||
filterText = StringHelper.replaceFirstOccurrence(filterText, "*.", "");
|
filterText = StringHelper.replaceFirstOccurrence(filterText, "*.", "");
|
||||||
} else if (filterText.contains("*")) {
|
} else if (filterText.contains("*")) {
|
||||||
filterText = "";
|
filterText = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
RowFilter<TableModel, Integer> filter = RowFilter.regexFilter(filterText, 1);
|
RowFilter<TableModel, Integer> filter = RowFilter.regexFilter(filterText, 1);
|
||||||
sorter.setRowFilter(filter);
|
sorter.setRowFilter(filter);
|
||||||
filterText = filterText.isEmpty() ? "*" : filterText;
|
filterText = filterText.isEmpty() ? "*" : filterText;
|
||||||
@@ -262,51 +291,57 @@ public class Databoard extends JPanel {
|
|||||||
selectedDataMap = dataMap.get(selectedHost);
|
selectedDataMap = dataMap.get(selectedHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 由于removeChangeListener不知什么原因不生效,因此建立两个tabbedPane
|
dataTabbedPane.removeAll();
|
||||||
dataTabbedPaneA.removeAll();
|
|
||||||
dataTabbedPaneB.removeAll();
|
|
||||||
|
|
||||||
ChangeListener changeListenerInstance = new ChangeListener() {
|
dataTabbedPane.setPreferredSize(new Dimension(500,0));
|
||||||
@Override
|
dataTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||||
public void stateChanged(ChangeEvent e) {
|
splitPane.setLeftComponent(dataTabbedPane);
|
||||||
int selectedIndex = dataTabbedPaneA.getSelectedIndex();
|
|
||||||
String selectedTitle = "";
|
|
||||||
if (selectedIndex != -1) {
|
|
||||||
selectedTitle = dataTabbedPaneA.getTitleAt(selectedIndex);
|
|
||||||
}
|
|
||||||
applyHostFilter(selectedTitle);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (selectedHost.equals("**")) {
|
if (selectedHost.equals("**")) {
|
||||||
dataTabbedPaneA.setPreferredSize(new Dimension(500,0));
|
|
||||||
dataTabbedPaneA.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
|
||||||
splitPane.setLeftComponent(dataTabbedPaneA);
|
|
||||||
for (Map.Entry<String, Map<String, List<String>>> entry : dataMap.entrySet()) {
|
for (Map.Entry<String, Map<String, List<String>>> entry : dataMap.entrySet()) {
|
||||||
JTabbedPane newTabbedPane = new JTabbedPane();
|
JTabbedPane newTabbedPane = new JTabbedPane();
|
||||||
newTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
newTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||||
|
|
||||||
for (Map.Entry<String, List<String>> entrySet : entry.getValue().entrySet()) {
|
for (Map.Entry<String, List<String>> entrySet : entry.getValue().entrySet()) {
|
||||||
Thread t = new Thread(() -> {
|
currentWorker = new SwingWorker<Object, Void>() {
|
||||||
String tabTitle = String.format("%s (%s)", entrySet.getKey(), entrySet.getValue().size());
|
@Override
|
||||||
newTabbedPane.addTab(tabTitle, new DataTable(entrySet.getKey(), entrySet.getValue()));
|
protected Object[] doInBackground() throws Exception {
|
||||||
dataTabbedPaneA.addTab(entry.getKey(), newTabbedPane);
|
String tabTitle = String.format("%s (%s)", entrySet.getKey(),
|
||||||
});
|
entrySet.getValue().size());
|
||||||
t.start();
|
DatatablePanel datatablePanel = new DatatablePanel(entrySet.getKey(),
|
||||||
|
entrySet.getValue());
|
||||||
|
datatablePanel.setTableListener(messagePanel);
|
||||||
|
return new Object[] {tabTitle, datatablePanel};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
if (!isCancelled()) {
|
||||||
try {
|
try {
|
||||||
t.join();
|
Object[] result = (Object[]) get();
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
newTabbedPane.addTab(result[0].toString(), (DatatablePanel) result[1]);
|
||||||
|
dataTabbedPane.addTab(entry.getKey(), newTabbedPane);
|
||||||
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataTabbedPaneA.addChangeListener(changeListenerInstance);
|
};
|
||||||
|
currentWorker.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dataTabbedPane.addChangeListener(changeListenerInstance);
|
||||||
} else {
|
} else {
|
||||||
dataTabbedPaneB.setPreferredSize(new Dimension(500,0));
|
dataTabbedPane.removeChangeListener(changeListenerInstance);
|
||||||
dataTabbedPaneB.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
|
||||||
splitPane.setLeftComponent(dataTabbedPaneB);
|
|
||||||
for (Map.Entry<String, List<String>> entry : selectedDataMap.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : selectedDataMap.entrySet()) {
|
||||||
String tabTitle = String.format("%s (%s)", entry.getKey(), entry.getValue().size());
|
String tabTitle = String.format("%s (%s)", entry.getKey(), entry.getValue().size());
|
||||||
dataTabbedPaneB.addTab(tabTitle, new DataTable(entry.getKey(), entry.getValue()));
|
DatatablePanel datatablePanel = new DatatablePanel(entry.getKey(), entry.getValue());
|
||||||
|
datatablePanel.setTableListener(messagePanel);
|
||||||
|
dataTabbedPane.addTab(tabTitle, datatablePanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,103 +367,21 @@ public class Databoard extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hostTextField.setText(selectedHost);
|
hostTextField.setText(selectedHost);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DataTable extends JPanel {
|
ChangeListener changeListener = new ChangeListener() {
|
||||||
private final JTable table;
|
public void stateChanged(ChangeEvent e) {
|
||||||
private final DefaultTableModel model;
|
JTabbedPane tabSource = (JTabbedPane) e.getSource();
|
||||||
private final JTextField searchField;
|
int index = tabSource.getSelectedIndex();
|
||||||
private TableRowSorter<DefaultTableModel> sorter;
|
if (index != -1) {
|
||||||
|
Component selectedComponent = tabSource.getComponentAt(index);
|
||||||
|
if (selectedComponent instanceof DatatablePanel) {
|
||||||
public DataTable(String tableName, List<String> list) {
|
((DatatablePanel) selectedComponent).updatePageSize();
|
||||||
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 = table.getSelectedRow();
|
|
||||||
if (selectedRow != -1) {
|
|
||||||
String rowData = table.getValueAt(selectedRow, 0).toString();
|
|
||||||
messagePanel.applyMessageFilter(tableName, rowData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
model.addColumn("Information");
|
dataTabbedPane.addChangeListener(changeListener);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
324
src/main/java/burp/ui/board/DatatablePanel.java
Normal file
324
src/main/java/burp/ui/board/DatatablePanel.java
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
package burp.ui.board;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.AdjustmentEvent;
|
||||||
|
import java.awt.event.AdjustmentListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.RowFilter;
|
||||||
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
import javax.swing.TransferHandler;
|
||||||
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import javax.swing.table.TableColumn;
|
||||||
|
import javax.swing.table.TableRowSorter;
|
||||||
|
|
||||||
|
public class DatatablePanel extends JPanel {
|
||||||
|
private final JTable table;
|
||||||
|
private final DefaultTableModel model;
|
||||||
|
private final JTextField searchField;
|
||||||
|
private TableRowSorter<DefaultTableModel> sorter;
|
||||||
|
private int pageSize; // 动态计算的,每页显示多少条记录
|
||||||
|
private int currentPage; // 当前页码
|
||||||
|
private List<String> fullList; // 假设这是一个包含所有数据的列表
|
||||||
|
private JScrollPane scrollPane;
|
||||||
|
private String tableName;
|
||||||
|
private final int SHOW_LENGTH = 5000;
|
||||||
|
private JCheckBox searchMode = new JCheckBox("Reverse search");
|
||||||
|
private JCheckBox showMode = new JCheckBox("Show all data");
|
||||||
|
private boolean scrollFlag = true;
|
||||||
|
|
||||||
|
public DatatablePanel(String tableName, List<String> list) {
|
||||||
|
fullList = list;
|
||||||
|
currentPage = 0;
|
||||||
|
pageSize = 10;
|
||||||
|
this.tableName = tableName;
|
||||||
|
|
||||||
|
String[] columnNames = {"#", "Information"};
|
||||||
|
model = new DefaultTableModel(columnNames, 0);
|
||||||
|
table = new JTable(model);
|
||||||
|
sorter = new TableRowSorter<>(model);
|
||||||
|
// 设置ID排序
|
||||||
|
sorter.setComparator(0, new Comparator<Integer>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Integer s1, Integer s2) {
|
||||||
|
return s1.compareTo(s2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
table.setRowSorter(sorter);
|
||||||
|
TableColumn idColumn = table.getColumnModel().getColumn(0);
|
||||||
|
idColumn.setMaxWidth(50);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// 设置布局
|
||||||
|
scrollPane = new JScrollPane(table);
|
||||||
|
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
scrollPane.addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
updatePageSize();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加滚动监听器,以加载更多数据
|
||||||
|
AdjustmentListener scrollListener = new AdjustmentListener() {
|
||||||
|
@Override
|
||||||
|
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||||
|
if (fullList.size() > SHOW_LENGTH) {
|
||||||
|
if (!e.getValueIsAdjusting() && !scrollPane.getVerticalScrollBar().getValueIsAdjusting()) {
|
||||||
|
if (scrollPane.getVerticalScrollBar().getValue() == scrollPane.getVerticalScrollBar().getMaximum() - scrollPane.getVerticalScrollBar().getVisibleAmount()) {
|
||||||
|
if ((currentPage + 1) * pageSize < fullList.size()) {
|
||||||
|
currentPage++;
|
||||||
|
loadPageData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
scrollPane.getVerticalScrollBar().addAdjustmentListener(scrollListener);
|
||||||
|
|
||||||
|
searchMode.addItemListener(new ItemListener() {
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
performSearch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
showMode.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
model.setRowCount(0);
|
||||||
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
scrollFlag = false;
|
||||||
|
loadPageData();
|
||||||
|
showMode.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setLayout(new BorderLayout(0, 5));
|
||||||
|
|
||||||
|
JPanel optionsPanel = new JPanel();
|
||||||
|
optionsPanel.setBorder(BorderFactory.createEmptyBorder(2, 3, 5, 5));
|
||||||
|
optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.X_AXIS));
|
||||||
|
|
||||||
|
// 新增复选框要在这修改rows
|
||||||
|
JPanel menuPanel = new JPanel(new GridLayout(2, 1));
|
||||||
|
menuPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
||||||
|
JPopupMenu menu = new JPopupMenu();
|
||||||
|
menuPanel.add(searchMode);
|
||||||
|
menuPanel.add(showMode);
|
||||||
|
menu.add(menuPanel);
|
||||||
|
|
||||||
|
JButton settingsButton = new JButton("Settings");
|
||||||
|
settingsButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
int x = settingsButton.getX();
|
||||||
|
int y = settingsButton.getY() - menu.getPreferredSize().height;
|
||||||
|
menu.show(settingsButton, x, y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
optionsPanel.add(settingsButton);
|
||||||
|
optionsPanel.add(Box.createHorizontalStrut(5));
|
||||||
|
optionsPanel.add(searchField);
|
||||||
|
|
||||||
|
add(scrollPane, BorderLayout.CENTER);
|
||||||
|
add(optionsPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
loadPageData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void performSearch() {
|
||||||
|
// 检查文本字段的字体颜色是否为黑色,表示可以进行搜索
|
||||||
|
if (searchField.getForeground().equals(Color.BLACK)) {
|
||||||
|
// 获取搜索文本
|
||||||
|
String searchText = searchField.getText();
|
||||||
|
|
||||||
|
// 创建行过滤器
|
||||||
|
RowFilter<DefaultTableModel, Object> rowFilter;
|
||||||
|
|
||||||
|
// 检查搜索模式是否为选中状态
|
||||||
|
if (searchMode.isSelected()) {
|
||||||
|
// 反向搜索:创建一个过滤器以排除与正则表达式匹配的行
|
||||||
|
rowFilter = new RowFilter<DefaultTableModel, Object>() {
|
||||||
|
public boolean include(Entry<? extends DefaultTableModel, ? extends Object> entry) {
|
||||||
|
// 对每一行的第二列进行判断(假设第二列的索引是1)
|
||||||
|
String value = (String) entry.getValue(1);
|
||||||
|
// 如果该列的值不包含搜索文本,则返回true,否则返回false
|
||||||
|
return searchText.isEmpty() ? true : !value.toLowerCase().contains(searchText.toLowerCase());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 正向搜索:创建一个过滤器以包含与正则表达式匹配的行
|
||||||
|
rowFilter = RowFilter.regexFilter("(?i)" + Pattern.quote(searchText), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置过滤器到排序器
|
||||||
|
sorter.setRowFilter(rowFilter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载指定页的数据
|
||||||
|
private void loadPageData() {
|
||||||
|
if (fullList.size() > SHOW_LENGTH && scrollFlag) {
|
||||||
|
int start = currentPage * pageSize;
|
||||||
|
int end = Math.min((currentPage + 1) * pageSize, fullList.size());
|
||||||
|
int lastRow = model.getRowCount();
|
||||||
|
start = Math.max(start, lastRow);
|
||||||
|
|
||||||
|
for (int i = start; i < end; i++) {
|
||||||
|
addRowToTable(model, new Object[]{fullList.get(i)});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (String item : fullList) {
|
||||||
|
addRowToTable(model, new Object[]{item});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addRowToTable(DefaultTableModel model, Object[] data) {
|
||||||
|
// 获取当前ID
|
||||||
|
int rowCount = model.getRowCount();
|
||||||
|
int id = rowCount > 0 ? (Integer) model.getValueAt(rowCount - 1, 0) + 1 : 1;
|
||||||
|
Object[] rowData = new Object[data.length + 1];
|
||||||
|
rowData[0] = id; // 设置ID列的值
|
||||||
|
System.arraycopy(data, 0, rowData, 1, data.length); // 拷贝其余数据
|
||||||
|
model.addRow(rowData); // 添加行
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePageSize() {
|
||||||
|
if (fullList.size() > SHOW_LENGTH && isShowing()) {
|
||||||
|
int oldPageSize = pageSize;
|
||||||
|
pageSize = getDynamicSize();
|
||||||
|
if (oldPageSize != pageSize) {
|
||||||
|
currentPage = 0;
|
||||||
|
loadPageData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDynamicSize() {
|
||||||
|
int visibleHeight = scrollPane.getViewport().getViewRect().height;
|
||||||
|
int rowHeight = table.getRowHeight();
|
||||||
|
return Math.max(1, visibleHeight / rowHeight + 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableListener(MessagePanel messagePanel) {
|
||||||
|
table.setDefaultEditor(Object.class, null);
|
||||||
|
|
||||||
|
// 表格内容双击事件
|
||||||
|
table.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if (e.getClickCount() == 2) {
|
||||||
|
int selectedRow = table.getSelectedRow();
|
||||||
|
if (selectedRow != -1) {
|
||||||
|
String rowData = table.getValueAt(selectedRow, 1).toString();
|
||||||
|
messagePanel.applyMessageFilter(tableName, rowData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
table.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException {
|
||||||
|
if (comp instanceof JTable) {
|
||||||
|
StringSelection stringSelection = new StringSelection(getSelectedData(
|
||||||
|
(JTable) comp));
|
||||||
|
clip.setContents(stringSelection, null);
|
||||||
|
} else {
|
||||||
|
super.exportToClipboard(comp, clip, action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectedData(JTable table) {
|
||||||
|
int[] selectRows = table.getSelectedRows();
|
||||||
|
StringBuilder selectData = new StringBuilder();
|
||||||
|
for (int row : selectRows) {
|
||||||
|
selectData.append(table.getValueAt(row, 1).toString()).append("\n");
|
||||||
|
}
|
||||||
|
// 便于单行复制,去除最后一个换行符
|
||||||
|
String revData = selectData.reverse().toString().replaceFirst("\n", "");
|
||||||
|
StringBuilder retData = new StringBuilder(revData).reverse();
|
||||||
|
return retData.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTable getTable() {
|
||||||
|
return this.table;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,12 +21,10 @@ import java.util.Arrays;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSplitPane;
|
import javax.swing.JSplitPane;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
@@ -60,7 +58,7 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
|
|
||||||
// Length字段根据大小进行排序
|
// Length字段根据大小进行排序
|
||||||
TableRowSorter<DefaultTableModel> sorter = (TableRowSorter<DefaultTableModel>) logTable.getRowSorter();
|
TableRowSorter<DefaultTableModel> sorter = (TableRowSorter<DefaultTableModel>) logTable.getRowSorter();
|
||||||
sorter.setComparator(3, new Comparator<String>() {
|
sorter.setComparator(4, new Comparator<String>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(String s1, String s2) {
|
public int compare(String s1, String s2) {
|
||||||
Integer age1 = Integer.parseInt(s1);
|
Integer age1 = Integer.parseInt(s1);
|
||||||
@@ -69,7 +67,7 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Color字段根据颜色顺序进行排序
|
// Color字段根据颜色顺序进行排序
|
||||||
sorter.setComparator(4, new Comparator<String>() {
|
sorter.setComparator(5, new Comparator<String>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(String s1, String s2) {
|
public int compare(String s1, String s2) {
|
||||||
int index1 = getIndex(s1);
|
int index1 = getIndex(s1);
|
||||||
@@ -158,6 +156,9 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
@Override
|
@Override
|
||||||
public Object getValueAt(int rowIndex, int columnIndex)
|
public Object getValueAt(int rowIndex, int columnIndex)
|
||||||
{
|
{
|
||||||
|
if (filteredLog.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
LogEntry logEntry = filteredLog.get(rowIndex);
|
LogEntry logEntry = filteredLog.get(rowIndex);
|
||||||
switch (columnIndex)
|
switch (columnIndex)
|
||||||
{
|
{
|
||||||
@@ -264,6 +265,7 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
|
logTable.lastSelectedIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByHost(String filterText) {
|
public void deleteByHost(String filterText) {
|
||||||
@@ -306,13 +308,13 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
return currentlyDisplayedItem.getHttpService();
|
return currentlyDisplayedItem.getHttpService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(IHttpRequestResponse messageInfo, String comment, String length, String color) {
|
public void add(IHttpRequestResponse messageInfo, String comment, String color) {
|
||||||
synchronized(log) {
|
synchronized(log) {
|
||||||
IRequestInfo iRequestInfo = helpers.analyzeRequest(messageInfo);
|
IRequestInfo iRequestInfo = helpers.analyzeRequest(messageInfo);
|
||||||
URL url = iRequestInfo.getUrl();
|
URL url = iRequestInfo.getUrl();
|
||||||
String method = iRequestInfo.getMethod();
|
String method = iRequestInfo.getMethod();
|
||||||
String status = String.valueOf(helpers.analyzeResponse(messageInfo.getResponse()).getStatusCode());
|
String status = String.valueOf(helpers.analyzeResponse(messageInfo.getResponse()).getStatusCode());
|
||||||
|
String length = String.valueOf(messageInfo.getResponse().length);
|
||||||
LogEntry logEntry = new LogEntry(callbacks.saveBuffersToTempFiles(messageInfo), method, url, comment, length, color, status);
|
LogEntry logEntry = new LogEntry(callbacks.saveBuffersToTempFiles(messageInfo), method, url, comment, length, color, status);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -327,8 +329,8 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
byte[] reqByteB = reqResMessage.getRequest();
|
byte[] reqByteB = reqResMessage.getRequest();
|
||||||
byte[] resByteB = reqResMessage.getResponse();
|
byte[] resByteB = reqResMessage.getResponse();
|
||||||
try {
|
try {
|
||||||
// 采用匹配数据结果比对
|
// 通过URL、请求和响应报文、匹配数据内容,多维度进行对比
|
||||||
if (areMapsEqual(getCacheData(reqByteB), getCacheData(reqByteA)) && areMapsEqual(getCacheData(resByteB), getCacheData(resByteA))) {
|
if ((entry.getUrl().toString().equals(url.toString()) || (Arrays.equals(reqByteB, reqByteA) || Arrays.equals(resByteB, resByteA))) && (areMapsEqual(getCacheData(reqByteB), getCacheData(reqByteA)) && areMapsEqual(getCacheData(resByteB), getCacheData(resByteA)))) {
|
||||||
isDuplicate = true;
|
isDuplicate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -355,6 +357,9 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean areMapsEqual(Map<String, Map<String, Object>> map1, Map<String, Map<String, Object>> map2) {
|
private boolean areMapsEqual(Map<String, Map<String, Object>> map1, Map<String, Map<String, Object>> map2) {
|
||||||
|
if (map1 == null || map2 == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (map1.size() != map2.size()) {
|
if (map1.size() != map2.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -398,7 +403,10 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
|
|
||||||
public class Table extends JTable {
|
public class Table extends JTable {
|
||||||
LogEntry logEntry;
|
LogEntry logEntry;
|
||||||
private SwingWorker<Void, Void> currentWorker;
|
private SwingWorker<Object, Void> currentWorker;
|
||||||
|
// 设置响应报文返回的最大长度为3MB
|
||||||
|
private final int MAX_LENGTH = 3145728;
|
||||||
|
private int lastSelectedIndex = -1;
|
||||||
|
|
||||||
public Table(TableModel tableModel) {
|
public Table(TableModel tableModel) {
|
||||||
super(tableModel);
|
super(tableModel);
|
||||||
@@ -407,35 +415,50 @@ public class MessagePanel extends AbstractTableModel implements IMessageEditorCo
|
|||||||
@Override
|
@Override
|
||||||
public void changeSelection(int row, int col, boolean toggle, boolean extend) {
|
public void changeSelection(int row, int col, boolean toggle, boolean extend) {
|
||||||
super.changeSelection(row, col, toggle, extend);
|
super.changeSelection(row, col, toggle, extend);
|
||||||
|
int selectedIndex = convertRowIndexToModel(row);
|
||||||
|
if (lastSelectedIndex != selectedIndex) {
|
||||||
|
lastSelectedIndex = selectedIndex;
|
||||||
|
logEntry = filteredLog.get(selectedIndex);
|
||||||
|
|
||||||
logEntry = filteredLog.get(convertRowIndexToModel(row));
|
|
||||||
requestViewer.setMessage("Loading...".getBytes(), true);
|
requestViewer.setMessage("Loading...".getBytes(), true);
|
||||||
responseViewer.setMessage("Loading...".getBytes(), false);
|
responseViewer.setMessage("Loading...".getBytes(), false);
|
||||||
currentlyDisplayedItem = logEntry.getRequestResponse();
|
currentlyDisplayedItem = logEntry.getRequestResponse();
|
||||||
|
|
||||||
// 取消之前的后台任务
|
|
||||||
if (currentWorker != null && !currentWorker.isDone()) {
|
if (currentWorker != null && !currentWorker.isDone()) {
|
||||||
currentWorker.cancel(true);
|
currentWorker.cancel(true);
|
||||||
}
|
}
|
||||||
// 在后台线程中执行耗时操作
|
|
||||||
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
|
currentWorker = new SwingWorker<Object, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Exception {
|
protected byte[][] doInBackground() throws Exception {
|
||||||
refreshMessage();
|
byte[] requestByte = logEntry.getRequestResponse().getRequest();
|
||||||
return null;
|
byte[] responseByte = logEntry.getRequestResponse().getResponse();
|
||||||
}
|
|
||||||
};
|
if (responseByte.length > MAX_LENGTH) {
|
||||||
// 设置当前后台任务
|
String ellipsis = "\r\n......";
|
||||||
currentWorker = worker;
|
responseByte = Arrays.copyOf(responseByte, MAX_LENGTH + ellipsis.length());
|
||||||
// 启动后台线程
|
byte[] ellipsisBytes = ellipsis.getBytes();
|
||||||
worker.execute();
|
System.arraycopy(ellipsisBytes, 0, responseByte, MAX_LENGTH, ellipsisBytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void refreshMessage() {
|
return new byte[][] {requestByte, responseByte};
|
||||||
SwingUtilities.invokeLater(() -> {
|
}
|
||||||
requestViewer.setMessage(logEntry.getRequestResponse().getRequest(), true);
|
|
||||||
responseViewer.setMessage(logEntry.getRequestResponse().getResponse(), false);
|
@Override
|
||||||
});
|
protected void done() {
|
||||||
|
if (!isCancelled()) {
|
||||||
|
try {
|
||||||
|
byte[][] result = (byte[][]) get();
|
||||||
|
requestViewer.setMessage(result[0], true);
|
||||||
|
responseViewer.setMessage(result[1], false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
currentWorker.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user