Skip to content

Added standalone script 'PrivateMethodAccess.js' #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));