Is there a way to access EncodeDecodeResult from a python script? I cannot import it. When I create an Encode/Decode script and return a simple string I get the following error.
java.lang.ClassCastException: class java.lang.String cannot be cast to class org.zaproxy.addon.encoder.processors.EncodeDecodeResult (java.lang.String is in module java.base of loader 'bootstrap'; org.zaproxy.addon.encoder.processors.EncodeDecodeResult is in unnamed module of loader org.zaproxy.zap.control.AddOnClassLoader @440b6dca)
When I try to import the module like this
import org.zaproxy.addon.encoder.processors.EncodeDecodeResult
I get
Traceback (most recent call last):
File "<script>", line 483, in process
ImportError: No module named addon
The first error seems to hint by saying that org.zaproxy.addon.encoder.processors.EncodeDecodeResult is in unnamed module of loader org.zaproxy.zap.control.AddOnClassLoader
, but I don't know how to use that.
An ugly hack I found is to raise an exception with the result string which will show the result on the encoder/decoder view. That would have been somewhat acceptable if it didn't disable the module after that.
Here's a basic example of a Python (Jython) script for Zap's Encode/Decode/Hash functionality. This example simply appends the string TEST
to the end of whatever is input.
from org.zaproxy.addon.encoder.processors import EncodeDecodeResult
def process(value):
return EncodeDecodeResult(value+"TEST");
I'll work on getting a template added to the various scripting add-ons.
For further reference (just in case): https://www.jython.org/jython-old-sites/archive/21/docs/usejava.html