Skip to content

Commit

Permalink
zzzzzzZZZZZZzzzzz
Browse files Browse the repository at this point in the history
  • Loading branch information
aress31 committed Dec 24, 2023
1 parent 052c8fd commit c68be9e
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 99 deletions.
6 changes: 3 additions & 3 deletions src/main/java/burp/MyContextMenuItemsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

import swurg.gui.components.tables.models.ParserTableModel;
import swurg.gui.views.ParserPanel;
import swurg.utilities.RequestWithMetadata;
import swurg.workers.Worker;
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.http.message.HttpRequestResponse;
import burp.api.montoya.http.message.requests.HttpRequest;
import burp.api.montoya.logging.Logging;
import burp.api.montoya.ui.contextmenu.ContextMenuEvent;
import burp.api.montoya.ui.contextmenu.ContextMenuItemsProvider;
import burp.http.MyHttpRequest;

public class MyContextMenuItemsProvider implements ContextMenuItemsProvider {
private MontoyaApi montoyaApi;
Expand Down Expand Up @@ -48,10 +48,10 @@ public List<Component> provideMenuItems(ContextMenuEvent contextMenuEvent) {
String url = selectedRequest.url();

ParserTableModel tableModel = (ParserTableModel) parserPanel.getTable().getModel();
List<RequestWithMetadata> requestWithMetadatas = worker.parseOpenAPI(worker.processOpenAPI(url));
List<MyHttpRequest> myHttpRequests = worker.parseOpenAPI(worker.processOpenAPI(url));

SwingUtilities.invokeLater(() -> {
requestWithMetadatas.forEach(requestWithMetadata -> tableModel.addRow(requestWithMetadata));
myHttpRequests.forEach(myHttpRequest -> tableModel.addRow(myHttpRequest));

parserPanel.getResourceTextField().setText(url);
parserPanel.getStatusPanel().updateStatus(COPYRIGHT, UIManager.getColor("TextField.foreground"));
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/swurg/gui/MainTabGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import javax.swing.JTabbedPane;

import burp.api.montoya.MontoyaApi;
import burp.http.MyHttpRequest;
import swurg.gui.views.AboutPanel;
import swurg.gui.views.ParametersPanel;
import swurg.gui.views.ParserPanel;
import swurg.observers.ParserTableModelObserver;
import swurg.utilities.RequestWithMetadata;

import lombok.Data;

Expand All @@ -23,11 +23,11 @@ public class MainTabGroup extends JTabbedPane implements ParserTableModelObserve
private ParametersPanel parametersPanel;
private AboutPanel aboutPanel;

List<RequestWithMetadata> requestWithMetadatas;
List<MyHttpRequest> myHttpRequests;

public MainTabGroup(MontoyaApi montoyaApi) {
this.montoyaApi = montoyaApi;
this.requestWithMetadatas = new ArrayList<>();
this.myHttpRequests = new ArrayList<>();

initComponents();

Expand All @@ -37,21 +37,21 @@ public MainTabGroup(MontoyaApi montoyaApi) {
}

private void initComponents() {
parserPanel = new ParserPanel(montoyaApi, requestWithMetadatas);
parserPanel = new ParserPanel(montoyaApi, myHttpRequests);
aboutPanel = new AboutPanel();
parametersPanel = new ParametersPanel(montoyaApi, requestWithMetadatas);
parametersPanel = new ParametersPanel(montoyaApi, myHttpRequests);

addTab("Parser", parserPanel);
addTab("About", aboutPanel);
}

@Override
public void onRequestWithMetadatasUpdate() {
if (indexOfComponent(parametersPanel) == -1 && !requestWithMetadatas.isEmpty()) {
if (indexOfComponent(parametersPanel) == -1 && !myHttpRequests.isEmpty()) {
removeTabAt(indexOfComponent(aboutPanel));
addTab("Parameters", parametersPanel);
addTab("About", aboutPanel);
} else if (indexOfComponent(parametersPanel) != -1 && requestWithMetadatas.isEmpty())
} else if (indexOfComponent(parametersPanel) != -1 && myHttpRequests.isEmpty())
removeTabAt(indexOfComponent(parametersPanel));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import javax.swing.table.AbstractTableModel;

import burp.http.MyHttpParameter;
import burp.http.MyHttpRequest;
import lombok.Data;
import swurg.utilities.RequestWithMetadata;

@Data
public class ParametersTableModel extends AbstractTableModel {
Expand All @@ -21,29 +21,29 @@ public ParametersTableModel(Set<MyHttpParameter> httpParameters) {
this.httpParameters = httpParameters;
}

public static ParametersTableModel fromRequestWithMetadataList(List<RequestWithMetadata> requestWithMetadatas) {
public static ParametersTableModel fromRequestWithMetadataList(List<MyHttpRequest> myHttpRequests) {
Set<MyHttpParameter> httpParameters = new LinkedHashSet<>();

requestWithMetadatas.forEach(requestWithMetadata -> requestWithMetadata.getHttpRequest().parameters()
.forEach(httpParameter -> httpParameters
.add(MyHttpParameter.builder().httpParameter(httpParameter).build())));
myHttpRequests.forEach(myHttpRequest -> myHttpRequest.getHttpRequest().parameters()
.forEach(myHttpParameter -> httpParameters
.add(MyHttpParameter.builder().httpParameter(myHttpParameter).build())));

return new ParametersTableModel(httpParameters);
}

public void updateData(List<RequestWithMetadata> requestWithMetadatas) {
public void updateData(List<MyHttpRequest> myHttpRequests) {
Set<MyHttpParameter> httpParameters = new LinkedHashSet<>();

requestWithMetadatas.forEach(requestWithMetadata -> requestWithMetadata.getHttpRequest().parameters()
.forEach(httpParameter -> httpParameters
.add(MyHttpParameter.builder().httpParameter(httpParameter).build())));
myHttpRequests.forEach(myHttpRequest -> myHttpRequest.getHttpRequest().parameters()
.forEach(myHttpParameter -> httpParameters
.add(MyHttpParameter.builder().httpParameter(myHttpParameter).build())));

this.httpParameters = httpParameters;
}

public void addRow(MyHttpParameter httpParameter) {
public void addRow(MyHttpParameter myHttpParameter) {
int rowCount = getRowCount();
httpParameters.add(httpParameter);
httpParameters.add(myHttpParameter);
fireTableRowsInserted(rowCount, rowCount);
}

Expand Down Expand Up @@ -82,19 +82,19 @@ public Class<?> getColumnClass(int column) {

@Override
public Object getValueAt(int row, int column) {
MyHttpParameter httpParameter = getHttpParameterAt(row);
MyHttpParameter myHttpParameter = getHttpParameterAt(row);

switch (column) {
case 0:
return row;
case 1:
return httpParameter.getHttpParameter().name();
return myHttpParameter.getHttpParameter().name();
case 2:
return httpParameter.getHttpParameter().type().toString();
return myHttpParameter.getHttpParameter().type().toString();
case 3:
return httpParameter.getHttpParameter().value();
return myHttpParameter.getHttpParameter().value();
case 4:
return httpParameter.getEditedValue();
return myHttpParameter.getEditedValue();
default:
throw new IllegalArgumentException("Invalid column index");
}
Expand All @@ -107,9 +107,9 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
String editedValue = (String) aValue;

if (editedValue != null && !editedValue.trim().isEmpty()) {
MyHttpParameter httpParameter = getHttpParameterAt(rowIndex);
if (httpParameter != null) {
httpParameter.setEditedValue(editedValue);
MyHttpParameter myHttpParameter = getHttpParameterAt(rowIndex);
if (myHttpParameter != null) {
myHttpParameter.setEditedValue(editedValue);

// Notify the table that the data has changed
fireTableCellUpdated(rowIndex, columnIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
import burp.api.montoya.http.message.params.HttpParameterType;
import burp.api.montoya.http.message.params.ParsedHttpParameter;
import burp.api.montoya.http.message.requests.HttpRequest;
import burp.http.MyHttpRequest;
import lombok.Data;
import swurg.observers.ParserTableModelObserver;
import swurg.observers.ParametersPanelObserver;
import swurg.utilities.RequestWithMetadata;

@Data
public class ParserTableModel extends AbstractTableModel {

private List<RequestWithMetadata> requestWithMetadatas;
private List<MyHttpRequest> myHttpRequests;
private String[] columnNames = { "#", "Scheme", "Method", "Server", "Path", "Parameters (COOKIE, URL)",
"Description" };

// Add a list to hold the observers
private List<ParserTableModelObserver> observers = new ArrayList<>();
private List<ParametersPanelObserver> parametersPanelObservers = new ArrayList<>();

public ParserTableModel(List<RequestWithMetadata> requestWithMetadatas) {
this.requestWithMetadatas = requestWithMetadatas;
public ParserTableModel(List<MyHttpRequest> myHttpRequests) {
this.myHttpRequests = myHttpRequests;
}

public void addRow(RequestWithMetadata requestWithMetadata) {
public void addRow(MyHttpRequest myHttpRequest) {
int rowCount = getRowCount();
requestWithMetadatas.add(requestWithMetadata);
myHttpRequests.add(myHttpRequest);
fireTableRowsInserted(rowCount, rowCount);
notifyObservers();
}

public void removeRow(int rowIndex) {
requestWithMetadatas.remove(rowIndex);
myHttpRequests.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
notifyObservers();
}

public void clear() {
requestWithMetadatas.clear();
myHttpRequests.clear();
fireTableDataChanged();
notifyObservers();
}
Expand Down Expand Up @@ -82,12 +82,12 @@ private void notifyParametersPanelObservers() {
}

public HttpRequest getHttpRequestAt(int rowIndex) {
return requestWithMetadatas.get(rowIndex).getHttpRequest();
return myHttpRequests.get(rowIndex).getHttpRequest();
}

@Override
public int getRowCount() {
return requestWithMetadatas.size();
return myHttpRequests.size();
}

@Override
Expand All @@ -110,28 +110,28 @@ public Class<?> getColumnClass(int column) {

@Override
public Object getValueAt(int row, int column) {
RequestWithMetadata requestWithMetadata = requestWithMetadatas.get(row);
MyHttpRequest myHttpRequest = myHttpRequests.get(row);

switch (column) {
case 0:
return row;
case 1:
return requestWithMetadata.getHttpRequest().httpService().secure() ? "HTTPS" : "HTTP";
return myHttpRequest.getHttpRequest().httpService().secure() ? "HTTPS" : "HTTP";
case 2:
return requestWithMetadata.getHttpRequest().method();
return myHttpRequest.getHttpRequest().method();
case 3:
return requestWithMetadata.getHttpRequest().httpService().host();
return myHttpRequest.getHttpRequest().httpService().host();
case 4:
return requestWithMetadata.getHttpRequest().path();
return myHttpRequest.getHttpRequest().path();
case 5:
return requestWithMetadata.getHttpRequest().parameters()
return myHttpRequest.getHttpRequest().parameters()
.stream()
.filter(parameter -> parameter.type() == HttpParameterType.COOKIE
|| parameter.type() == HttpParameterType.URL)
.map(ParsedHttpParameter::name)
.collect(Collectors.joining(", "));
case 6:
return requestWithMetadata.getDescription() != null ? requestWithMetadata.getDescription() : "N/A";
return myHttpRequest.getDescription() != null ? myHttpRequest.getDescription() : "N/A";
default:
throw new IllegalArgumentException("Invalid column index");
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/swurg/gui/views/ParametersPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import burp.api.montoya.logging.Logging;
import burp.http.MyHttpParameter;
import burp.http.MyHttpRequest;
import burp.api.montoya.http.handler.HttpHandler;
import burp.api.montoya.http.handler.HttpRequestToBeSent;
import burp.api.montoya.http.handler.HttpResponseReceived;
Expand All @@ -36,7 +37,6 @@
import swurg.gui.components.tables.renderers.CustomTableCellRenderer;
import swurg.observers.ParametersPanelObserver;
import swurg.utilities.HtmlResourceLoader;
import swurg.utilities.RequestWithMetadata;

public class ParametersPanel extends JPanel
implements HttpHandler, ParametersPanelObserver {
Expand All @@ -56,20 +56,20 @@ public class ParametersPanel extends JPanel
ToolType.SEQUENCER,
ToolType.TARGET);

private List<RequestWithMetadata> requestWithMetadatas;
private List<MyHttpRequest> myHttpRequests;

public ParametersPanel(MontoyaApi montoyaApi, List<RequestWithMetadata> requestWithMetadatas) {
public ParametersPanel(MontoyaApi montoyaApi, List<MyHttpRequest> myHttpRequests) {
this.logging = montoyaApi.logging();
this.requestWithMetadatas = requestWithMetadatas;
this.myHttpRequests = myHttpRequests;

parametersTableModel = ParametersTableModel.fromRequestWithMetadataList(requestWithMetadatas);
parametersTableModel = ParametersTableModel.fromRequestWithMetadataList(myHttpRequests);

initComponents();
}

@Override
public void onRequestWithMetadatasUpdate() {
parametersTableModel.updateData(requestWithMetadatas);
parametersTableModel.updateData(myHttpRequests);

}

Expand Down
Loading

0 comments on commit c68be9e

Please sign in to comment.