Android Open Source - android-ssl-bypass Virtual Machine Event Manager






From Project

Back to project page android-ssl-bypass.

License

The source code is released under:

Copyright (c) 2012, iSEC Partners. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the ...

If you think the Android project android-ssl-bypass listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.isecpartners.android.jdwp;
/*from   w ww.  jav a  2s .  c o  m*/
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.isecpartners.android.jdwp.common.Message;
import com.isecpartners.android.jdwp.common.QueueAgent;
import com.isecpartners.android.jdwp.pluginservice.JDIPlugin;
import com.sun.jdi.Location;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.Type;
import com.sun.jdi.VirtualMachine;
import com.sun.jdi.event.Event;
import com.sun.jdi.event.EventIterator;
import com.sun.jdi.event.EventQueue;
import com.sun.jdi.event.EventSet;
import com.sun.jdi.request.BreakpointRequest;
import com.sun.jdi.request.ClassPrepareRequest;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.MethodEntryRequest;
import com.sun.jdi.request.MethodExitRequest;
import com.sun.jdi.request.StepRequest;

public class VirtualMachineEventManager extends QueueAgent {
  private final static org.apache.log4j.Logger LOGGER = Logger
      .getLogger(VirtualMachineEventManager.class.getName());
  private EventSet currentEventSet;

  private VirtualMachine vm;
  private HashMap<EventRequest, JDIPlugin> vmEvents;
  
  
  private DalvikUtils vmUtils;

  public VirtualMachineEventManager(VirtualMachine vm) {
    this.vm = vm;
    this.vmUtils = new DalvikUtils(vm,0);
    this.vmEvents = new HashMap<EventRequest, JDIPlugin>();
  }
  
  public HashMap<EventRequest, JDIPlugin> getVmEvents() {
    return vmEvents;
  }

  public void setVmEvents(HashMap<EventRequest, JDIPlugin> vmEvents) {
    this.vmEvents = vmEvents;
  }


  // TODO test what happens when two things try to create the same bp
  public BreakpointRequest createBreakpointRequest(String locationString,
      JDIPlugin vmeh) throws LocationNotFoundException {
    Location loc = this.vmUtils.resolveLocation(locationString);
    if (loc == null) {
      throw new LocationNotFoundException(locationString);
    }
    BreakpointRequest bpEvent = this.vmUtils.createBreakpointRequest(loc);
    this.vmEvents.put(bpEvent, vmeh);
    VirtualMachineEventManager.LOGGER.info("BreakpointRequest created: "
        + bpEvent);
    return bpEvent;
  }

  public ClassPrepareRequest createClassPrepareRequest(String classFilter,
      JDIPlugin vmeh) throws LocationNotFoundException,
      ReferenceTypeNotFoundException {
    Type classtype = this.vmUtils.findClassType(classFilter);
    if (classtype == null) {
      throw new ReferenceTypeNotFoundException(classFilter);
    }
    ClassPrepareRequest cpr = this.vmUtils
        .createClassPrepareRequest(classFilter);
    this.vmEvents.put(cpr, vmeh);
    VirtualMachineEventManager.LOGGER.info("ClassPrepareRequest created: "
        + cpr);
    return cpr;
  }

  public MethodEntryRequest createMethodEntryRequest(String classFilter,
      JDIPlugin vmeh) throws LocationNotFoundException,
      ReferenceTypeNotFoundException {
    Type classtype = this.vmUtils.findClassType(classFilter);
    if (classtype == null) {
      throw new ReferenceTypeNotFoundException(classFilter);
    }
    MethodEntryRequest mer = this.vmUtils
        .createMethodEntryRequest(classFilter);
    this.vmEvents.put(mer, vmeh);
    VirtualMachineEventManager.LOGGER.info("MethodEntryRequest created: "
        + mer);
    return mer;

  }

  public MethodExitRequest createMethodExitRequest(String classFilter,
      JDIPlugin vmeh) throws LocationNotFoundException,
      ReferenceTypeNotFoundException {
    Type classtype = this.vmUtils.findClassType(classFilter);
    if (classtype == null) {
      throw new ReferenceTypeNotFoundException(classFilter);
    }
    MethodExitRequest mer = this.vmUtils
        .createMethodExitRequest(classFilter);
    this.vmEvents.put(mer, vmeh);
    VirtualMachineEventManager.LOGGER.info("MethodExitRequest created: "
        + mer);
    return mer;
  }

  public StepRequest createStepRequest(ThreadReference tr, int depth,
      int type, JDIPlugin vmeh) throws LocationNotFoundException {
    StepRequest stepEvent = this.vmUtils.createStepRequest(tr, depth, type);
    this.vmEvents.put(stepEvent, vmeh);
    VirtualMachineEventManager.LOGGER.info("StepRequest created: "
        + stepEvent);
    return stepEvent;
  }

  public void deleteEventRequest(EventRequest req) {
    this.vmUtils.deleteEventRequest(req);
  }

  private EventQueue getEventQueue() {
    return this.vm.eventQueue();
  }

  public void resumeEventSet() {
    this.currentEventSet.resume();
  }

  @Override
  public void run() {
    boolean done = false;
    while (!done) {
      EventQueue queue = this.getEventQueue();
      EventSet eventSet;
      try {
        eventSet = queue.remove();
        this.setCurrentEventSet(eventSet);
        EventIterator it = eventSet.eventIterator();

        if (it.hasNext()) {
          Event event = it.nextEvent();
          JDIPlugin handler = this.vmEvents.get(event.request());
          if(event instanceof com.sun.jdi.event.VMDisconnectEvent || event instanceof com.sun.jdi.event.VMDeathEvent){
            done = true;
            this.sendMessage(new Message(Message.Type.DISCONNECTED,event));
            break;
          } else {
            handler.handleEvent(event);
          }
        }
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    }
  }

  private void setCurrentEventSet(EventSet eventSet) {
    this.currentEventSet = eventSet;
  }

  public void setVmUtils(DalvikUtils vmUtils) {
    this.vmUtils = vmUtils;
  }

  public DalvikUtils getDalvikUtils(int index) {
    return new DalvikUtils(this.vm,index);
  }
}




Java Source Code List

com.isec.helperapp.EasySSLSocketFactory.java
com.isec.helperapp.EasyX509TrustManager.java
com.isec.helperapp.MainActivity.java
com.isec.helperapp.TrustAllTrustManager.java
com.isec.ssltest.SSLTestActivity.java
com.isecpartners.android.jdwp.ADBInterface.java
com.isecpartners.android.jdwp.ClassLoaderUtils.java
com.isecpartners.android.jdwp.ClassWrapper.java
com.isecpartners.android.jdwp.CommandLine.java
com.isecpartners.android.jdwp.Constants.java
com.isecpartners.android.jdwp.Control.java
com.isecpartners.android.jdwp.DalvikUtils.java
com.isecpartners.android.jdwp.DexClassLoaderNotFoundException.java
com.isecpartners.android.jdwp.LocationNotFoundException.java
com.isecpartners.android.jdwp.NoLoadClassMethodException.java
com.isecpartners.android.jdwp.NoVMSessionException.java
com.isecpartners.android.jdwp.NotImplementedException.java
com.isecpartners.android.jdwp.ReferenceTypeNotFoundException.java
com.isecpartners.android.jdwp.VirtualMachineEventManager.java
com.isecpartners.android.jdwp.VirtualMachineSession.java
com.isecpartners.android.jdwp.common.Message.java
com.isecpartners.android.jdwp.common.QueueAgentInterface.java
com.isecpartners.android.jdwp.common.QueueAgent.java
com.isecpartners.android.jdwp.connection.AbstractConnection.java
com.isecpartners.android.jdwp.connection.AttachingConnection.java
com.isecpartners.android.jdwp.connection.DVMConnectionProvider.java
com.isecpartners.android.jdwp.connection.DefaultConnectionFactory.java
com.isecpartners.android.jdwp.connection.NoAttachingConnectorException.java
com.isecpartners.android.jdwp.connection.NoListeningConnectorException.java
com.isecpartners.android.jdwp.plugin.JythonConsoleJDIPlugin.java
com.isecpartners.android.jdwp.plugin.SSLBypassJDIPlugin.java
com.isecpartners.android.jdwp.plugin.TestJDIPlugin.java
com.isecpartners.android.jdwp.plugin.TraceMethodsJDIPlugin.java
com.isecpartners.android.jdwp.pluginservice.AbstractJDIPlugin.java
com.isecpartners.android.jdwp.pluginservice.AbstractJythonConsolePlugin.java
com.isecpartners.android.jdwp.pluginservice.AbstractPluginService.java
com.isecpartners.android.jdwp.pluginservice.ClasspathUtils.java
com.isecpartners.android.jdwp.pluginservice.JDIPluginServiceFactory.java
com.isecpartners.android.jdwp.pluginservice.JDIPluginService.java
com.isecpartners.android.jdwp.pluginservice.JDIPlugin.java
com.isecpartners.android.jdwp.pluginservice.JythonPluginServiceFactory.java
com.isecpartners.android.jdwp.pluginservice.JythonPluginService.java
com.isecpartners.android.jdwp.pluginservice.PluginNotFoundException.java
com.isecpartners.android.jdwp.pluginservice.PluginService.java