吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 663|回复: 2
收起左侧

[求助] 请问这个类的源码大概是什么意思?java的

[复制链接]
ppgjx 发表于 2023-1-20 22:38
[Asm] 纯文本查看 复制代码
    package socks;


    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import server.RemoteServer;

    import java.util.Arrays;

    public class SocksConnectionRequest {
        /*
         * Data VER CMD RSV ATYP DST.ADDR           SDT.PORT
         *       1   1   1    1  Variable              2
         *       05  01  00  01  00000000             1010
         *       05  01  00  03  0962616964752E636F6D 0050
         * */


        private final static Logger logger = LoggerFactory.getLogger(SocksConnectionRequest.class);

        private final byte[] data;

        private byte version;
        private byte cmd;
        private byte rsv;
        private byte atyp;
        private String addr;
        private int port;

        private SocksConnectionRequest(byte[] data) {
            this.data = data;
            this.version = data[0];
            this.cmd = data[1];
            this.rsv = data[2];
            this.atyp = data[3];


            if (atyp == 0x01) { //ipv4
                addr = bytesToIpv4(Arrays.copyOfRange(data, 4, data.length - 2));
            } else if (atyp == 0x03) { //domain
                addr = bytesToDomain(Arrays.copyOfRange(data, 5, data.length - 2));
            } else if (atyp == 0x04) { //ipv6
                addr = bytesToIpv6(Arrays.copyOfRange(data, 4, data.length - 2));
            } else {
                logger.error("unknown atyp: " + atyp);
            }

            port = (data[data.length - 2] & 0xFF) * 256 + (data[data.length - 1] & 0xFF);
        }

        private static boolean validate(byte[] data) {
            if (data.length < 7) return false;
            if (data[0] != 0x05) return false;
            if (data[2] != 0x00) return false;
            return data[3] == 0x01 || data[3] == 0x03 || data[3] == 0x04;
        }

        public static SocksConnectionRequest fromBytes(byte[] data) {
            if(validate(data)) {
                return new SocksConnectionRequest(data);
            } else {
                return null;
            }
        }


        public String getAddress() {
            return addr;
        }

        public int getDstPort() {
            return port;
        }

        private String bytesToIpv4(byte[] addrBytes) {
            String ipv4AddrString = "";
            for (byte addrByte : addrBytes) {
                ipv4AddrString = ipv4AddrString.concat((addrByte & 0xFF) + ".");
            }
            return ipv4AddrString.substring(0, ipv4AddrString.length() - 1);
        }

        private String bytesToDomain(byte[] addrBytes) {
            StringBuilder domainString = new StringBuilder(addrBytes.length);
            for (byte addrByte : addrBytes) {
                domainString.append((char) addrByte);
            }
            return domainString.toString();
        }

        private String bytesToIpv6(byte[] addrBytes) {
            String ipv6AddrString = "";
            for (byte addrByte : addrBytes) {
                ipv6AddrString = ipv6AddrString.concat(String.valueOf(addrByte) + ":");
            }
            return ipv6AddrString.substring(0, ipv6AddrString.length() - 1);
        }

    }


一点都看不懂 为啥还有十六进制。。。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

天心阁下 发表于 2023-1-24 03:54
处理socks5的请求阶段

+----+-----+-------+-------+------------+-----------+
|VER | CMD |  RSV   |  ATYP  | DST.ADDR | DST.PORT |
+----+-----+-------+-------+------------+-----------+
| 1     |   1    |  X'00'  |     1     |    Variable  |       2         |
+----+-----+-------+-------+------------+-----------+
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 01:53

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表