Android Open Source - android-ssl-bypass Class Wrapper






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;
/*w  ww . ja  va 2  s  . c  o  m*/
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.ClassObjectReference;
import com.sun.jdi.ClassType;
import com.sun.jdi.Field;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.InvocationException;
import com.sun.jdi.Method;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.Value;

public class ClassWrapper {
  private final static Logger LOGGER = Logger
      .getLogger(ClassWrapper.class.getName());
  private ClassObjectReference cor;
  private ReferenceType reflectedType;
  private ReferenceType referenceType;
  private ThreadReference thread;
  private ObjectReference instance;

  public ClassWrapper(ClassObjectReference cor, ThreadReference tr) {
    this.setCor(cor);
    this.setReflectedType(cor.reflectedType());
    this.setReferenceType(cor.referenceType());
    this.thread = tr;
  }

  public ObjectReference getInstance(){
    if(this.instance == null){
      this.instance = this.newInstance();
    }
    return this.instance;
  }
  /**
   * @return the cor
   */
  public ClassObjectReference getCor() {
    return cor;
  }

  /**
   * @param cor
   *            the cor to set
   */
  public void setCor(ClassObjectReference cor) {
    this.cor = cor;
  }

  /**
   * @return the reflectedType
   */
  public ReferenceType getReflectedType() {
    return reflectedType;
  }

  /**
   * @param reflectedType
   *            the reflectedType to set
   */
  public void setReflectedType(ReferenceType reflectedType) {
    this.reflectedType = reflectedType;
  }

  /**
   * @return the referenceType
   */
  public ReferenceType getReferenceType() {
    return referenceType;
  }

  /**
   * @param referenceType
   *            the referenceType to set
   */
  public void setReferenceType(ReferenceType referenceType) {
    this.referenceType = referenceType;
  }

  /*
   * Create a new instance of a class using the debugger
   */
  public ObjectReference newInstance() {
    try {
      Method newInst = this.referenceType.methodsByName("newInstance")
          .get(0);
      // ClassType classType = (ClassType)this.referenceType;
      // LOGGER.info("got classtype: " + classType.name());
      ClassType classType = (ClassType) this.reflectedType;
      ClassWrapper.LOGGER.info("got classtype: " + classType.name());
      return (ObjectReference) this.cor.invokeMethod(this.thread,
          newInst, Constants.NOARGS, 1);
    } catch (java.lang.IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvalidTypeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotLoadedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IncompatibleThreadStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InvocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }

  public Value invokeMethodOnInstance(String methodName,List<? extends Value> args ) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException{
    ReferenceType type = this.referenceType;
    List<Method> meths = type.methodsByName(methodName);
    Method method = null;
    this.getInstance();
    if (meths.isEmpty()) {
      LOGGER.info("no methods found");
      type = this.reflectedType;
      meths = type.methodsByName(methodName);
    } else if (meths.size() == 1) {
      method = meths.get(0);
    } else {
      for (Method m : meths) {
        List<String> argNamesToMatch = this.getArgumentTypeNames(args);
        List<String> argNames = m.argumentTypeNames();
        if ((argNamesToMatch == null && argNames == null)
            || (argNamesToMatch.equals(argNames))) {
          method = m;
          break;
        }
      }
    }
    if (method == null) {
      LOGGER.warn("no matching methods found for " + methodName);
      return null;
    }
    return this.instance.invokeMethod(this.thread, method, args, 1);
  }
  public Value invokeMethodOnType(ReferenceType type, String methodName,
      List<? extends Value> args) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    List<Method> meths = type.methodsByName(methodName);
    Method method = null;
    if (meths.isEmpty()) {
      LOGGER.info("no methods found");
      return null;
    } else if (meths.size() == 1) {
      method = meths.get(0);
    } else {
      for (Method m : meths) {
        List<String> argNamesToMatch = this.getArgumentTypeNames(args);
        List<String> argNames = m.argumentTypeNames();
        if ((argNamesToMatch == null && argNames == null)
            || (argNamesToMatch.equals(argNames))) {
          method = m;
          break;
        }
      }
    }
    if (method == null) {
      LOGGER.warn("no matching methods found for " + methodName);
      return null;
    }
    return ((ClassType) type).invokeMethod(this.thread, method, args, 2);
  }

  private List<String> getArgumentTypeNames(List<? extends Value> args) {
    List<String> argNames = new ArrayList<String>();
    for (Value arg : args) {
      argNames.add(arg.type().name());
    }
    return argNames;
  }

  public Field getField(String fieldName) {
    Field field = this.cor.reflectedType().fieldByName(fieldName);
    if (field == null) {
      field = this.cor.referenceType().fieldByName(fieldName);
    }
    return field;
  }

  public Value getFieldValue(Field allowAll) {
    Value val = this.cor.reflectedType().getValue(allowAll);
    if (val == null) {
      val = this.cor.referenceType().getValue(allowAll);
    }
    return val;
  }

}




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