Skip to content

Commit b913c61

Browse files
author
Justine Osborne
committed
many fixes to pluginservice code as well as introduction of the AbstractJythonConsolePlugin, which provides easy acess to the JythonConsole. This could be useful when requiring interactivity. Eventually a better interactive commandline for plugins should be created.
WARNING: changes to pluginservice and new functionality has not yet been fully tested with all existing Java plugins
1 parent fd57806 commit b913c61

20 files changed

+231
-113
lines changed

AndroidSSLBypass/TODO.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
* Currently not calling tearDownEvents() always for plugins to remove breakpoints,
2-
etc.
1+
===Feature Requests===
2+
3+
* Ability to unload plugins on demand
34

4-
* maybe create an unload plugins command which removes all currently set events for that plugin ....
5+
* Multiple handler support for a single event (might be tricky)
56

6-
* Add support for all VM events (currently only four most used types supported)
7+
* Support for all VM events (http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/event/package-summary.html) - currently only four most used are supported
78

8-
* No support for multiple handlers for a single event
9+
* Support for interaction with the commandline via Jython plugins
10+
11+
===Random TODOs===
912

10-
* Make sure everything is platform independent and configurable
13+
* Currently not calling tearDownEvents() always for plugins to remove event requests
1114

12-
* Add documentation!!
15+
* Make sure everything is platform independent and configurable
1316

14-
* Add licensing info and thirdparty libs documentation
17+
* Add documentation!!
1518

16-
* Fix all the bugs :)
19+
* Add licensing info and thirdparty libs documentation
20+
21+
* Entire plugin service architecture should probably be reworked to something better and cleaner
22+
23+
* Fix all the bugs :)

AndroidSSLBypass/asb.jar

1.77 KB
Binary file not shown.

AndroidSSLBypass/defaults.prop

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
adb.location=D:/tools/android-sdk/platform-tools/adb.exe
1+
adb.location=/home/freeze/android-sdks/platform-tools/adb
22

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from com.isecpartners.android.jdwp.pluginservice import AbstractJythonConsolePlugin
2+
from com.isecpartners.android.jdwp import DalvikUtils
3+
import com.sun.jdi.event.Event
4+
5+
class TestJythonConsolePlugin(AbstractJythonConsolePlugin):
6+
7+
def __init__(self):
8+
AbstractJythonConsolePlugin.__init__(self,"TestJythonConsolePlugin")
9+
self.output("Python: initalized TestJythonPlugin")
10+
11+
def setupEvents(self):
12+
self.output("Python: setupEvents for android.util.Log.i,d,v,e,w")
13+
self.createBreakpointRequest("android.util.Log.i")
14+
self.createBreakpointRequest("android.util.Log.d")
15+
self.createBreakpointRequest("android.util.Log.v")
16+
self.createBreakpointRequest("android.util.Log.e")
17+
self.createBreakpointRequest("android.util.Log.w")
18+

AndroidSSLBypass/plugins/filters

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
com.android.internal.telephony.gsm.SmsMessage
1+
android.util.Log

AndroidSSLBypass/plugins/plugins.jar

-352 Bytes
Binary file not shown.

AndroidSSLBypass/src/com/isecpartners/android/jdwp/CommandLine.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.isecpartners.android.jdwp.pluginservice.JDIPluginServiceFactory;
3535
import com.isecpartners.android.jdwp.pluginservice.JythonPluginService;
3636
import com.isecpartners.android.jdwp.pluginservice.JythonPluginServiceFactory;
37+
import com.isecpartners.android.jdwp.pluginservice.PluginNotFoundException;
3738
import com.sun.jdi.request.EventRequest;
3839

3940
public class CommandLine extends QueueAgent {
@@ -448,9 +449,16 @@ public String loadPlugins(
448449
} catch (IOException e1) {
449450
LOGGER.error("could not load plugins due to IO exception: " + e1);
450451
sb.append("ERROR: could not load plugins due to IO exception");
452+
} catch (PluginNotFoundException e) {
453+
LOGGER.error("plugin not found");
454+
sb.append("ERROR: could not load plugins due to PluginNotFoundException: " + e.getMessage());
451455
}
452456
return sb.toString();
453457
}
458+
459+
public String unloadPlugins(String pluginDirToUnload){
460+
return "not implemented";
461+
}
454462

455463
/**
456464
* Initialize a specific plugin from those available (see list-plugins).
@@ -468,10 +476,12 @@ public String initializePlugin(
468476
this.jythonPluginService.initPlugin(this.ctrl.getVMEM(),
469477
pluginName);
470478
LOGGER.info("attempted to init plugin: " + pluginName);
471-
sb.append("plugin initialized: " + pluginName);
479+
sb.append("attempted to init plugin: " + pluginName);
472480
} catch (NoVMSessionException e) {
473481
LOGGER.error("No virtual machine session");
474482
sb.append("ERROR: no virtual machine session");
483+
} catch (PluginNotFoundException e) {
484+
sb.append("plugin not found: " + e.getMessage());
475485
}
476486
return sb.toString();
477487
}
@@ -498,13 +508,13 @@ public String listPlugins() {
498508
@Command(name = "list-vm-events", abbrev = "events", description= "List all the currently set VM events (breakpoints, etc.)")
499509
public String listVMEvents(){
500510
StringBuilder sb = new StringBuilder();
501-
sb.append("Currently set VirtualMachine events: \n");
511+
sb.append("Currently set VirtualMachine events: \n\n");
502512
if(this.ctrl.isConnected()){
503513
try {
504514
VirtualMachineEventManager vmem = this.ctrl.getVMEM();
505515
for(EventRequest er : vmem.getVmEvents().keySet()){
506516
JDIPlugin handler = vmem.getVmEvents().get(er);
507-
sb.append(INDENT + er + " handler: " + handler.getClass().getName());
517+
sb.append(INDENT + "event request: " + er + ", handler: " + handler.getClass().getName() + "\n\n");
508518
}
509519
} catch (NoVMSessionException e) {
510520
// TODO Auto-generated catch block

AndroidSSLBypass/src/com/isecpartners/android/jdwp/DalvikUtils.java

+35-7
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,16 @@
4141
public class DalvikUtils extends Thread{
4242
private final static org.apache.log4j.Logger LOGGER = Logger
4343
.getLogger(DalvikUtils.class.getName());
44-
private static final String NEW_INSTANCE_METHOD_NAME = "newInstance";
45-
private static final String LOAD_CLASS_METHOD_NAME = "loadClass";
4644
public static ArrayList<Value> NOARGS = new ArrayList<Value>();
4745
private ThreadReference currentThread = null;
4846
private EventRequestManager eventRequestManager = null;
49-
private String name = null;
5047
private VirtualMachine vm = null;
51-
private DalvikUtils vmUtils;
5248
private ClassLoaderUtils classLoaderUtils;
49+
private String name = null;
5350

5451
public DalvikUtils(VirtualMachine vm, int threadIndex) {
5552
this.vm = vm;
56-
this.name = this.vm.name();
53+
this.name = this.vm.name();
5754

5855
// TODO dont know if this should be defaulted or exception thrown
5956
if ((threadIndex < 0) || (threadIndex >= this.vm.allThreads().size())) {
@@ -272,8 +269,20 @@ public List<LocalVariable> getLocals(ThreadReference tr, int idx)
272269
}
273270
return null;
274271
}
272+
273+
public Value getLocalVariableValue(ThreadReference tr, int frameIdx,
274+
String localName) throws AbsentInformationException,
275+
IncompatibleThreadStateException {
276+
StackFrame fr = tr.frame(frameIdx);
277+
Value ret = null;
278+
LocalVariable var = fr.visibleVariableByName(localName);
279+
if (var != null) {
280+
ret = fr.getValue(var);
281+
}
282+
return ret;
283+
}
275284

276-
public Value getLocalVariableValue(ThreadReference tr, StackFrame fr,
285+
public Value getLocalVariableValue(StackFrame fr,
277286
String localName) throws AbsentInformationException,
278287
IncompatibleThreadStateException {
279288
Value ret = null;
@@ -283,9 +292,28 @@ public Value getLocalVariableValue(ThreadReference tr, StackFrame fr,
283292
}
284293
return ret;
285294
}
295+
296+
public StringReference getLocalVariableValueAsString(StackFrame fr,
297+
String localName) throws AbsentInformationException,
298+
IncompatibleThreadStateException {
299+
Value val = null;
300+
StringReference ret = null;
301+
LocalVariable var = fr.visibleVariableByName(localName);
302+
if (var != null) {
303+
val = fr.getValue(var);
304+
if( val instanceof StringReference){
305+
ret = (StringReference) fr.getValue(var);
306+
} else {
307+
LOGGER.warn("getLocalVariableValueAsString called with non-String Object: " + var.getClass().getName());
308+
}
309+
} else {
310+
LOGGER.warn("LocalVariable with name: " + localName + " was not found");
311+
}
312+
return ret;
313+
}
286314

287315
/*
288-
* THis function appears to take an exorbitant amount of time why why why
316+
* This function appears to take an exorbitant amount of time why why why
289317
*/
290318
public boolean setLocalVariableValue(int i, String name, Value sf)
291319
throws IncompatibleThreadStateException, InvalidTypeException,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.isecpartners.android.jdwp.plugin;
1+
package com.isecpartners.android.jdwp.plugin;
22

33
import java.io.FileNotFoundException;
44
import java.io.IOException;
@@ -10,9 +10,10 @@
1010

1111
import com.isecpartners.android.jdwp.LocationNotFoundException;
1212
import com.isecpartners.android.jdwp.pluginservice.AbstractJDIPlugin;
13+
import com.isecpartners.android.jdwp.pluginservice.AbstractJythonConsolePlugin;
1314
import com.sun.jdi.event.Event;
1415

15-
public class JythonConsoleJDIPlugin extends AbstractJDIPlugin {
16+
public class JythonConsoleJDIPlugin extends AbstractJythonConsolePlugin {
1617
private static final String BREAKPOINT_LOCATION = "breakpoint.location";
1718

1819
private final static org.apache.log4j.Logger LOGGER = Logger
@@ -25,33 +26,6 @@ public JythonConsoleJDIPlugin() throws FileNotFoundException,
2526
super(JythonConsoleJDIPlugin.class.getName());
2627
}
2728

28-
public void consoleQuit(Event event) {
29-
JythonConsoleJDIPlugin.LOGGER.info("console quit called!");
30-
this.resumeEventSet();
31-
}
32-
33-
@Override
34-
public void handleEvent(Event event) {
35-
JythonConsoleJDIPlugin.LOGGER.info("handling event: " + event);
36-
PySystemState.initialize();
37-
PythonInterpreter pyi = new PythonInterpreter();
38-
pyi.exec("import sys");
39-
pyi.exec("import os");
40-
// you can pass the python.path to java to avoid hardcoding this
41-
// java -Dpython.path=/path/to/jythonconsole-0.0.6 EmbedExample
42-
pyi.exec("con_path = os.path.abspath(r'jythonconsole/jythonconsole-0.0.7/')");
43-
pyi.exec("sys.path.append(con_path)");
44-
pyi.exec("from console import main");
45-
PyObject main = pyi.get("main");
46-
47-
// stuff some objects into the namespace
48-
49-
// TODO make an event wrapper object for easier console use?
50-
pyi.set("event", event);
51-
pyi.set("plugin", this);
52-
main.__call__(pyi.getLocals());
53-
}
54-
5529
@Override
5630
public void setupEvents() {
5731
this.breakpointLocation = this.properties
@@ -60,10 +34,12 @@ public void setupEvents() {
6034
try {
6135

6236
this.createBreakpointRequest(this.breakpointLocation);
37+
LOGGER.info("success setting up events!");
6338
} catch (LocationNotFoundException e) {
6439
JythonConsoleJDIPlugin.LOGGER
6540
.error("could not set breakpoint on location: "
6641
+ this.breakpointLocation);
6742
}
6843
}
44+
6945
}

AndroidSSLBypass/src/com/isecpartners/android/jdwp/plugin/TraceMethodsJDIPlugin.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.FileReader;
1010
import java.io.IOException;
1111
import java.util.ArrayList;
12+
import java.util.List;
1213
import java.util.Map;
1314

1415
import org.apache.log4j.Logger;
@@ -45,34 +46,42 @@ public TraceMethodsJDIPlugin() throws FileNotFoundException, IOException {
4546

4647
@Override
4748
public void handleEvent(Event event) {
49+
StringBuilder out = new StringBuilder("");
4850
if (event instanceof MethodEntryEvent) {
4951
MethodEntryEvent meEvent = (MethodEntryEvent) event;
5052
ThreadReference tr = meEvent.thread();
5153
StackFrame fr;
52-
StringBuilder out = new StringBuilder("");
54+
5355
try {
54-
fr = tr.frames().get(0);
56+
fr = tr.frame(0);
5557
Location loc = fr.location();
5658
Method method = loc.method();
57-
out.append("\n =============== \n" + method.toString() + "\n=============== \n");
59+
out.append("\n===============\n" + method.toString()
60+
+ "\n===============\n");
5861
out.append("local variables:\n");
59-
Map<LocalVariable, Value> vars = fr.getValues(fr.visibleVariables());
60-
for(LocalVariable key : vars.keySet()){
61-
out.append("\t" + key + " : " + vars.get(key) + "\n");
62+
List<LocalVariable> visVars = fr.visibleVariables();
63+
if (visVars != null && !visVars.isEmpty()) {
64+
Map<LocalVariable, Value> vars = fr.getValues(visVars);
65+
for (LocalVariable key : vars.keySet()) {
66+
out.append("\t" + key + " : " + vars.get(key) + "\n");
67+
}
6268
}
6369
out.append("\n =============== \n");
64-
LOGGER.info(out.toString());
6570
} catch (IncompatibleThreadStateException e) {
66-
// TODO Auto-generated catch block
67-
e.printStackTrace();
71+
out.append("could not get visible variables due to IncompatibleThreadStateException");
72+
LOGGER.error(e);
6873
} catch (AbsentInformationException e) {
69-
// TODO Auto-generated catch block
70-
e.printStackTrace();
74+
out.append("could not get visible variables due to AbsentInformationException");
75+
//TODO should probably print full stack trace
76+
LOGGER.error(e);
7177
}
7278

7379
} else {
74-
LOGGER.info("received unexpected event type: " + event);
80+
out.append("unexpected event type for handler: " + event);
7581
}
82+
83+
LOGGER.info(out.toString());
84+
this.output(out.toString());
7685
this.resumeEventSet();
7786
}
7887

AndroidSSLBypass/src/com/isecpartners/android/jdwp/pluginservice/AbstractJDIPlugin.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.io.FileInputStream;
55
import java.io.FileNotFoundException;
66
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import java.net.URL;
79
import java.util.ArrayList;
810
import java.util.Properties;
911

@@ -46,7 +48,7 @@ public abstract class AbstractJDIPlugin extends QueueAgent implements JDIPlugin
4648
public AbstractJDIPlugin(String name){
4749
this.name = name;
4850
}
49-
51+
5052
public void output(String message){
5153
LOGGER.info(message);
5254
try {
@@ -111,9 +113,10 @@ public void init(VirtualMachineEventManager vmem, String path)
111113
this.vmem = vmem;
112114
this.basePath = path;
113115
this.propsPath = path + File.separator + this.getPluginName() + ".prop";
114-
this.propsFile = new File(this.propsPath);
115-
if(this.propsFile.isFile()){
116-
this.properties.load(new FileInputStream(this.propsPath));
116+
117+
URL pathURL = ClassLoader.getSystemResource(this.propsPath);
118+
if(pathURL != null) {
119+
this.propsFile = new File(pathURL.getPath());
117120
}
118121
this.setupEvents();
119122
}

0 commit comments

Comments
 (0)