Package com.lixia.rdp.Package

Examples of com.lixia.rdp.Package.RdpPackage


            // append to the defragmentation buffer
            byte[] content = new byte[data.getEnd() - data.getPosition()];
            data.copyToByteArray(content, 0, data.getPosition(), content.length);
            fragment_buffer = append(fragment_buffer, content);
            if ((flags & CHANNEL_FLAG_LAST) != 0) {
                RdpPackage fullpacket = new RdpPackage(fragment_buffer.length);
                fullpacket.copyFromByteArray(fragment_buffer, 0, 0, fragment_buffer.length);
                // process the entire reconstructed packet
                channel.process(fullpacket);
                fragment_buffer = null;
            }
View Full Code Here


     * @param length Desired length of packet
     * @return Packet prepared for this channel
     * @throws RdesktopException
     */
    public RdpPackage init(int length) throws RdesktopException {
        RdpPackage s;

        s = RDPConnection.conf.secure.init(RDPConnection.conf.encryption ? Secure.SEC_ENCRYPT : 0, length + 8);
        s.setHeader(RdpPackage.CHANNEL_HEADER);
        s.incrementPosition(8);

        return s;
    }
View Full Code Here

        while (data_offset < length) {

            int thisLength = Math.min(VChannels.CHANNEL_CHUNK_LENGTH, length - data_offset);

            RdpPackage s = RDPConnection.conf.secure.init(RDPConnection.conf.encryption ? Secure.SEC_ENCRYPT : 0, 8 + thisLength);
            s.setLittleEndian32(length);

            int flags = ((data_offset == 0) ? VChannels.CHANNEL_FLAG_FIRST : 0);
            if (data_offset + thisLength >= length) {
                flags |= VChannels.CHANNEL_FLAG_LAST;
            }

            if ((this.flags() & VChannels.CHANNEL_OPTION_SHOW_PROTOCOL) != 0) {
                flags |= VChannels.CHANNEL_FLAG_SHOW_PROTOCOL;
            }
            //System.out.printf("Sending %d bytes with flags %d\n", thisLength, flags);
            s.setLittleEndian32(flags);
            s.copyFromPacket(data, data_offset, s.getPosition(), thisLength);
            s.incrementPosition(thisLength);
            s.markEnd();

            data_offset += thisLength;

            if (RDPConnection.conf.secure != null) {
                RDPConnection.conf.secure.send_to_channel(s, RDPConnection.conf.encryption ? Secure.SEC_ENCRYPT : 0, this.mcs_id());
View Full Code Here

            StringTokenizer tok = new StringTokenizer(name, ".");
            RDPConnection.conf.hostname = tok.nextToken();
            RDPConnection.conf.hostname.trim();
        }

        RdpPackage mcs_data = this.sendMcsData();
        McsLayer.connect(host, port, mcs_data);

        this.processMcsData(mcs_data);

        if (RDPConnection.conf.encryption) {
View Full Code Here

     * @return Packet populated with MCS data
     */
    public RdpPackage sendMcsData() {
//        logger.debug("Secure.sendMcsData");

        RdpPackage buffer = new RdpPackage(512);
        int hostlen = 2 * (RDPConnection.conf.hostname == null ? 0 : RDPConnection.conf.hostname.length());
        if (hostlen > 30) {
            hostlen = 30;
        }

        int length = 158;
        if (RDPConnection.conf.use_rdp5) {
            length += 76 + 12 + 4;
        }

        if (RDPConnection.conf.use_rdp5 && (channels.num_channels() > 0)) {
            length += channels.num_channels() * 12 + 8;
        }

        buffer.setBigEndian16(5)/* unknown */

        buffer.setBigEndian16(0x14);
        buffer.set8(0x7c);
        buffer.setBigEndian16(1);

        buffer.setBigEndian16(length | 0x8000)// remaining length

        buffer.setBigEndian16(8)// length?
        buffer.setBigEndian16(16);
        buffer.set8(0);
        buffer.setLittleEndian16(0xc001);
        buffer.set8(0);

        buffer.setLittleEndian32(0x61637544)// "Duca" ?!
        buffer.setBigEndian16(length - 14 | 0x8000)// remaining length

        // Client information
        buffer.setLittleEndian16(SEC_TAG_CLI_INFO);
        buffer.setLittleEndian16(RDPConnection.conf.use_rdp5 ? 212 : 136)// length
        buffer.setLittleEndian16(RDPConnection.conf.use_rdp5 ? 4 : 1);
        buffer.setLittleEndian16(8);
        buffer.setLittleEndian16(RDPConnection.conf.width);
        buffer.setLittleEndian16(RDPConnection.conf.height);
        buffer.setLittleEndian16(0xca01);
        buffer.setLittleEndian16(0xaa03);
        buffer.setLittleEndian32(RDPConnection.conf.keylayout);
        buffer.setLittleEndian32(RDPConnection.conf.use_rdp5 ? 2600 : 419); // or 0ece  // client build? we are 2600 compatible :-)

        /* Unicode name of client, padded to 32 bytes */
        buffer.outUnicodeString(RDPConnection.conf.hostname.toUpperCase(), hostlen);
        buffer.incrementPosition(30 - hostlen);

        buffer.setLittleEndian32(4);
        buffer.setLittleEndian32(0);
        buffer.setLittleEndian32(12);
        buffer.incrementPosition(64)/* reserved? 4 + 12 doublewords */

        buffer.setLittleEndian16(0xca01); // out_uint16_le(s, 0xca01);
        buffer.setLittleEndian16(RDPConnection.conf.use_rdp5 ? 1 : 0);

        if (RDPConnection.conf.use_rdp5) {
            buffer.setLittleEndian32(0); // out_uint32(s, 0);
            buffer.set8(RDPConnection.conf.server_bpp); // out_uint8(s, g_server_bpp);
            buffer.setLittleEndian16(0x0700); // out_uint16_le(s, 0x0700);
            buffer.set8(0); // out_uint8(s, 0);
            buffer.setLittleEndian32(1); // out_uint32_le(s, 1);

            buffer.incrementPosition(64);

            buffer.setLittleEndian16(SEC_TAG_CLI_4); // out_uint16_le(s, SEC_TAG_CLI_4);
            buffer.setLittleEndian16(12); // out_uint16_le(s, 12);
            buffer.setLittleEndian32(RDPConnection.conf.console_session ? 0xb : 0xd); // out_uint32_le(s, g_console_session ? 0xb : 9);
            buffer.setLittleEndian32(0); // out_uint32(s, 0);
        }

        // Client encryption settings //
        buffer.setLittleEndian16(SEC_TAG_CLI_CRYPT);
        buffer.setLittleEndian16(RDPConnection.conf.use_rdp5 ? 12 : 8)// length

        //if(RDPConnection.conf.use_rdp5) buffer.setLittleEndian32(RDPConnection.conf.encryption ? 0x1b : 0);  // 128-bit encryption supported
        //else
        buffer.setLittleEndian32(RDPConnection.conf.encryption ? (RDPConnection.conf.console_session ? 0xb : 0x3) : 0);

        if (RDPConnection.conf.use_rdp5) {
            buffer.setLittleEndian32(0); // unknown
        }
        if (RDPConnection.conf.use_rdp5 && (channels.num_channels() > 0)) {
//            logger.debug(("num_channels is " + channels.num_channels()));
            buffer.setLittleEndian16(SEC_TAG_CLI_CHANNELS); // out_uint16_le(s, SEC_TAG_CLI_CHANNELS);
            buffer.setLittleEndian16(channels.num_channels() * 12 + 8); // out_uint16_le(s, g_num_channels * 12 + 8);  // length
            buffer.setLittleEndian32(channels.num_channels()); // out_uint32_le(s, g_num_channels);  // number of virtual channels
            for (int i = 0; i < channels.num_channels(); i++) {
//                logger.debug(("Requesting channel " + channels.channel(i).name()));
                buffer.out_uint8p(channels.channel(i).name(), 8); // out_uint8a(s, g_channels[i].name, 8);
                buffer.setBigEndian32(channels.channel(i).flags()); // out_uint32_be(s, g_channels[i].flags);
            }
        }

        buffer.markEnd();
        return buffer;
    }
View Full Code Here

            rdpdr_version_minor = versionMinor;
        }
    }

    private void rdpdr_send_client_announce_reply() {
        RdpPackage s;

        s = new RdpPackage(12);
        s.setLittleEndian16(RDPDR_COMPONENT_TYPE_CORE);
        s.setLittleEndian16(PAKID_CORE_CLIENTID_CONFIRM);
        s.setLittleEndian16(1);// versionMajor, must be set to 1
        s.setLittleEndian16(rdpdr_version_minor);// versionMinor
        if (rdpdr_clientid > 0) {
            s.setLittleEndian32(rdpdr_clientid); // clientID, given by the server in a Server Announce Request
        } else {
            s.setLittleEndian32(0x815ed39d);///* IP address (use 127.0.0.1) 0x815ed39d */
        }
        s.markEnd();

        try {
            this.send_packet(s);
        } catch (RdesktopException e) {
        } catch (IOException e) {
View Full Code Here

        int sec_flags = Secure.SEC_LICENCE_NEG;
        int userlen = (username.length == 0 ? 0 : username.length + 1);
        int hostlen = (hostname.length == 0 ? 0 : hostname.length + 1);
        int length = 128 + userlen + hostlen;

        RdpPackage buffer = secure.init(sec_flags, length);

        buffer.set8(LICENCE_TAG_REQUEST);
        buffer.set8(2); // version
        buffer.setLittleEndian16(length);

        buffer.setLittleEndian32(1);

        if (RDPConnection.conf.built_in_licence && (!RDPConnection.conf.load_licence) && (!RDPConnection.conf.save_licence)) {
//            logger.debug("Using built-in Windows Licence");
            buffer.setLittleEndian32(0x03010000);
        } else {
//            logger.debug("Requesting licence");
            buffer.setLittleEndian32(0xff010000);
        }
        buffer.copyFromByteArray(client_random, 0, buffer.getPosition(), Secure.SEC_RANDOM_SIZE);
        buffer.incrementPosition(Secure.SEC_RANDOM_SIZE);
        buffer.setLittleEndian16(0);

        buffer.setLittleEndian16(Secure.SEC_MODULUS_SIZE + Secure.SEC_PADDING_SIZE);
        buffer.copyFromByteArray(rsa_data, 0, buffer.getPosition(), Secure.SEC_MODULUS_SIZE);
        buffer.incrementPosition(Secure.SEC_MODULUS_SIZE);

        buffer.incrementPosition(Secure.SEC_PADDING_SIZE);

        buffer.setLittleEndian16(LICENCE_TAG_USER);
        buffer.setLittleEndian16(userlen);

        if (username.length != 0) {
            buffer.copyFromByteArray(username, 0, buffer.getPosition(), userlen - 1);
        } else {
            buffer.copyFromByteArray(username, 0, buffer.getPosition(), userlen);
        }

        buffer.incrementPosition(userlen);

        buffer.setLittleEndian16(LICENCE_TAG_HOST);
        buffer.setLittleEndian16(hostlen);

        if (hostname.length != 0) {
            buffer.copyFromByteArray(hostname, 0, buffer.getPosition(), hostlen - 1);
        } else {
            buffer.copyFromByteArray(hostname, 0, buffer.getPosition(), hostlen);
        }
        buffer.incrementPosition(hostlen);
        buffer.markEnd();
        secure.send(buffer, sec_flags);
    }
View Full Code Here

     * @param length Desired length of PDU
     * @return
     * @throws RdesktopException
     */
    public RdpPackage init(int length) throws RdesktopException {
        RdpPackage data = IsoLayer.init(length + 8);
        //data.pushLayer(RdpPackage.MCS_HEADER, 8);
        data.setHeader(RdpPackage.MCS_HEADER);
        data.incrementPosition(8);
        data.setStart(data.getPosition());
        return data;
    }
View Full Code Here

     */
    public RdpPackage receive(int[] channel) throws IOException,
            RdesktopException, OrderException, CryptoException {
//    logger.debug("receive");
        int opcode = 0, appid = 0, length = 0;
        RdpPackage buffer = IsoLayer.receive();
        if (buffer == null) {
            return null;
        }
        buffer.setHeader(RdpPackage.MCS_HEADER);
        opcode = buffer.get8();

        appid = opcode >> 2;

        if (appid != SDIN) {
            if (appid != DPUM) {
                throw new RdesktopException("Expected data got" + opcode);
            }
            throw new EOFException("End of transmission!");
        }

        buffer.incrementPosition(2); // Skip UserID
        channel[0] = buffer.getBigEndian16(); // Get ChannelID
//    logger.debug("Channel ID = " + channel[0]);
        buffer.incrementPosition(1); // Skip Flags

        length = buffer.get8();

        if ((length & 0x80) != 0) {
            buffer.incrementPosition(1);
        }
        buffer.setStart(buffer.getPosition());

        return buffer;

    }
View Full Code Here

     */
    public void sendConnectInitial(RdpPackage data) throws IOException, RdesktopException {
//        logger.debug("MCS.sendConnectInitial");
        if (false) {
            int length = 7 + (3 * 34) + 4 + data.getEnd();
            RdpPackage buffer = IsoLayer.init(length + 5);

            sendBerHeader(buffer, CONNECT_INITIAL, length);
            sendBerHeader(buffer, BER_TAG_OCTET_STRING, 0); //calling domain
            sendBerHeader(buffer, BER_TAG_OCTET_STRING, 0); // called domain

            sendBerHeader(buffer, BER_TAG_BOOLEAN, 1);
            buffer.set8(255); //upward flag

            sendDomainParams(buffer, 2, 2, 0, 0xffff); //target parameters
            sendDomainParams(buffer, 1, 1, 1, 0x420); // minimun parameters
            sendDomainParams(buffer, 0xffff, 0xfc17, 0xffff, 0xffff); //maximum parameters

            sendBerHeader(buffer, BER_TAG_OCTET_STRING, data.getEnd());

            data.copyToPacket(buffer, 0, buffer.getPosition(), data.getEnd());
            buffer.incrementPosition(data.getEnd());
            buffer.markEnd();
            IsoLayer.send(buffer);
            return;
        }

//        logger.debug("MCS.sendConnectInitial");
        int datalen = data.getEnd();
        int length = 9 + domainParamSize(34, 2, 0, 0xffff)
                + domainParamSize(1, 1, 1, 0x420)
                + domainParamSize(0xffff, 0xfc17, 0xffff, 0xffff) + 4 + datalen; // RDP5 Code

        RdpPackage buffer = IsoLayer.init(length + 5);

        sendBerHeader(buffer, CONNECT_INITIAL, length);
        sendBerHeader(buffer, BER_TAG_OCTET_STRING, 1); //calling domain
        buffer.set8(1); // RDP5 Code
        sendBerHeader(buffer, BER_TAG_OCTET_STRING, 1); // called domain
        buffer.set8(1); // RDP5 Code

        sendBerHeader(buffer, BER_TAG_BOOLEAN, 1);
        buffer.set8(0xff); //upward flag

        sendDomainParams(buffer, 34, 2, 0, 0xffff); //target parameters // RDP5 Code
        sendDomainParams(buffer, 1, 1, 1, 0x420); // minimum parameters
        sendDomainParams(buffer, 0xffff, 0xfc17, 0xffff, 0xffff); //maximum parameters

        sendBerHeader(buffer, BER_TAG_OCTET_STRING, datalen);

        data.copyToPacket(buffer, 0, buffer.getPosition(), data.getEnd());
        buffer.incrementPosition(data.getEnd());
        buffer.markEnd();
        IsoLayer.send(buffer);
    }
View Full Code Here

TOP

Related Classes of com.lixia.rdp.Package.RdpPackage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.