コード例 #1
0
 @Override
 protected void onConnected(ByteBuffer buffer) throws Exception {
   m_Encryptor = EncryptorFactory.createEncryptorByConfig(m_Config);
   // 构造socks5请求(跳过前3个字节)
   buffer.clear();
   buffer.put((byte) 0x03); // domain
   byte[] domainBytes = m_DestAddress.getHostName().getBytes();
   buffer.put((byte) domainBytes.length); // domain length;
   buffer.put(domainBytes);
   buffer.putShort((short) m_DestAddress.getPort());
   // buffer.put("I will be damned".getBytes());
   buffer.flip();
   m_Encryptor.encrypt(buffer);
   if (write(buffer, false)) {
     m_TunnelEstablished = true;
     onTunnelEstablished();
   } else {
     m_TunnelEstablished = true;
     this.beginReceive();
   }
 }
コード例 #2
0
  public static ShadowsocksConfig parse(String proxyInfo) throws Exception {
    ShadowsocksConfig config = new ShadowsocksConfig();
    Uri uri = Uri.parse(proxyInfo);
    if (uri.getPort() == -1) {
      String base64String = uri.getHost();
      proxyInfo =
          "ss://" + new String(Base64.decode(base64String.getBytes("ASCII"), Base64.DEFAULT));
      uri = Uri.parse(proxyInfo);
    }

    String userInfoString = uri.getUserInfo();
    if (userInfoString != null) {
      String[] userStrings = userInfoString.split(":");
      config.EncryptMethod = userStrings[0];
      if (userStrings.length >= 2) {
        config.Password = userStrings[1];
      }
    }
    config.ServerAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
    config.Encryptor = EncryptorFactory.createEncryptorByConfig(config);
    return config;
  }