正在查看: 万能钥匙 v1.1.23 应用的 TCPSocket.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 万能钥匙 v1.1.23 应用的 TCPSocket.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.finogeeks.lib.applet.api.network.tcp;
import android.util.Base64;
import com.finogeeks.lib.applet.modules.log.FLog;
import hh0.l;
import java.io.InputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.d0;
import kotlin.jvm.internal.g0;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.p;
import kotlin.jvm.internal.y;
import lg0.h;
import lg0.i;
import org.json.JSONObject;
@Metadata(d1 = {"\u0000F\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0010\u0012\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0010\u0015\n\u0002\b\f\u0018\u00002\u00020\u0001:\u000212B\u0017\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004¢\u0006\u0004\b\u0006\u0010\u0007J\r\u0010\t\u001a\u00020\b¢\u0006\u0004\b\t\u0010\nJ\r\u0010\u000b\u001a\u00020\b¢\u0006\u0004\b\u000b\u0010\nJ%\u0010\u0010\u001a\u00020\b2\u0006\u0010\f\u001a\u00020\u00022\u0006\u0010\u000e\u001a\u00020\r2\u0006\u0010\u000f\u001a\u00020\r¢\u0006\u0004\b\u0010\u0010\u0011J\u0017\u0010\u0014\u001a\u00020\b2\u0006\u0010\u0013\u001a\u00020\u0012H\u0002¢\u0006\u0004\b\u0014\u0010\u0015J\u000f\u0010\u0016\u001a\u00020\bH\u0002¢\u0006\u0004\b\u0016\u0010\nJ\u000f\u0010\u0017\u001a\u00020\bH\u0002¢\u0006\u0004\b\u0017\u0010\nJ!\u0010\u001a\u001a\u00020\b2\b\u0010\u0018\u001a\u0004\u0018\u00010\u00022\u0006\u0010\u0019\u001a\u00020\rH\u0002¢\u0006\u0004\b\u001a\u0010\u001bJ\u0015\u0010\u001e\u001a\u00020\b2\u0006\u0010\u001d\u001a\u00020\u001c¢\u0006\u0004\b\u001e\u0010\u001fR\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0005\u0010 R$\u0010#\u001a\u00020!2\u0006\u0010\"\u001a\u00020!8\u0006@BX\u0086\u000e¢\u0006\f\n\u0004\b#\u0010$\u001a\u0004\b%\u0010&R\u001b\u0010,\u001a\u00020'8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b(\u0010)\u001a\u0004\b*\u0010+R\u0018\u0010\u0013\u001a\u0004\u0018\u00010\u00128\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0013\u0010-R\u0017\u0010\u0003\u001a\u00020\u00028\u0006¢\u0006\f\n\u0004\b\u0003\u0010.\u001a\u0004\b/\u00100¨\u00063"}, d2 = {"Lcom/finogeeks/lib/applet/api/network/tcp/TCPSocket;", "", "", "socketId", "Lcom/finogeeks/lib/applet/api/network/tcp/TCPSocket$Callback;", "callback", "<init>", "(Ljava/lang/String;Lcom/finogeeks/lib/applet/api/network/tcp/TCPSocket$Callback;)V", "Llg0/e0;", "close", "()V", "closeQuietly", "address", "", "port", "timeout", "connect", "(Ljava/lang/String;II)V", "Ljava/net/Socket;", "socket", "loopReadData", "(Ljava/net/Socket;)V", "onSocketClose", "onSocketConnect", "errMsg", "errCode", "onSocketError", "(Ljava/lang/String;I)V", "", "data", "sendMessage", "([B)V", "Lcom/finogeeks/lib/applet/api/network/tcp/TCPSocket$Callback;", "", "<set-?>", "connected", "Z", "getConnected", "()Z", "", "forbiddenPorts$delegate", "Llg0/h;", "getForbiddenPorts", "()[I", "forbiddenPorts", "Ljava/net/Socket;", "Ljava/lang/String;", "getSocketId", "()Ljava/lang/String;", "Callback", "Companion", "finapplet_release"}, k = 1, mv = {1, 4, 0})
public final class TCPSocket {
static final l[] f = {g0.j(new y(g0.b(TCPSocket.class), "forbiddenPorts", "getForbiddenPorts()[I"))};
private final h a;
private Socket b;
private boolean c;
private final String d;
private final a e;
public interface a {
void a(String str);
void a(String str, String str2, int i);
void a(String str, JSONObject jSONObject);
void b(String str);
}
public static final class b {
private b() {
}
public b(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public static final class c extends p implements ah0.a<int[]> {
public static final c a = new c();
public c() {
super(0);
}
public final int[] invoke() {
return new int[]{1099, 1433, 1521, 1719, 1720, 1723, 2049, 2375, 3128, 3306, 3389, 3659, 4045, 5060, 5061, 5432, 5984, 6379, 6000, 6566, 7001, 7002, 8443, 8888, 9200, 9300, 10051, 10080, 11211, 27017, 27018, 27019};
}
}
static {
new b(null);
}
public TCPSocket(String str, a aVar) {
n.j(str, "socketId");
n.j(aVar, "callback");
this.d = str;
this.e = aVar;
this.a = i.a(c.a);
}
private final void a(String str, int i) {
this.e.a(this.d, str, i);
}
private final void a(Socket socket) {
String str;
String str2;
String str3 = "recv socket fail: ";
InetAddress inetAddress = socket.getInetAddress();
n.e(inetAddress, "remoteAddress");
String hostAddress = inetAddress.getHostAddress();
String str4 = inetAddress instanceof Inet4Address ? "IPv4" : "IPv6";
int port = socket.getPort();
InetAddress localAddress = socket.getLocalAddress();
n.e(localAddress, "localAddress");
String hostAddress2 = localAddress.getHostAddress();
String str5 = localAddress instanceof Inet4Address ? "IPv4" : "IPv6";
int localPort = socket.getLocalPort();
try {
InputStream inputStream = socket.getInputStream();
byte[] bArr = new byte[4096];
d0 d0Var = new d0();
while (true) {
try {
int read = inputStream.read(bArr);
d0Var.a = read;
InputStream inputStream2 = inputStream;
if (read == -1) {
str2 = str3;
a("recv socket fail: remote socket " + this.d + " closed", -2);
return;
}
str2 = str3;
try {
Object obj = str4;
JSONObject put = new JSONObject().put("message", Base64.encodeToString(bArr, 0, read, 2)).put("remoteInfo", new JSONObject().put("address", hostAddress).put("port", port).put("family", str4).put("size", d0Var.a)).put("localInfo", new JSONObject().put("address", hostAddress2).put("port", localPort).put("family", str5)).put("size", d0Var.a);
a aVar = this.e;
String str6 = this.d;
n.e(put, "info");
aVar.a(str6, put);
inputStream = inputStream2;
str3 = str2;
str4 = obj;
} catch (Exception e) {
e = e;
}
e = e;
} catch (Exception e2) {
e = e2;
str2 = str3;
}
try {
if (this.c) {
StringBuilder sb = new StringBuilder();
str = str2;
try {
sb.append(str);
sb.append(e.getMessage());
a(sb.toString(), -2);
return;
} catch (Exception e3) {
e = e3;
a(str + e.getMessage(), -2);
return;
}
}
return;
} catch (Exception e4) {
e = e4;
str = str2;
}
}
} catch (Exception e5) {
e = e5;
str = "recv socket fail: ";
}
}
private final int[] d() {
h hVar = this.a;
l lVar = f[0];
return (int[]) hVar.getValue();
}
private final void e() {
this.e.b(this.d);
}
private final void f() {
this.c = true;
this.e.a(this.d);
}
public final void a() {
if (!this.c) {
a("close socket tcp not call bind or connect", -1);
return;
}
this.c = false;
b();
e();
}
public final void a(String str, int i, int i2) {
n.j(str, "address");
if (this.c) {
a("this socket tcp has already connected", -1);
return;
}
if (i <= 1024 || mg0.l.x(d(), i) || (8000 <= i && 8100 >= i)) {
FLog.d$default("TCPSocket", "connect fail: 禁止的端口", null, 4, null);
a("connect fail: invalid address " + str + ':' + i, -4);
return;
}
try {
InetAddress byName = InetAddress.getByName(str);
n.e(byName, "inetAddress");
if (byName.isLoopbackAddress()) {
FLog.d$default("TCPSocket", "connect fail: 回环地址", null, 4, null);
a("connect fail: invalid address " + str + ':' + i, -4);
return;
}
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(str, i), i2);
this.b = socket;
InetAddress inetAddress = socket.getInetAddress();
InetAddress localAddress = socket.getLocalAddress();
n.e(inetAddress, "remoteAddress");
String hostAddress = inetAddress.getHostAddress();
n.e(localAddress, "localAddress");
if (!n.d(hostAddress, localAddress.getHostAddress())) {
f();
a(socket);
} else {
FLog.d$default("TCPSocket", "connect fail: 禁止与本机IP通信", null, 4, null);
a("connect socket fail: Connection refused", -2);
e();
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
a("invalid port \"" + i + '\"', 2);
} else if (e instanceof UnknownHostException) {
FLog.d$default("TCPSocket", "connect fail: 未知Host", null, 4, null);
a("connect socket getaddrinfo fail: " + e.getMessage(), 1);
} else if (e instanceof SocketTimeoutException) {
a("connect socket fail: timeout", -2);
} else {
a("connect socket fail: " + e.getMessage(), -2);
}
e();
}
} catch (Exception e2) {
FLog.d$default("TCPSocket", "connect fail: 无法解析ip地址", null, 4, null);
a("connect socket getaddrinfo fail: " + e2.getMessage(), 1);
}
}
public final void a(byte[] bArr) {
n.j(bArr, "data");
if (!this.c) {
a("send socket tcp not call accept or connect", -1);
return;
}
Socket socket = this.b;
if (socket != null) {
try {
socket.getOutputStream().write(bArr);
} catch (Exception e) {
a("send socket fail: " + e.getMessage(), -2);
}
}
}
public final void b() {
try {
Socket socket = this.b;
if (socket != null) {
socket.close();
}
} catch (Exception unused) {
}
}
public final String getD() {
return this.d;
}
}