NoRoot Firewall v4.0.2版本的 MD5 值为:65ececf86f2a47bb27bef1872f52b654
以下内容为反编译后的 FragDebugButtons.java 源代码,内容仅作参考
package app.greyshirts.firewall.ui.debug;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import app.greyshirts.firewall.R;
import app.greyshirts.firewall.app.Filter;
import app.greyshirts.firewall.app.PackageNames;
import app.greyshirts.firewall.cache.DnsCache;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
public class FragDebugButtons extends Fragment implements View.OnClickListener {
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
View inflate = layoutInflater.inflate(R.layout.frag_debug_buttons, (ViewGroup) null);
inflate.findViewById(R.id.buttonNormalHttpGet).setOnClickListener(this);
inflate.findViewById(R.id.buttonShutdownByServer).setOnClickListener(this);
inflate.findViewById(R.id.buttonClosedByServer).setOnClickListener(this);
inflate.findViewById(R.id.buttonPortClosed).setOnClickListener(this);
inflate.findViewById(R.id.buttonServerNotExist).setOnClickListener(this);
inflate.findViewById(R.id.buttonDownloadBig).setOnClickListener(this);
inflate.findViewById(R.id.buttonUploadBig).setOnClickListener(this);
inflate.findViewById(R.id.buttonDownloadSmallNotKeepalive).setOnClickListener(this);
inflate.findViewById(R.id.buttonDownloadSmallKeepalive).setOnClickListener(this);
inflate.findViewById(R.id.buttonGoogle).setOnClickListener(this);
inflate.findViewById(R.id.buttonYahoo).setOnClickListener(this);
inflate.findViewById(R.id.buttonUDP).setOnClickListener(this);
inflate.findViewById(R.id.buttonUDPRecv).setOnClickListener(this);
inflate.findViewById(R.id.dnsButton).setOnClickListener(this);
inflate.findViewById(R.id.addFilterRules).setOnClickListener(this);
inflate.findViewById(R.id.queryFilter).setOnClickListener(this);
return inflate;
}
@Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.buttonNormalHttpGet) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to http://192.168.1.216:8000/");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://192.168.1.216:8000/").openConnection();
httpURLConnection.connect();
Log.i("HTTP", "connected");
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
byte[] bArr2 = new byte[read];
System.arraycopy(bArr, 0, bArr2, 0, read);
Log.i("HTTP", "body:" + new String(bArr2));
} else {
httpURLConnection.disconnect();
return;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonShutdownByServer) {
new Thread(new Runnable(this) {
@Override
public void run() {
int read;
try {
Log.i("SOCK", "connecting to 192.168.1.216");
Socket socket = new Socket();
socket.connect(new InetSocketAddress("192.168.1.216", 8001));
InputStream inputStream = socket.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
read = inputStream.read(bArr);
if (read == -1) {
break;
}
Log.i("SOCK", String.format("received %d bytes", Integer.valueOf(read)));
}
Log.i("SOCK", String.format("received %d bytes", Integer.valueOf(read)));
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
socket.getOutputStream().write("hello back to you".getBytes());
try {
Thread.sleep(5000L);
} catch (InterruptedException e2) {
Log.i("SOCK", "caught exception. " + e2);
}
inputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
Log.i("SOCK", "err " + e3.toString());
}
}
}).start();
} else if (id == R.id.buttonClosedByServer) {
new Thread(new Runnable(this) {
@Override
public void run() {
int read;
InputStream inputStream = null;
try {
try {
Log.i("SOCK", "connecting to 192.168.1.216");
Socket socket = new Socket();
socket.connect(new InetSocketAddress("192.168.1.216", 8002));
inputStream = socket.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
read = inputStream.read(bArr);
if (read == -1) {
break;
}
Log.i("SOCK", String.format("received %d bytes", Integer.valueOf(read)));
}
Log.i("SOCK", String.format("received %d bytes", Integer.valueOf(read)));
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
OutputStream outputStream = socket.getOutputStream();
Log.i("SOCK", "write data1");
outputStream.write("hello back to you".getBytes());
try {
Thread.sleep(5000L);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
Log.i("SOCK", "write data2");
outputStream.write("hello back to you2".getBytes());
try {
Thread.sleep(5000L);
} catch (InterruptedException e3) {
e3.printStackTrace();
}
Log.i("SOCK", "write data3");
outputStream.write("hello back to you3".getBytes());
Log.i("SOCK", "XXX cannot reach here");
if (inputStream == null) {
return;
}
} catch (IOException e4) {
e4.printStackTrace();
Log.i("SOCK", "err " + e4.toString());
if (inputStream == null) {
return;
}
}
try {
inputStream.close();
} catch (Exception unused) {
}
} catch (Throwable th) {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception unused2) {
}
}
throw th;
}
}
}).start();
} else if (id == R.id.buttonPortClosed) {
new Thread(new Runnable(this) {
@Override
public void run() {
int read;
InputStream inputStream = null;
try {
try {
Log.i("SOCK", "connecting to 192.168.1.216");
Socket socket = new Socket();
socket.connect(new InetSocketAddress("192.168.1.216", 7999));
inputStream = socket.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
read = inputStream.read(bArr);
if (read == -1) {
break;
}
Log.i("SOCK", String.format("received %d bytes????", Integer.valueOf(read)));
}
Log.i("SOCK", String.format("received %d bytes???", Integer.valueOf(read)));
if (inputStream == null) {
return;
}
} catch (IOException e) {
e.printStackTrace();
Log.i("SOCK", "err " + e.toString());
if (inputStream == null) {
return;
}
}
try {
inputStream.close();
} catch (IOException unused) {
}
} catch (Throwable th) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused2) {
}
}
throw th;
}
}
}).start();
} else if (id == R.id.buttonServerNotExist) {
new Thread(new Runnable(this) {
@Override
public void run() {
int read;
InputStream inputStream = null;
try {
try {
Log.i("SOCK", "connecting to 192.168.1.200");
Socket socket = new Socket();
socket.connect(new InetSocketAddress("192.168.1.200", 8000));
inputStream = socket.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
read = inputStream.read(bArr);
if (read == -1) {
break;
}
Log.i("SOCK", String.format("received %d bytes????", Integer.valueOf(read)));
}
Log.i("SOCK", String.format("received %d bytes???", Integer.valueOf(read)));
if (inputStream == null) {
return;
}
} catch (IOException e) {
e.printStackTrace();
Log.i("SOCK", "err " + e.toString());
if (inputStream == null) {
return;
}
}
try {
inputStream.close();
} catch (IOException unused) {
}
} catch (Throwable th) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused2) {
}
}
throw th;
}
}
}).start();
} else if (id == R.id.buttonDownloadBig) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to http://192.168.1.216:8000/");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://192.168.1.216:8000/downloadBig").openConnection();
httpURLConnection.connect();
Log.i("HTTP", "connected");
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[1048576];
long currentTimeMillis = System.currentTimeMillis();
int i = 0;
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
i += read;
}
long currentTimeMillis2 = System.currentTimeMillis();
httpURLConnection.disconnect();
if (i != 41943040) {
Log.i("HTTP", String.format("error!!! download size =%d. but expected %d", Integer.valueOf(i), 41943040));
} else {
Log.i("HTTP", "download size OK");
}
Log.i("HTTP", "data check OK");
Log.i("HTTP", String.format("thruput %fMbps", Double.valueOf((((3.3554432E8d / (currentTimeMillis2 - currentTimeMillis)) * 1000.0d) / 1024.0d) / 1024.0d)));
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonUploadBig) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to http://192.168.1.216:8000/");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://192.168.1.216:8000/uploadBig").openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setFixedLengthStreamingMode(41943040);
Log.i("HTTP", "connected");
OutputStream outputStream = httpURLConnection.getOutputStream();
long currentTimeMillis = System.currentTimeMillis();
byte[] bArr = new byte[1048576];
for (int i = 0; i < 41943040; i += bArr.length) {
outputStream.write(bArr);
}
long currentTimeMillis2 = System.currentTimeMillis();
httpURLConnection.disconnect();
Log.i("HTTP", "data send complete");
Log.i("HTTP", String.format("thruput %fMbps", Double.valueOf((((3.3554432E8d / (currentTimeMillis2 - currentTimeMillis)) * 1000.0d) / 1024.0d) / 1024.0d)));
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonDownloadSmallNotKeepalive) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to http://192.168.1.216:8000/");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://192.168.1.216:8000/downloadSmall").openConnection();
httpURLConnection.addRequestProperty("Connection", "close");
httpURLConnection.connect();
Log.i("HTTP", "connected");
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[1048576];
int i = 0;
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
i += read;
}
httpURLConnection.disconnect();
if (i != 5242880) {
Log.i("HTTP", String.format("error!!! download size =%d. but expected %d", Integer.valueOf(i), 5242880));
} else {
Log.i("HTTP", "download size OK");
}
Log.i("HTTP", "data check OK");
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonDownloadSmallKeepalive) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to http://192.168.1.216:8000/");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://192.168.1.216:8000/downloadSmall").openConnection();
httpURLConnection.connect();
Log.i("HTTP", "connected");
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[1048576];
int i = 0;
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
i += read;
}
httpURLConnection.disconnect();
if (i != 5242880) {
Log.i("HTTP", String.format("error!!! download size =%d. but expected %d", Integer.valueOf(i), 5242880));
} else {
Log.i("HTTP", "download size OK");
}
Log.i("HTTP", "data check OK");
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonGoogle) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to www.google.co.jp");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://173.194.38.88").openConnection();
httpURLConnection.connect();
Log.i("HTTP", "connected");
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
byte[] bArr2 = new byte[read];
System.arraycopy(bArr, 0, bArr2, 0, read);
Log.i("HTTP", "body:" + new String(bArr2));
} else {
httpURLConnection.disconnect();
return;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonYahoo) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
Log.i("HTTP", "connecting to yahoo");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://www.yahoo.co.jp").openConnection();
httpURLConnection.connect();
Log.i("HTTP", "connected");
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bArr = new byte[8192];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
byte[] bArr2 = new byte[read];
System.arraycopy(bArr, 0, bArr2, 0, read);
Log.i("HTTP", "body:" + new String(bArr2));
} else {
httpURLConnection.disconnect();
return;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.i("HTTP", "err " + e.toString());
} catch (IOException e2) {
e2.printStackTrace();
Log.i("HTTP", "err " + e2.toString());
}
}
}).start();
} else if (id == R.id.buttonUDP) {
new Thread(new Runnable(this) {
@Override
public void run() {
DatagramSocket datagramSocket;
IOException e;
try {
Log.i("SOCK", "connecting to 192.168.1.216");
datagramSocket = new DatagramSocket();
try {
try {
datagramSocket.connect(new InetSocketAddress("192.168.1.216", 53));
datagramSocket.send(new DatagramPacket("hello".getBytes(), 5));
} catch (IOException e2) {
e = e2;
e.printStackTrace();
Log.i("SOCK", "err " + e.toString());
if (datagramSocket == null) {
return;
}
datagramSocket.close();
}
} catch (Throwable th) {
th = th;
if (datagramSocket != null) {
datagramSocket.close();
}
throw th;
}
} catch (IOException e3) {
datagramSocket = null;
e = e3;
} catch (Throwable th2) {
th = th2;
datagramSocket = null;
if (datagramSocket != null) {
}
throw th;
}
datagramSocket.close();
}
}).start();
} else if (id == R.id.buttonUDPRecv) {
new Thread(new Runnable(this) {
@Override
public void run() {
try {
new InetSocketAddress(InetAddress.getByAddress(new byte[]{-64, -88, 1, 1}), 80);
DatagramChannel open = DatagramChannel.open();
open.socket().bind(null);
open.configureBlocking(false);
InetSocketAddress inetSocketAddress = (InetSocketAddress) open.receive(ByteBuffer.allocateDirect(1500));
open.close();
} catch (Exception e) {
Log.i("TEST", "UDP Recv failed " + e);
}
}
}).start();
} else if (id == R.id.buttonNotification) {
} else {
if (id == R.id.dnsButton) {
new DnsTask().execute(((EditText) getView().findViewById(R.id.dnsText)).getText().toString());
} else if (id == R.id.addFilterRules) {
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 500; i++) {
Filter.getInstance(FragDebugButtons.this.getActivity()).addCustomFilter(1, 1, "8.8.8.8", 0, 80, "Browser", PackageNames.newInstanceFromCommaList("com.google.android.browser"), 0);
}
}
}).start();
} else if (id == R.id.queryFilter) {
long currentTimeMillis = System.currentTimeMillis();
Filter.getInstance(getActivity()).getRuleForConnection(Filter.Profile.PROFILE_WIFI, new byte[]{8, 8, 8, 8}, 80, PackageNames.newInstanceFromCommaList("com.google.android.browser"));
long currentTimeMillis2 = System.currentTimeMillis();
DnsCache.getInstance().startResolver("8.8.8.8", new DnsCache.ResolveNameResult(this) {
@Override
public void onFinish(String str, String str2) {
}
});
FragmentActivity activity = getActivity();
Toast.makeText(activity, "" + (currentTimeMillis2 - currentTimeMillis) + "ms", 1).show();
}
}
}
private class DnsTask extends AsyncTask<String, Void, String> {
private DnsTask() {
}
@Override
public String doInBackground(String... strArr) {
String[] strArr2 = new String[1];
int i = DnsCache.getnameinfo(strArr[0], strArr2);
if (i == 0) {
return strArr2[0];
}
return "err=" + i;
}
@Override
public void onPostExecute(String str) {
Toast.makeText(FragDebugButtons.this.getActivity().getApplicationContext(), str, 0).show();
}
}
static {
System.loadLibrary("core");
}
}