-
-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kberg
committed
Jun 13, 2020
1 parent
4c99d2d
commit f13468a
Showing
13 changed files
with
266 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
addOns/kotlin/src/main/java/org/zaproxy/zap/extension/kotlin/ExtensionKotlin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2020 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.zap.extension.kotlin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.swing.*; | ||
import org.apache.log4j.Logger; | ||
import org.parosproxy.paros.control.Control; | ||
import org.parosproxy.paros.extension.Extension; | ||
import org.parosproxy.paros.extension.ExtensionAdaptor; | ||
import org.parosproxy.paros.extension.ExtensionHook; | ||
import org.parosproxy.paros.view.View; | ||
import org.zaproxy.zap.ZAP; | ||
import org.zaproxy.zap.control.AddOnLoader; | ||
import org.zaproxy.zap.control.ExtensionFactory; | ||
import org.zaproxy.zap.extension.script.ExtensionScript; | ||
|
||
public class ExtensionKotlin extends ExtensionAdaptor { | ||
|
||
public static final String NAME = "ExtensionKotlin"; | ||
public static final int EXTENSION_ORDER = 9999; | ||
public static final ImageIcon KOTLIN_ICON; | ||
private static final List<Class<? extends Extension>> EXTENSION_DEPENDENCIES; | ||
private static final Logger LOGGER = Logger.getLogger(ExtensionKotlin.class); | ||
|
||
static { | ||
List<Class<? extends Extension>> dependencies = new ArrayList<>(1); | ||
dependencies.add(ExtensionScript.class); | ||
EXTENSION_DEPENDENCIES = Collections.unmodifiableList(dependencies); | ||
|
||
KOTLIN_ICON = | ||
View.isInitialised() | ||
? new ImageIcon( | ||
ExtensionKotlin.class.getResource( | ||
"/org/zaproxy/zap/extension/kotlin/resources/kotlin.png")) | ||
: null; | ||
} | ||
|
||
public ExtensionKotlin() { | ||
super(NAME); | ||
setOrder(EXTENSION_ORDER); | ||
} | ||
|
||
@Override | ||
public void hook(ExtensionHook extensionHook) { | ||
super.hook(extensionHook); | ||
|
||
LOGGER.debug("Hooking Kotlin Scripting Extension"); | ||
String zapJar = ZAP.class.getProtectionDomain().getCodeSource().getLocation().getFile(); | ||
|
||
LOGGER.debug("Loading Kotlin engine..."); | ||
AddOnLoader addonLoader = ExtensionFactory.getAddOnLoader(); | ||
Arrays.stream(addonLoader.getURLs()).forEach(LOGGER::debug); | ||
KotlinScriptEngineFactory factory = new KotlinScriptEngineFactory(addonLoader, zapJar); | ||
getExtScript().registerScriptEngineWrapper(new KotlinEngineWrapper(factory)); | ||
LOGGER.debug("Kotlin engine loaded."); | ||
} | ||
|
||
public List<Class<? extends Extension>> getDependencies() { | ||
return EXTENSION_DEPENDENCIES; | ||
} | ||
|
||
private ExtensionScript getExtScript() { | ||
return Control.getSingleton().getExtensionLoader().getExtension(ExtensionScript.class); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
addOns/kotlin/src/main/java/org/zaproxy/zap/extension/kotlin/KotlinEngineWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2020 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.zap.extension.kotlin; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import javax.script.ScriptEngineFactory; | ||
import javax.swing.*; | ||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants; | ||
import org.zaproxy.zap.extension.script.DefaultEngineWrapper; | ||
|
||
public class KotlinEngineWrapper extends DefaultEngineWrapper { | ||
|
||
@Override | ||
public ImageIcon getIcon() { | ||
return ExtensionKotlin.KOTLIN_ICON; | ||
} | ||
|
||
@Override | ||
public String getSyntaxStyle() { | ||
return SyntaxConstants.SYNTAX_STYLE_NONE; | ||
} | ||
|
||
@Override | ||
public boolean isRawEngine() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> getExtensions() { | ||
return Collections.singletonList("kts"); | ||
} | ||
|
||
public KotlinEngineWrapper(ScriptEngineFactory factory) { | ||
super(factory); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
addOns/kotlin/src/main/java/org/zaproxy/zap/extension/kotlin/KotlinScriptEngineFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2020 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.zap.extension.kotlin; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import javax.script.Bindings; | ||
import javax.script.ScriptContext; | ||
import javax.script.ScriptEngine; | ||
import kotlin.jvm.JvmClassMappingKt; | ||
import kotlin.reflect.KClass; | ||
import kotlin.script.experimental.jvm.util.JvmClasspathUtilKt; | ||
import org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineFactoryBase; | ||
import org.jetbrains.kotlin.cli.common.repl.ScriptArgsWithTypes; | ||
import org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine; | ||
import org.jetbrains.kotlin.script.jsr223.KotlinStandardJsr223ScriptTemplate; | ||
|
||
public class KotlinScriptEngineFactory extends KotlinJsr223JvmScriptEngineFactoryBase { | ||
|
||
private final List<File> jars; | ||
|
||
public KotlinScriptEngineFactory(ClassLoader classLoader, String zapJar) { | ||
List<File> clJars = | ||
JvmClasspathUtilKt.scriptCompilationClasspathFromContextOrStdlib( | ||
new String[] {"kotlin-stdlib"}, classLoader, true); | ||
if (zapJar != null) { | ||
clJars.add(new File(zapJar)); | ||
} | ||
jars = clJars; | ||
} | ||
|
||
@Override | ||
public ScriptEngine getScriptEngine() { | ||
return new KotlinJsr223JvmLocalScriptEngine( | ||
this, | ||
jars, | ||
KotlinStandardJsr223ScriptTemplate.class.getName(), | ||
(ctx, types) -> | ||
new ScriptArgsWithTypes( | ||
new Bindings[] {ctx.getBindings(ScriptContext.ENGINE_SCOPE)}, | ||
types), | ||
new KClass<?>[] {JvmClassMappingKt.getKotlinClass(Bindings.class)}); | ||
} | ||
} |
76 changes: 0 additions & 76 deletions
76
addOns/kotlin/src/main/kotlin/org/zaproxy/zap/extension/kotlin/ExtensionKotlin.kt
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
addOns/kotlin/src/main/kotlin/org/zaproxy/zap/extension/kotlin/KotlinEngineWrapper.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.