FreeShare Geek v3.1.8290版本的 MD5 值为:492ca3ae4cdfab7e2d18d5e1b4428e75
以下内容为反编译后的 q.java 源代码,内容仅作参考
package com.stkj.processor.server;
import android.util.Log;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.atomic.AtomicBoolean;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.Record;
import org.xbill.DNS.ai;
import org.xbill.DNS.x;
public class q {
private static final q f2189a = new q();
private String d;
private Thread e;
private Thread f;
private ServerSocket g;
private DatagramSocket h;
private int f2190c = 1053;
private final AtomicBoolean b = new AtomicBoolean(true);
public static final q a() {
return f2189a;
}
private q() {
a("192.168.43.1");
}
public q a(int i) {
Log.e("DB_DC", "Port:" + i);
if (i < 0) {
i = 1053;
}
this.f2190c = i;
Log.e("DB_DC", "Set port:" + i);
return this;
}
public q a(String str) {
if (str == null) {
str = "192.168.43.1";
}
this.d = str;
return this;
}
public void b() {
Log.e("DB_DC", "DNSServer will be start");
this.b.set(true);
this.e = new Thread(new Runnable() {
@Override
public void run() {
q.this.d();
}
});
this.e.start();
this.f = new Thread(new Runnable() {
@Override
public void run() {
q.this.c();
}
});
this.f.start();
Log.e("DB_DC", "DNSServer was started");
}
public void c() {
byte[] a2;
try {
this.h = new DatagramSocket(this.f2190c);
try {
this.h.setReuseAddress(true);
byte[] bArr = new byte[512];
DatagramPacket datagramPacket = new DatagramPacket(bArr, bArr.length);
DatagramPacket datagramPacket2 = null;
while (this.b.get()) {
datagramPacket.setLength(bArr.length);
try {
this.h.receive(datagramPacket);
try {
a2 = a(new x(bArr), bArr, datagramPacket.getLength(), null);
} catch (IOException e) {
a2 = a(bArr);
}
} catch (InterruptedIOException e2) {
}
if (a2 != null) {
if (datagramPacket2 == null) {
datagramPacket2 = new DatagramPacket(a2, a2.length, datagramPacket.getAddress(), datagramPacket.getPort());
} else {
datagramPacket2.setData(a2);
datagramPacket2.setLength(a2.length);
datagramPacket2.setAddress(datagramPacket.getAddress());
datagramPacket2.setPort(datagramPacket.getPort());
}
DatagramPacket datagramPacket3 = datagramPacket2;
this.h.send(datagramPacket3);
datagramPacket2 = datagramPacket3;
}
}
} finally {
this.h.close();
}
} catch (IOException e3) {
}
}
public void d() {
try {
this.g = new ServerSocket(this.f2190c);
try {
this.g.setReuseAddress(true);
while (this.b.get()) {
final Socket accept = this.g.accept();
new Thread(new Runnable() {
@Override
public void run() {
q.this.a(accept);
}
}).start();
}
} finally {
this.g.close();
}
} catch (IOException e) {
}
}
public void a(Socket socket) {
byte[] a2;
try {
try {
socket.setSoTimeout(5000);
DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
byte[] bArr = new byte[dataInputStream.readUnsignedShort()];
dataInputStream.readFully(bArr);
try {
a2 = a(new x(bArr), bArr, bArr.length, socket);
if (a2 == null) {
try {
return;
} catch (IOException e) {
return;
}
}
} catch (IOException e2) {
a2 = a(bArr);
}
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataOutputStream.writeShort(a2.length);
dataOutputStream.write(a2);
try {
socket.close();
} catch (IOException e3) {
}
} finally {
try {
socket.close();
} catch (IOException e4) {
}
}
} catch (IOException e5) {
try {
socket.close();
} catch (IOException e6) {
}
}
}
private byte[] a(x xVar, byte[] bArr, int i, Socket socket) {
int max;
org.xbill.DNS.u a2 = xVar.a();
if (a2.b(0)) {
return null;
}
if (a2.b() != 0) {
return a(xVar, 1);
}
if (a2.c() != 0) {
return a(xVar, 4);
}
Record b = xVar.b();
OPTRecord e = xVar.e();
if (socket != null) {
max = 65535;
} else {
max = e != null ? Math.max(e.getPayloadSize(), 512) : 512;
}
int i2 = (e == null || (e.getFlags() & 32768) == 0) ? 0 : 1;
x xVar2 = new x(xVar.a().a());
xVar2.a().a(0);
if (xVar.a().b(7)) {
xVar2.a().a(7);
}
xVar2.a(b, 0);
Name name = b.getName();
int type = b.getType();
int dClass = b.getDClass();
if (!ai.d(type) && type != 255) {
return a(xVar, 4);
}
byte a3 = a(xVar2, name, type, dClass, 0, i2);
if (a3 != 0 && a3 != 3) {
return a(xVar, a3);
}
return xVar2.c(max);
}
private byte a(x xVar, Name name, int i, int i2, int i3, int i4) {
try {
xVar.a(Record.fromString(name, 1, 1, 0L, this.d, name), 1);
return (byte) 0;
} catch (IOException e) {
return (byte) 1;
}
}
private byte[] a(byte[] bArr) {
try {
return a(new org.xbill.DNS.u(bArr), 1, null);
} catch (IOException e) {
return null;
}
}
private byte[] a(org.xbill.DNS.u uVar, int i, Record record) {
x xVar = new x();
xVar.a(uVar);
for (int i2 = 0; i2 < 4; i2++) {
xVar.a(i2);
}
if (i == 2) {
xVar.a(record, 0);
}
uVar.d(i);
return xVar.g();
}
private byte[] a(x xVar, int i) {
return a(xVar.a(), i, xVar.b());
}
}