diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a45ee8..d884770c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ 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/). ## [Unreleased] +### Added +- Standalone script 'PrivateMethodAccess.js' ### Changed - Add cautionary note to help and readme. ### Fixed diff --git a/standalone/PrivateMethodAccess.js b/standalone/PrivateMethodAccess.js new file mode 100644 index 00000000..4d6f7725 --- /dev/null +++ b/standalone/PrivateMethodAccess.js @@ -0,0 +1,29 @@ +/* +When writing scripts you may find that you need to access private java methods. +This script shows how you can do this easily. + +WARNING: we do not consider private methods to be part of the public API, so they may +be changed or removed at any time. +If you think you have a strong case for making a method public then either: + +1. Ask on the ZAP Dev Group: https://groups.google.com/group/zaproxy-develop +2. Submit a pull request making the change (but be prepared for it to be rejected) + +*/ + +var ExtensionAlert = Java.type( + "org.zaproxy.zap.extension.alert.ExtensionAlert" +); +var MethodUtils = Java.type("org.apache.commons.lang3.reflect.MethodUtils"); + +extAlert = control.getExtensionLoader().getExtension(ExtensionAlert); + +print(extAlert); + +// Note that there are a lot of other methods in MethodUtils if these are not what you are looking for. + +// Call a private method with no parameters +print(MethodUtils.invokeMethod(extAlert, true, "getAlertPanel")); + +// Call a private method with parameters +print(MethodUtils.invokeMethod(extAlert, true, "applyOverride", "abc", "+def"));