imToken v2.9.3版本的 MD5 值为:42af1a08a3f01f69d2f3782d81007b3c
以下内容为反编译后的 SocksRequest.java 源代码,内容仅作参考
package com.subgraph.orchid.socks;
import androidx.lifecycle.CoroutineLiveDataKt;
import com.subgraph.orchid.TorConfig;
import com.subgraph.orchid.data.IPv4Address;
import java.io.IOException;
import java.net.Socket;
import java.util.logging.Logger;
public abstract class SocksRequest {
private static final Logger logger = Logger.getLogger(SocksRequest.class.getName());
private IPv4Address address;
private byte[] addressData;
private final TorConfig config;
private String hostname;
private long lastWarningTimestamp = 0;
private int port;
private final Socket socket;
public abstract int getCommandCode();
public abstract boolean isConnectRequest();
public abstract void readRequest() throws SocksRequestException;
public abstract void sendConnectionRefused() throws SocksRequestException;
public abstract void sendError(boolean z) throws SocksRequestException;
public abstract void sendSuccess() throws SocksRequestException;
public SocksRequest(TorConfig torConfig, Socket socket) {
this.config = torConfig;
this.socket = socket;
}
public int getPort() {
return this.port;
}
public IPv4Address getAddress() {
return this.address;
}
public boolean hasHostname() {
return this.hostname != null;
}
public String getHostname() {
return this.hostname;
}
public String getTarget() {
if (this.config.getSafeLogging()) {
return "[scrubbed]:" + this.port;
}
if (this.hostname != null) {
return this.hostname + ":" + this.port;
}
return this.address + ":" + this.port;
}
public void setPortData(byte[] bArr) throws SocksRequestException {
if (bArr.length != 2) {
throw new SocksRequestException();
}
this.port = (bArr[1] & 255) | ((bArr[0] & 255) << 8);
}
public void setIPv4AddressData(byte[] bArr) throws SocksRequestException {
logUnsafeSOCKS();
if (bArr.length != 4) {
throw new SocksRequestException();
}
this.addressData = bArr;
int i = 0;
for (byte b : bArr) {
i = (i << 8) | (b & 255);
}
this.address = new IPv4Address(i);
}
private boolean testRateLimit() {
long currentTimeMillis = System.currentTimeMillis();
long j = currentTimeMillis - this.lastWarningTimestamp;
this.lastWarningTimestamp = currentTimeMillis;
return j > CoroutineLiveDataKt.DEFAULT_TIMEOUT;
}
private void logUnsafeSOCKS() throws SocksRequestException {
if ((this.config.getWarnUnsafeSocks() || this.config.getSafeSocks()) && testRateLimit()) {
logger.warning("Your application is giving Orchid only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4a (e.g. via privoxy or socat) instead. For more information please see https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS");
}
if (this.config.getSafeSocks()) {
throw new SocksRequestException("Rejecting unsafe SOCKS request");
}
}
public void setHostname(String str) {
this.hostname = str;
}
public byte[] readPortData() throws SocksRequestException {
byte[] bArr = new byte[2];
readAll(bArr, 0, 2);
return bArr;
}
public byte[] readIPv4AddressData() throws SocksRequestException {
byte[] bArr = new byte[4];
readAll(bArr);
return bArr;
}
public byte[] readIPv6AddressData() throws SocksRequestException {
byte[] bArr = new byte[16];
readAll(bArr);
return bArr;
}
public String readNullTerminatedString() throws SocksRequestException {
try {
StringBuilder sb = new StringBuilder();
while (true) {
int read = this.socket.getInputStream().read();
if (read == -1) {
throw new SocksRequestException();
}
if (read == 0) {
return sb.toString();
}
sb.append((char) read);
}
} catch (IOException e) {
throw new SocksRequestException(e);
}
}
public int readByte() throws SocksRequestException {
try {
int read = this.socket.getInputStream().read();
if (read != -1) {
return read;
}
throw new SocksRequestException();
} catch (IOException e) {
throw new SocksRequestException(e);
}
}
protected void readAll(byte[] bArr) throws SocksRequestException {
readAll(bArr, 0, bArr.length);
}
public void readAll(byte[] bArr, int i, int i2) throws SocksRequestException {
while (i2 > 0) {
try {
int read = this.socket.getInputStream().read(bArr, i, i2);
if (read == -1) {
throw new SocksRequestException();
}
i += read;
i2 -= read;
} catch (IOException e) {
throw new SocksRequestException(e);
}
}
}
public void socketWrite(byte[] bArr) throws SocksRequestException {
try {
this.socket.getOutputStream().write(bArr);
} catch (IOException e) {
throw new SocksRequestException(e);
}
}
}