Skip to content

Commit

Permalink
Version: 3.0.1 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
gh0stkey committed May 9, 2024
1 parent a6cd013 commit ca773f3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/main/java/hae/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class Config {
"any header",
"any body",
"response",
"response line",
"response header",
"response body",
"request",
"request line",
"request header",
"request body"
};
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hae/HaE.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HaE implements BurpExtension {
@Override
public void initialize(MontoyaApi api) {
// 设置扩展名称
String version = "3.0";
String version = "3.0.1";
api.extension().setName(String.format("HaE (%s) - Highlighter and Extractor", version));

// 加载扩展后输出的项目信息
Expand Down
68 changes: 35 additions & 33 deletions src/main/java/hae/component/board/Datatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import burp.api.montoya.MontoyaApi;
import hae.component.board.message.MessageTableModel;
import hae.instances.editor.RequestEditor;
import jregex.Pattern;
import jregex.REFlags;

Expand Down Expand Up @@ -30,7 +31,6 @@ public Datatable(MontoyaApi api, String tabName, List<String> dataList) {
this.api = api;
this.tabName = tabName;


String[] columnNames = {"#", "Information"};

dataTableModel = new DefaultTableModel(columnNames, 0);
Expand Down Expand Up @@ -114,19 +114,6 @@ public void changedUpdate(DocumentEvent e) {
optionsPanel.add(Box.createHorizontalStrut(5));
optionsPanel.add(searchField);

dataTable.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);
}
}
});

add(scrollPane, BorderLayout.CENTER);
add(optionsPanel, BorderLayout.SOUTH);
}
Expand Down Expand Up @@ -186,26 +173,20 @@ public boolean include(Entry<?, ?> entry) {
}
}

public static 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");
}

// 便于单行复制,去除最后一个换行符
if (!selectData.isEmpty()){
selectData.deleteCharAt(selectData.length() - 1);
}

return selectData.toString();
}

public JTable getDataTable() {
return this.dataTable;
}

public void setTableListener(MessageTableModel messagePanel) {
// 表格复制功能
dataTable.setTransferHandler(new TransferHandler() {
@Override
public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException {
if (comp instanceof JTable) {
StringSelection stringSelection = new StringSelection(getSelectedDataAtTable((JTable) comp));
clip.setContents(stringSelection, null);
} else {
super.exportToClipboard(comp, clip, action);
}
}
});

dataTable.setDefaultEditor(Object.class, null);

// 表格内容双击事件
Expand All @@ -222,5 +203,26 @@ public void mouseClicked(MouseEvent e) {
}
});
}

public String getSelectedDataAtTable(JTable table) {
int[] selectRows = table.getSelectedRows();
StringBuilder selectData = new StringBuilder();

for (int row : selectRows) {
selectData.append(table.getValueAt(row, 1).toString()).append("\n");
}

// 便于单行复制,去除最后一个换行符
if (!selectData.isEmpty()){
selectData.deleteCharAt(selectData.length() - 1);
return selectData.toString();
} else {
return "";
}
}

public JTable getDataTable() {
return this.dataTable;
}
}

15 changes: 7 additions & 8 deletions src/main/java/hae/instances/editor/RequestEditor.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package hae.instances.editor;

import burp.api.montoya.MontoyaApi;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.core.Range;
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpRequestEditor;
import burp.api.montoya.ui.editor.extension.HttpRequestEditorProvider;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.core.Range;
import burp.api.montoya.http.message.HttpRequestResponse;
import burp.api.montoya.http.message.requests.HttpRequest;
import burp.api.montoya.ui.Selection;
Expand Down Expand Up @@ -60,7 +60,7 @@ public synchronized boolean isEnabledFor(HttpRequestResponse requestResponse) {
HttpRequest request = requestResponse.request();
if (request != null && !request.bodyToString().equals("Loading...")) {
List<Map<String, String>> result = messageProcessor.processRequest("", request, false);
jTabbedPane = generateTabbedPaneFromResultMap(api, result);
generateTabbedPaneFromResultMap(api, jTabbedPane, result);
return jTabbedPane.getTabCount() > 0;
}
return false;
Expand All @@ -81,7 +81,8 @@ public Selection selectedData() {
return new Selection() {
@Override
public ByteArray contents() {
return ByteArray.byteArray(Datatable.getSelectedData(((Datatable) jTabbedPane.getSelectedComponent()).getDataTable()));
Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent();
return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable()));
}

@Override
Expand All @@ -97,8 +98,8 @@ public boolean isModified() {
}
}

public static JTabbedPane generateTabbedPaneFromResultMap(MontoyaApi api, List<Map<String, String>> result) {
JTabbedPane tabbedPane = new JTabbedPane();
public static void generateTabbedPaneFromResultMap(MontoyaApi api, JTabbedPane tabbedPane, List<Map<String, String>> result) {
tabbedPane.removeAll();
if (result != null && !result.isEmpty() && result.size() > 0) {
Map<String, String> dataMap = result.get(0);
if (dataMap != null && !dataMap.isEmpty() && dataMap.size() > 0) {
Expand All @@ -109,7 +110,5 @@ public static JTabbedPane generateTabbedPaneFromResultMap(MontoyaApi api, List<M
});
}
}

return tabbedPane;
}
}
9 changes: 5 additions & 4 deletions src/main/java/hae/instances/editor/ResponseEditor.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package hae.instances.editor;

import burp.api.montoya.MontoyaApi;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.core.Range;
import burp.api.montoya.http.message.HttpRequestResponse;
import burp.api.montoya.http.message.responses.HttpResponse;
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpResponseEditor;
import burp.api.montoya.ui.editor.extension.HttpResponseEditorProvider;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.core.Range;
import burp.api.montoya.ui.Selection;
import hae.component.board.Datatable;
import hae.instances.http.utils.MessageProcessor;
Expand Down Expand Up @@ -59,7 +59,7 @@ public synchronized boolean isEnabledFor(HttpRequestResponse requestResponse) {
HttpResponse request = requestResponse.response();
if (request != null && !request.bodyToString().equals("Loading...")) {
List<Map<String, String>> result = messageProcessor.processResponse("", request, false);
jTabbedPane = RequestEditor.generateTabbedPaneFromResultMap(api, result);
RequestEditor.generateTabbedPaneFromResultMap(api, jTabbedPane, result);
return jTabbedPane.getTabCount() > 0;
}
return false;
Expand All @@ -80,7 +80,8 @@ public Selection selectedData() {
return new Selection() {
@Override
public ByteArray contents() {
return ByteArray.byteArray(Datatable.getSelectedData(((Datatable) jTabbedPane.getSelectedComponent()).getDataTable()));
Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent();
return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable()));
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hae/instances/editor/WebSocketEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean isEnabledFor(WebSocketMessage webSocketMessage) {
String websocketMessage = webSocketMessage.payload().toString();
if (!websocketMessage.isEmpty()) {
List<Map<String, String>> result = messageProcessor.processMessage("", websocketMessage, false);
jTabbedPane = RequestEditor.generateTabbedPaneFromResultMap(api, result);
RequestEditor.generateTabbedPaneFromResultMap(api, jTabbedPane, result);
return jTabbedPane.getTabCount() > 0;
}
return false;
Expand All @@ -76,7 +76,8 @@ public Selection selectedData() {
return new Selection() {
@Override
public ByteArray contents() {
return ByteArray.byteArray(Datatable.getSelectedData(((Datatable) jTabbedPane.getSelectedComponent()).getDataTable()));
Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent();
return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable()));
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/hae/instances/http/utils/RegularMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public Map<String, Map<String, Object>> match(String host, String type, String m
case "response body":
matchContent = body;
break;
case "request line":
case "response line":
matchContent = message.split("\\r?\\n", 2)[0];
break;
default:
break;
}
Expand Down

0 comments on commit ca773f3

Please sign in to comment.