Skip to content

Commit

Permalink
Added standalone script 'PrivateMethodAccess.js'
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Bennetts <[email protected]>
  • Loading branch information
psiinon committed Aug 6, 2024
1 parent 4e0d979 commit 62f0519
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions standalone/PrivateMethodAccess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
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 code 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, e.g. for passing parameters.
print(MethodUtils.invokeMethod(extAlert, true, "getAlertPanel"));

0 comments on commit 62f0519

Please sign in to comment.