Skip to content

Commit

Permalink
## [v1.1.17] - 2024-02-29
Browse files Browse the repository at this point in the history
### Changed
- bugfix: fixed bug in strange text cursor caret movement in the StyledDocumentWithChunk which has JComponents.
- bugfix: fixed bug in dissapeared CR Jlabel component while editing in the ParmGenRegex. 
- bugfix: fixed bug in getting into infinite loop after sending request which contain no contents.
- bugfix: fixed bug in problem when it cannot be displayed as ImageIcon in the StyledDocumentWithChunk.
- maintenance: Added Deprecated Annotation for no meaning doing things in PRequest.
  • Loading branch information
gdgd009xcd authored Feb 29, 2024
2 parents 1cd4738 + 864a6d9 commit 64b630e
Show file tree
Hide file tree
Showing 16 changed files with 611 additions and 272 deletions.
8 changes: 8 additions & 0 deletions addOns/automacrobuilder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to this add-on will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [v1.1.17] - 2024-02-29
### Changed
- bugfix: fixed bug in strange text cursor caret movement in the StyledDocumentWithChunk which has JComponents.
- bugfix: fixed bug in dissapeared CR Jlabel component while editing in the ParmGenRegex.
- bugfix: fixed bug in getting into infinite loop after sending request which contain no contents.
- bugfix: fixed bug in problem when it cannot be displayed as ImageIcon in the StyledDocumentWithChunk.
- maintenance: Added Deprecated Annotation for no meaning doing things in PRequest.

## [v1.1.16] - 2024-02-02
### Changed
- bugfix: fixed bug in tracking token68 in Authorization bearer header(which used in OAuth2.0)
Expand Down
2 changes: 1 addition & 1 deletion addOns/automacrobuilder/automacrobuilder.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.zaproxy.gradle.addon.AddOnStatus

version = "1.1.16"
version = "1.1.17"
description = "AutoMacroBuilder for ZAP"

tasks.withType<JavaCompile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class PRequest extends ParseHTTPHeaders {
private static org.apache.logging.log4j.Logger LOGGER4J =
org.apache.logging.log4j.LogManager.getLogger();

// @Deprecated(since = "1.2", forRemoval = true) 20240229 since no need hold chunks in this PRequest.
private List<RequestChunk> chunks = null;
// @Deprecated(since = "1.2", forRemoval = true) 20240229 since no need hold doctext in this PRequest.
private String doctext = null;

public PRequest(String h, int p, boolean ssl, byte[] _binmessage, Encode _pageenc) {
Expand All @@ -48,14 +50,17 @@ public PRequest(String h, int p, boolean ssl, byte[] _binmessage, Encode _pageen
* create instance
* pass argument chunkdoc, extract doctext from chunkdoc
*
* @Deprecated 20240229 since no need hold chunks/doctext in this PRequest.
*
* @param h
* @param p
* @param ssl
* @param _binmessage
* @param _pageenc
* @param chunkdoc
*/
public PRequest(
@Deprecated(since = "1.2", forRemoval = true)
PRequest(
String h,
int p,
boolean ssl,
Expand All @@ -65,11 +70,7 @@ public PRequest(
super(h, p, ssl, _binmessage, _pageenc);
if (chunkdoc != null) {
chunks = chunkdoc.getRequestChunks();
try {
doctext = chunkdoc.getText(0, chunkdoc.getLength());
} catch (BadLocationException ex) {
Logger.getLogger(PRequest.class.getName()).log(Level.SEVERE, null, ex);
}
doctext = chunkdoc.getPlaceHolderStyleText();
}
}

Expand Down Expand Up @@ -99,8 +100,11 @@ public PRequest clone() {
/**
* Get List<RequestChunk> which is parsed request contents representation
*
* @Deprecated 20240229 since no need hold chunks/doctext in this PRequest.
*
* @return
*/
@Deprecated(since = "1.2", forRemoval = true)
public List<RequestChunk> getRequestChunks() {
if (this.chunks == null) {
String theaders = getHeaderOnly();
Expand All @@ -111,19 +115,37 @@ public List<RequestChunk> getRequestChunks() {
return this.chunks;
}

/**
* generate List<RequestChunk> which is parsed request contents representation
* @return
*/
public List<RequestChunk> generateRequestChunks() {
List<RequestChunk> chunks;
String theaders = getHeaderOnly();
byte[] tbodies = getBodyBytes();
String tcontent_type = getHeader("Content-Type");
chunks = getRequestChunks(theaders, tbodies, tcontent_type);
return chunks;
}

/**
* set doc text from StyledDocumentWithChunks(representating for PRequest)
*
* @Deprecated 20240229 since no need hold chunks/doctext in this PRequest.
*
* @param doc
*/
@Deprecated(since = "1.2", forRemoval = true)
public void setDocText(StyledDocumentWithChunk doc) {
try {
this.doctext = doc.getText(0, doc.getLength());
} catch (BadLocationException ex) {
Logger.getLogger(PRequest.class.getName()).log(Level.SEVERE, null, ex);
}
this.doctext = doc.getPlaceHolderStyleText();
}

/**
* @Deprecated 20240229 since no need hold chunks/doctext in this PRequest.
*
* @return
*/
@Deprecated(since = "1.2", forRemoval = true)
public String getDocText() {
return this.doctext;
}
Expand Down Expand Up @@ -301,8 +323,11 @@ private List<RequestChunk> getRequestChunks(
/**
* update DocText and Chunks with specified chunks
*
* @Deprecated 20240229 since no need hold chunks/doctext in this PRequest.
*
* @param orgchunks
*/
@Deprecated(since = "1.2", forRemoval = true)
void updateDocAndChunks(List<RequestChunk> orgchunks) {

if (orgchunks == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private List<PResponse.ResponseChunk> getResponseChunks(
}

boolean displayableTextContents = false;
if (tbodies.length < MAX_SIZE_DISPLAYABLE_TEXTS) {
if (tbodies != null && tbodies.length < MAX_SIZE_DISPLAYABLE_TEXTS) {
if (mediaType.equalsIgnoreCase("text/html")) {
displayableTextContents = true;
} else if (!application_json_contents.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,16 @@ public void updateOriginalBase(ParmGenMacroTrace runningInstance) {
ent -> {
int i = ent.getKey();
if (i < this.rlist.size()) {
/**
List<RequestChunk> orgchunks =
this.rlist
.get(i)
.request
.getRequestChunks(); // current display content chunks.
.generateRequestChunks(); // current display content chunks.
ent.getValue()
.request
.updateDocAndChunks(orgchunks); // update chunks if possible.
**/
this.rlist.set(i, ent.getValue());
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.zaproxy.zap.extension.automacrobuilder;

import java.util.stream.IntStream;

import static java.util.stream.Collectors.joining;

public class PrintableString {

private String nonPrintableString = null;

public PrintableString(String nonPrintableString) {
this.nonPrintableString = nonPrintableString;
}

public String convert(int len) {
return convert(this.nonPrintableString, len);
}

public String convert(String original, int len) {
this.nonPrintableString = original;

if (original == null || original.isEmpty()) {
return "";
} else if (len > 0 && len < original.length()) {
int divideLen = len / 2;
int reminderlen = len % 2;
int originalLen = original.length();
original = original.substring(0, divideLen + reminderlen) + "..." + original.substring(originalLen - divideLen, originalLen);
}

String convertedString = "";
try (IntStream istream = original.chars()) { // after executed, then this resource automatically be freed.

convertedString = istream.mapToObj(ci -> {
String value = "";
if (ci <= 0x001f || ci == 0x007f || (ci >= 0x0080)) {
try {
value = String.format("%%%02x", ci);
} catch (Exception e) {
}
} else {
value = String.valueOf((char) ci);
}
return value;
}).collect(joining());
}

return convertedString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public enum CHUNKTYPE {
CHUNKTYPE ctype;
byte[] data;
int partno;
int textPos;// text position in StyledDocument
int textLen;// text length in StyledDocument

RequestChunk(CHUNKTYPE ctype, byte[] data, int partno) {
this.ctype = ctype;
this.data = data;
this.partno = partno;
this.textPos = -1;
this.textLen = -1;
}

/**
Expand Down Expand Up @@ -66,6 +70,19 @@ public int getPartNo() {
return this.partno;
}

public void setTextPosLen(int textPos, int textLen) {
this.textPos = textPos;
this.textLen = textLen;
}

public int getTextPos() {
return this.textPos;
}

public int getTextLen() {
return this.textLen;
}

public RequestChunk clone() {
try {
RequestChunk nobj = (RequestChunk) super.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.regex.Pattern;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.JTextComponent;
import javax.swing.text.StyledDocument;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -2189,10 +2190,10 @@ public String getMessageRequest() {
/**
* update current PRequestResponse with Edited(displayed) PRequestResponse
*
* @param doc
* @param changedDoc
*/
@Override
public void ParmGenRegexSaveAction(StyledDocumentWithChunk doc) {
public void ParmGenRegexSaveAction(StyledDocumentWithChunk changedDoc) {
int selectedTabIndex = getSelectedTabIndexOfMacroRequestList();
ParmGenMacroTrace pmt = getParmGenMacroTraceAtTabIndex(selectedTabIndex);
if (pmt == null) return;
Expand All @@ -2202,15 +2203,25 @@ public void ParmGenRegexSaveAction(StyledDocumentWithChunk doc) {
int idx = requestJList.getSelectedIndex();
if(prequestResponseList != null && idx > -1 && idx < prequestResponseList.size()){
try {
/**
PRequest newrequest = doc.reBuildPRequestFromDocTextAndChunks();// get edited request
if (newrequest != null) {
pmt.updateRequestCurrentList(idx, newrequest);// copy edited request to current request
JTextPaneContents ndoc = new JTextPaneContents(messageRequest);
ndoc.setRequestChunks(newrequest);
pmt.nullfetchResValAndCookieMan();
}
**/
if (changedDoc != null) {
if (changedDoc.isRequest()) {
// update only the StyledDocument in messageRequest
StyledDocumentWithChunk updatedDoc = new StyledDocumentWithChunk(changedDoc);
messageRequest.setStyledDocument((StyledDocument) updatedDoc);
pmt.nullfetchResValAndCookieMan();
}
}
} catch (Exception ex) {
Logger.getLogger(MacroBuilderUI.class.getName()).log(Level.SEVERE, null, ex);
LOGGER4J.error(ex.getMessage(), ex);
}
}
}
Expand Down
Loading

0 comments on commit 64b630e

Please sign in to comment.