Skip to content

Commit

Permalink
Merge pull request #17 from gdgd009xcd/PROCOPIUS231106
Browse files Browse the repository at this point in the history
23111201 PROCOPIUS231106
- new feature: added feature which is related to popup menu of CustomActiveScan
- new feature: Changed  behaviour of "SendMessage" popup menu. it shows animation what is doing.
- maintenance: updated typical.gif
  • Loading branch information
gdgd009xcd authored Nov 12, 2023
2 parents b2af2dc + 52cfe9f commit 160122a
Show file tree
Hide file tree
Showing 29 changed files with 1,188 additions and 140 deletions.
6 changes: 6 additions & 0 deletions addOns/automacrobuilder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
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.10] - 2023-11-12
### Changed
- new feature: added feature which is related to popup menu of CustomActiveScan
- new feature: Changed behaviour of "SendMessage" popup menu. it shows animation what is doing.
- maintenance: updated typical.gif

## [v1.1.9] - 2023-11-03
### Sorry..
- bugfix: Fixed strange behaviour in file load/save actions.
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.9"
version = "1.1.10"
description = "AutoMacroBuilder for ZAP"

tasks.withType<JavaCompile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public class CastUtils {
public static <T> T castToType(Object obj) {
return (T) obj;
}

public static <T> T castToType(Class<T> clazz, Object obj) {
if (clazz.isAssignableFrom(obj.getClass())) {
return clazz.cast(obj);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package org.zaproxy.zap.extension.automacrobuilder;

import org.zaproxy.zap.extension.automacrobuilder.generated.MacroBuilderUI;
import org.zaproxy.zap.extension.automacrobuilder.zap.ExtensionAutoMacroBuilder;

import javax.swing.*;
import java.awt.*;
import java.io.File;
Expand Down Expand Up @@ -74,6 +77,8 @@ public class EnvironmentVariables {
private static List<Pattern> ExcludeMimeTypesPatterns = null;
private static org.apache.logging.log4j.Logger LOGGER4J;

private static ExtensionAutoMacroBuilder extensionAutoMacroBuilder;

public static String JSONFileIANACharsetName =
Encode.UTF_8.getIANACharsetName(); // JSON file IN/OUT encoding
public static String DefaultCSVFileIANACharsetName =
Expand All @@ -85,6 +90,8 @@ public class EnvironmentVariables {
static {
LOGGER4J = org.apache.logging.log4j.LogManager.getLogger();

extensionAutoMacroBuilder = null;

setExcludeMimeTypes(
Arrays.asList(
"image/.*",
Expand Down Expand Up @@ -272,6 +279,7 @@ public void approveSelection() {


jfc.setFileFilter(pFilter);
jfc.setAcceptAllFileFilterUsed(false);

int fileChooserSelection = jfc.showOpenDialog(parent);// OPEN_DIALOG

Expand Down Expand Up @@ -343,6 +351,7 @@ this, m, getZapResourceString(
jfc.setSelectedFile(cfile);
ParmFileFilter pFilter=new ParmFileFilter();
jfc.setFileFilter(pFilter);
jfc.setAcceptAllFileFilterUsed(false);

EnvironmentVariables.choosedFilePathName = null;
int fileChooserSelection = jfc.showSaveDialog(parent);
Expand All @@ -360,4 +369,37 @@ this, m, getZapResourceString(

return EnvironmentVariables.choosedFilePathName;
}

public static void setExtensionAutoMacroBuilder(ExtensionAutoMacroBuilder extensionAutoMacroBuilder) {
EnvironmentVariables.extensionAutoMacroBuilder = extensionAutoMacroBuilder;
}

private static void callCleanUp() {
if (EnvironmentVariables.extensionAutoMacroBuilder != null) {
EnvironmentVariables.extensionAutoMacroBuilder.cleanUp();
}
}

private static ParmGenMacroTraceProvider getParmGenMacroTraceProvider() {
if (EnvironmentVariables.extensionAutoMacroBuilder != null) {
return EnvironmentVariables.extensionAutoMacroBuilder.getParmGenMacroTraceProvider();
}
return null;
}

public static ParmGenMacroTrace getBaseInstanceOfParmGenMacroTrace(int tabIndex) {
ParmGenMacroTraceProvider pmtProvider = getParmGenMacroTraceProvider();
if (pmtProvider != null) {
return pmtProvider.getBaseInstance(tabIndex);
}
return null;
}

public static MacroBuilderUI getMacroBuilderUI() {
if (EnvironmentVariables.extensionAutoMacroBuilder != null) {
MacroBuilderUI ui = EnvironmentVariables.extensionAutoMacroBuilder.getMacroBuilderUI();
return ui;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.zaproxy.zap.extension.automacrobuilder;

import java.lang.reflect.Array;

/**
* <P>Create Generic Array.</P><P></P>
* Note: <BR>From java se api document,<BR>
* The number of dimensions of the new array must not exceed 255.<BR>
* GenericArray throws an IllegalArgumentException<BR>
* when assigning a class with 255 or more dimensions array to type parameter T.<p></p>
* @param <T>
*/
public class GenericArray<T> {
final private T[] genericArray;

@SuppressWarnings({"cast","unchecked"})
public GenericArray(Class<T> classType, int size) {
this.genericArray = (T[]) Array.newInstance(classType, size);
}
@SuppressWarnings({"cast","unchecked"})
public GenericArray(T object, int size) {
this.genericArray = (T[]) Array.newInstance(object.getClass(), size);
}

@SuppressWarnings("cast")
public T get(int index) {
return (T) this.genericArray[index];
}

public T[] getArray() {
return this.genericArray;
}

public void set(int index, T item) {
this.genericArray[index] = item;
}

public int size() {
return this.genericArray.length;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@
*/
package org.zaproxy.zap.extension.automacrobuilder;

import org.zaproxy.zap.extension.automacrobuilder.zap.MyWorkPanel;
import org.zaproxy.zap.utils.DisplayUtils;

import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.*;

import static org.zaproxy.zap.extension.automacrobuilder.EnvironmentVariables.ZAP_ICONS;

/** @author gdgd009xcd */
@SuppressWarnings("serial")
public class MacroBuilderUIRequestListRender extends DefaultListCellRenderer {
ParmGenMacroTrace pmt;
private static final ImageIcon A_TAB_ICON =
DisplayUtils.getScaledIcon(
new ImageIcon(MyWorkPanel.class.getResource(ZAP_ICONS + "/A.png")));

public MacroBuilderUIRequestListRender(ParmGenMacroTrace pmt) {
this.pmt = pmt;
Expand All @@ -42,6 +48,13 @@ public Component getListCellRendererComponent(
super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);

boolean isRunning = pmt.getRunningStepNo() == index;
if (isRunning && index >= 0) {
label.setIcon(A_TAB_ICON);
} else {
label.setIcon(null);
}

if (list.isSelectedIndex(index)) {
// 選択行はデフォルトの色
label.setBackground(list.getSelectionBackground());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.zaproxy.zap.extension.automacrobuilder.mdepend.ClientDependent;
import org.zaproxy.zap.extension.automacrobuilder.mdepend.ClientRequest;
import org.zaproxy.zap.extension.automacrobuilder.view.StyledDocumentWithChunk;
import org.zaproxy.zap.extension.automacrobuilder.view.SwingTimerFakeRunner;

/** @author gdgd009xcd */
public class ParmGenMacroTrace extends ClientDependent {
Expand Down Expand Up @@ -114,6 +115,8 @@ public class ParmGenMacroTrace extends ClientDependent {

private boolean isCacheNull = false;

private int runningStepNo = -1;// current running stepno. use only in base instance.

public String state_debugprint() {
String msg = "PMT_UNKNOWN";
switch (state) {
Expand Down Expand Up @@ -180,13 +183,18 @@ public void setAppParmsIniList(List<AppParmsIni> appParmsIniList) {
public ParmGenMacroTrace() {}

/**
* Get copy of this instance for scan
* create New running instance for scan
*
* @return
*/
public <T> ParmGenMacroTrace getScanInstance(
public <T> ParmGenMacroTrace createScanRunningInstance(
T sender, ParmGenMacroTraceParams pmtParams, ParmGenMacroTraceProvider pmtProvider) {
ParmGenMacroTrace nobj = new ParmGenMacroTrace();
SwingTimerFakeRunner swingRunner = pmtProvider.getSwingRunner(pmtParams.getTabIndex());
if (swingRunner != null) {
swingRunner.registRunningInstance(nobj);
}

nobj.sender = sender;
nobj.threadid = Thread.currentThread().getId();
// nobj.setUUID(UUIDGenerator.getUUID()); // already set in super.constructor
Expand Down Expand Up @@ -225,6 +233,8 @@ public <T> ParmGenMacroTrace getScanInstance(

nobj.isCacheNull = this.isCacheNull;

nobj.runningStepNo = this.runningStepNo;

return nobj;
}

Expand Down Expand Up @@ -280,6 +290,8 @@ public ParmGenMacroTrace getCopyInstanceForSession() {

nobj.isCacheNull = this.isCacheNull;

nobj.runningStepNo = this.runningStepNo;

return nobj;
}

Expand All @@ -302,6 +314,7 @@ public void clear() {
lastResponseEncode = null;
isURIOfRequestIsModified = false;
isCacheNull = false;
runningStepNo = -1;
nullfetchResValAndCookieMan();
}

Expand Down Expand Up @@ -517,7 +530,8 @@ public void startBeforePreMacro(OneThreadProcessor otp) {
oit = null;
cit = null;

stepno = 0;
this.stepno = 0;


try {
if (rlist != null && selected_request >= 0 && rlist.size() > selected_request) {
Expand All @@ -531,7 +545,7 @@ public void startBeforePreMacro(OneThreadProcessor otp) {
// copy clone.
PRequestResponse ppr = cit.next().clone();
PRequestResponse opr = oit.next().clone();
stepno = n;
this.stepno = n;
if (n++ >= selected_request) {
break;
}
Expand All @@ -551,7 +565,7 @@ public void startBeforePreMacro(OneThreadProcessor otp) {

LOGGER4J.debug(
"PreMacro StepNo:"
+ stepno
+ this.stepno
+ " "
+ ppr.request.getHost()
+ " "
Expand All @@ -569,7 +583,7 @@ public void startBeforePreMacro(OneThreadProcessor otp) {

if (pqrs != null) {
// cit.set(pqrs); // 更新
savelist.put(stepno, pqrs);
savelist.put(this.stepno, pqrs);
}

if (TWaiter != null) {
Expand Down Expand Up @@ -717,7 +731,6 @@ public void startPostMacro(OneThreadProcessor otp) {
} else {
state = PMT_POSTMACRO_NULL;
}

LOGGER4J.debug("END PostMacro X-Thread:" + threadid);
}

Expand Down Expand Up @@ -1281,6 +1294,11 @@ public List<AppParmsIni> getAppParmIniHasStepNoSpecified(int stepno) {
return hasnolist;
}

public ParmGenMacroTraceParams getParmGenMacroTraceParams(){
ParmGenMacroTraceParams pmtParams = new ParmGenMacroTraceParams(this.selected_request, this.last_stepno, this.tabIndex);
return pmtParams;
}

/**
* update AppParmsIni and clear cookie/token caches if newAppParmsIniList == null and
* getAppParmsIniList() != null then nothing to do(current ParmIniList remains)
Expand Down Expand Up @@ -1333,4 +1351,16 @@ public void setURIOfRequestIsModified(boolean b) {
public boolean isCacheNull() {
return this.isCacheNull;
}

public void setRunningStepNo(int step) {
this.runningStepNo = step;
}

public int getRunningStepNo() {
return this.runningStepNo;
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public ParmGenMacroTraceParams(int pos, int lastStepNo, int tabindex) {
this.tabIndex = tabindex;
}

public ParmGenMacroTraceParams(ParmGenMacroTraceParams pmtParams) {
this.selected_request = pmtParams.selected_request;
this.last_stepno = pmtParams.last_stepno;
this.tabIndex = pmtParams.getTabIndex();
}

public ParmGenMacroTraceParams(String hv) {
setString(hv);
}
Expand Down
Loading

0 comments on commit 160122a

Please sign in to comment.