forked from mwielgoszewski/jython-burp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJythonFactory.java
More file actions
45 lines (33 loc) · 1.24 KB
/
JythonFactory.java
File metadata and controls
45 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import org.python.util.PythonInterpreter;
public class JythonFactory
{
private static JythonFactory instance = null;
public synchronized static JythonFactory getInstance()
{
if (instance == null)
instance = new JythonFactory();
return instance;
}
public static Object getJythonObject(String interfaceName, String pathToJythonModule)
{
Object jyObject = null;
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile(pathToJythonModule);
String tempName = pathToJythonModule.substring(pathToJythonModule.lastIndexOf("/") + 1);
tempName = tempName.substring(0, tempName.indexOf("."));
String instanceName = tempName.toLowerCase();
String javaClassName = tempName.substring(0, 1).toUpperCase() + tempName.substring(1);
String objectDef = " = " + javaClassName + "()";
interpreter.exec(instanceName + objectDef);
try
{
Class JavaInterface = Class.forName(interfaceName);
jyObject = interpreter.get(instanceName).__tojava__(JavaInterface);
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
return jyObject;
}
}