Skip to content

Commit

Permalink
Merge pull request #462 from psiinon/standalone/private
Browse files Browse the repository at this point in the history
Added standalone script 'PrivateMethodAccess.js'
  • Loading branch information
psiinon authored Aug 6, 2024
2 parents 4e0d979 + 77401dd commit 433b960
Show file tree
Hide file tree
Showing 2 changed files with 31 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
29 changes: 29 additions & 0 deletions standalone/PrivateMethodAccess.js
Original file line number Diff line number Diff line change
@@ -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"));

0 comments on commit 433b960

Please sign in to comment.