百度手机卫士 v8.1.5版本的 MD5 值为:15af71eae74e2f2b5b9f845fe77a4804
以下内容为反编译后的 ProxyUtils.java 源代码,内容仅作参考
package com.quickbird.mini.utils;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.quickbird.mini.vpn.proxy.HttpProxyRules;
import com.quickbird.mini.vpn.vpn.VpnServiceManager;
import com.quickbird.sdk.QuickBird;
import com.quickbird.sdk.internal.SdkConstant;
import com.quickbird.sdk.utils.QBNetworkUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONException;
public class ProxyUtils {
private static final long QB_GRAY_PKG_EXPIRED_TIME = 86400000;
private static volatile List sHttpVerbs;
private static volatile InetSocketAddress sSafeVpnProxyAdr;
private static final String QB_PROXY_CHARSET_NAME = "latin1";
private static final CharsetDecoder QB_CHARSET_DECODER = Charset.forName(QB_PROXY_CHARSET_NAME).newDecoder();
private static final Pattern PATTERN_LOCAL_ADDRESS = Pattern.compile("^172\\.20\\..*");
private static final Pattern PATTERN_REQUEST_HEADER = Pattern.compile("(?:GET|POST|OPTIONS|PUT|HEAD|CONNECT) ([^\\s]+) HTTP/1\\.\\d\\r\\n.*?Host: ([^\\s]+)\\r\\n", 32);
private static final Pattern PATTERN_REQUEST_MODE = Pattern.compile("(?:GET|POST|OPTIONS|PUT|HEAD|CONNECT) ");
private static final Pattern PATTERN_RESPOND_HEADER = Pattern.compile("HTTP/1\\.\\d");
private static final Pattern PATTERN_QB_GRAY_RESPOND_HEADER = Pattern.compile("X-QB-GRAY: ([^\\s]+)");
private static final int HTTP_PROXY_PORT = 80;
private static final InetSocketAddress BLOCK_ADDRESS = new InetSocketAddress("127.0.0.1", HTTP_PROXY_PORT);
private static final byte[] SAFE_VPN_ENCRYPT_FLAG = {-1, 59};
public static String getProxyCharsetName() {
return QB_PROXY_CHARSET_NAME;
}
public static CoderResult decode(ByteBuffer byteBuffer, CharBuffer charBuffer, boolean z) {
return QB_CHARSET_DECODER.decode(byteBuffer, charBuffer, z);
}
public static boolean isLocalHostAddress(String str) {
return PATTERN_LOCAL_ADDRESS.matcher(str).find();
}
public static boolean isHttpProxyPort(int i) {
return HTTP_PROXY_PORT == i;
}
public static Matcher getRequestHeaderMatcher(CharSequence charSequence) {
return PATTERN_REQUEST_HEADER.matcher(charSequence);
}
public static Matcher getRequestModeMatcher(CharSequence charSequence) {
return PATTERN_REQUEST_MODE.matcher(charSequence);
}
public static boolean isHttpRespondHeader(CharSequence charSequence) {
return PATTERN_RESPOND_HEADER.matcher(charSequence).find();
}
public static byte[] getHttpProxyPrefix() {
try {
return "http://".getBytes(getProxyCharsetName());
} catch (UnsupportedEncodingException e) {
return new byte[]{48};
}
}
public static InetSocketAddress getBlockAddress() {
return BLOCK_ADDRESS;
}
public static boolean isSafeVpnProxy(Context context) {
return VpnServiceManager.getInstance(context).isSafeVpnOpened() && QBNetworkUtils.isWifiNetworkType(context);
}
public static byte[] getSafeVpnEncryptFlag() {
return SAFE_VPN_ENCRYPT_FLAG;
}
public static InetSocketAddress getSafeVpnProxyAddress() {
if (sSafeVpnProxyAdr == null) {
synchronized (ProxyUtils.class) {
if (sSafeVpnProxyAdr == null) {
sSafeVpnProxyAdr = new InetSocketAddress(SdkConstant.SAFE_VPN_PROXY_URL, SdkConstant.SAFE_VPN_PROXY_PORT);
}
}
}
return sSafeVpnProxyAdr;
}
public static short getShort(byte[] bArr, int i) {
return (short) ((bArr[i + 1] << 8) | (bArr[i + 0] & 255));
}
public static List getHttpVerbs() {
if (sHttpVerbs == null) {
synchronized (ProxyUtils.class) {
if (sHttpVerbs == null) {
sHttpVerbs = new ArrayList();
try {
sHttpVerbs.add(ByteBuffer.wrap("GET ".getBytes(getProxyCharsetName())));
sHttpVerbs.add(ByteBuffer.wrap("POST".getBytes(getProxyCharsetName())));
sHttpVerbs.add(ByteBuffer.wrap("HEAD".getBytes(getProxyCharsetName())));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
return sHttpVerbs;
}
public static void matcherQbGrayRespondHeader(Context context, CharSequence charSequence) {
if (!TextUtils.isEmpty(charSequence)) {
Matcher matcher = PATTERN_QB_GRAY_RESPOND_HEADER.matcher(charSequence);
if (matcher.find()) {
String trim = matcher.group(1).trim();
if (QuickBird.SDK_DEBUG) {
Log.i(QuickBird.SDK_TAG, "Matcher gray pkg :" + trim);
}
if (!TextUtils.isEmpty(trim)) {
HttpProxyRules httpProxyRules = HttpProxyRules.getInstance(context);
long currentTimeMillis = 86400000 + System.currentTimeMillis();
ArrayList arrayList = new ArrayList();
arrayList.add(trim);
try {
httpProxyRules.addRules(2, arrayList, 1, currentTimeMillis);
} catch (IOException e) {
} catch (JSONException e2) {
}
}
}
}
}
}