⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orders.java

📁 cygwin 是一个在windows平台上运行的unix模拟环境
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* Orders.java
 * Component: ProperJavaRDP
 * 
 * Revision: $Revision: 1.7 $
 * Author: $Author: telliott $
 * Date: $Date: 2005/09/27 14:15:39 $
 *
 * Copyright (c) 2005 Propero Limited
 *
 * Purpose: Encapsulates an RDP order
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 * 
 * (See gpl.txt for details of the GNU General Public License.)
 * 
 */
package net.propero.rdp;

import org.apache.log4j.Logger;

import java.awt.image.IndexColorModel;
import java.io.IOException;

import net.propero.rdp.orders.*;

public class Orders {
    static Logger logger = Logger.getLogger(Orders.class);

    private OrderState os = null;

    private RdesktopCanvas surface = null;

    public static Cache cache = null;

    /* RDP_BMPCACHE2_ORDER */
    private static final int ID_MASK = 0x0007;
    private static final int MODE_MASK = 0x0038;
    private static final int SQUARE = 0x0080;
    private static final int PERSIST = 0x0100;
    private static final int FLAG_51_UNKNOWN = 0x0800;
    private static final int MODE_SHIFT = 3;
    private static final int LONG_FORMAT = 0x80;
    private static final int BUFSIZE_MASK = 0x3FFF; /* or 0x1FFF? */
    private static final int RDP_ORDER_STANDARD = 0x01;
    private static final int RDP_ORDER_SECONDARY = 0x02;
    private static final int RDP_ORDER_BOUNDS = 0x04;
    private static final int RDP_ORDER_CHANGE = 0x08;
    private static final int RDP_ORDER_DELTA = 0x10;
    private static final int RDP_ORDER_LASTBOUNDS = 0x20;
    private static final int RDP_ORDER_SMALL = 0x40;
    private static final int RDP_ORDER_TINY = 0x80;

    /* standard order types */
    private static final int RDP_ORDER_DESTBLT = 0;
    private static final int RDP_ORDER_PATBLT = 1;
    private static final int RDP_ORDER_SCREENBLT = 2;
    private static final int RDP_ORDER_LINE = 9;
    private static final int RDP_ORDER_RECT = 10;
    private static final int RDP_ORDER_DESKSAVE = 11;
    private static final int RDP_ORDER_MEMBLT = 13;
    private static final int RDP_ORDER_TRIBLT = 14;
    private static final int RDP_ORDER_POLYLINE = 22;
    private static final int RDP_ORDER_TEXT2 = 27;
    private int rect_colour;

    /* secondary order types */
    private static final int RDP_ORDER_RAW_BMPCACHE = 0;
    private static final int RDP_ORDER_COLCACHE = 1;
    private static final int RDP_ORDER_BMPCACHE = 2;
    private static final int RDP_ORDER_FONTCACHE = 3;
    private static final int RDP_ORDER_RAW_BMPCACHE2 = 4;
    private static final int RDP_ORDER_BMPCACHE2 = 5;
    private static final int MIX_TRANSPARENT = 0;
    private static final int MIX_OPAQUE = 1;
    private static final int TEXT2_VERTICAL = 0x04;
    private static final int TEXT2_IMPLICIT_X = 0x20;

    public Orders() {
        os = new OrderState();
    }

    public void resetOrderState() {
        this.os.reset();
        os.setOrderType(RDP_ORDER_PATBLT);
        return;
    }

    private int inPresent(RdpPacket_Localised data, int flags, int size) {
        int present = 0;
        int bits = 0;
        int i = 0;

        if ((flags & RDP_ORDER_SMALL) != 0) {
            size--;
        }

        if ((flags & RDP_ORDER_TINY) != 0) {

            if (size < 2) {
                size = 0;
            } else {
                size -= 2;
            }
        }

        for (i = 0; i < size; i++) {
            bits = data.get8();
            present |= (bits << (i * 8));
        }
        return present;
    }

    /**
     * Process a set of orders sent by the server
     * @param data Packet packet containing orders
     * @param next_packet Offset of end of this packet (start of next)
     * @param n_orders Number of orders sent in this packet
     * @throws OrderException
     * @throws RdesktopException
     */
    public void processOrders(RdpPacket_Localised data, int next_packet,
            int n_orders) throws OrderException, RdesktopException {

        int present = 0;
        // int n_orders = 0;
        int order_flags = 0, order_type = 0;
        int size = 0, processed = 0;
        boolean delta;

        while (processed < n_orders) {

            order_flags = data.get8();

            if ((order_flags & RDP_ORDER_STANDARD) == 0) {
                throw new OrderException("Order parsing failed!");
            }

            if ((order_flags & RDP_ORDER_SECONDARY) != 0) {
                this.processSecondaryOrders(data);
            } else {

                if ((order_flags & RDP_ORDER_CHANGE) != 0) {
                    os.setOrderType(data.get8());
                }

                switch (os.getOrderType()) {
                case RDP_ORDER_TRIBLT:
                case RDP_ORDER_TEXT2:
                    size = 3;
                    break;

                case RDP_ORDER_PATBLT:
                case RDP_ORDER_MEMBLT:
                case RDP_ORDER_LINE:
                    size = 2;
                    break;

                default:
                    size = 1;
                }

                present = this.inPresent(data, order_flags, size);

                if ((order_flags & RDP_ORDER_BOUNDS) != 0) {

                    if ((order_flags & RDP_ORDER_LASTBOUNDS) == 0) {
                        this.parseBounds(data, os.getBounds());
                    }

                    surface.setClip(os.getBounds());
                }

                delta = ((order_flags & RDP_ORDER_DELTA) != 0);

                switch (os.getOrderType()) {
                case RDP_ORDER_DESTBLT:
                    logger.debug("DestBlt Order");
                    this.processDestBlt(data, os.getDestBlt(), present, delta);
                    break;

                case RDP_ORDER_PATBLT:
                    logger.debug("PatBlt Order");
                    this.processPatBlt(data, os.getPatBlt(), present, delta);
                    break;

                case RDP_ORDER_SCREENBLT:
                    logger.debug("ScreenBlt Order");
                    this.processScreenBlt(data, os.getScreenBlt(), present,
                            delta);
                    break;

                case RDP_ORDER_LINE:
                    logger.debug("Line Order");
                    this.processLine(data, os.getLine(), present, delta);
                    break;

                case RDP_ORDER_RECT:
                    logger.debug("Rectangle Order");
                    this.processRectangle(data, os.getRectangle(), present,
                            delta);
                    break;

                case RDP_ORDER_DESKSAVE:
                    logger.debug("Desksave!");
                    this
                            .processDeskSave(data, os.getDeskSave(), present,
                                    delta);
                    break;

                case RDP_ORDER_MEMBLT:
                    logger.debug("MemBlt Order");
                    this.processMemBlt(data, os.getMemBlt(), present, delta);
                    break;

                case RDP_ORDER_TRIBLT:
                    logger.debug("TriBlt Order");
                    this.processTriBlt(data, os.getTriBlt(), present, delta);
                    break;

                case RDP_ORDER_POLYLINE:
                    logger.debug("Polyline Order");
                    this
                            .processPolyLine(data, os.getPolyLine(), present,
                                    delta);
                    break;

                case RDP_ORDER_TEXT2:
                    logger.debug("Text2 Order");
                    this.processText2(data, os.getText2(), present, delta);
                    break;

                default:
                    logger.warn("Unimplemented Order type " + order_type);
                    return;
                }

                if ((order_flags & RDP_ORDER_BOUNDS) != 0) {
                    surface.resetClip();
                    logger.debug("Reset clip");
                }
            }

            processed++;
        }
        if (data.getPosition() != next_packet) {
            throw new OrderException("End not reached!");
        }
    }

    private int ROP2_S(int rop3) {
        return (rop3 & 0x0f);
    }

    private int ROP2_P(int rop3) {
        return ((rop3 & 0x3) | ((rop3 & 0x30) >> 2));
    }

    /**
     * Register an RdesktopCanvas with this Orders object.
     * This surface is where all drawing orders will be carried
     * out.
     * @param surface Surface to register
     */
    public void registerDrawingSurface(RdesktopCanvas surface) {
        this.surface = surface;
        surface.registerCache(cache);
    }

    /**
     * Handle secondary, or caching, orders
     * @param data Packet containing secondary order
     * @throws OrderException
     * @throws RdesktopException
     */
    private void processSecondaryOrders(RdpPacket_Localised data)
            throws OrderException, RdesktopException {
        int length = 0;
        int type = 0;
        int flags = 0;
        int next_order = 0;

        length = data.getLittleEndian16();
        flags = data.getLittleEndian16();
        type = data.get8();

        next_order = data.getPosition() + length + 7;

        switch (type) {

        case RDP_ORDER_RAW_BMPCACHE:
            logger.debug("Raw BitmapCache Order");
            this.processRawBitmapCache(data);
            break;

        case RDP_ORDER_COLCACHE:
            logger.debug("Colorcache Order");
            this.processColorCache(data);
            break;

        case RDP_ORDER_BMPCACHE:
            logger.debug("Bitmapcache Order");
            this.processBitmapCache(data);
            break;

        case RDP_ORDER_FONTCACHE:
            logger.debug("Fontcache Order");
            this.processFontCache(data);
            break;

        case RDP_ORDER_RAW_BMPCACHE2:
            try {
                this.process_bmpcache2(data, flags, false);
            } catch (IOException e) {
                throw new RdesktopException(e.getMessage());
            } /* uncompressed */
            break;

        case RDP_ORDER_BMPCACHE2:
            try {
                this.process_bmpcache2(data, flags, true);
            } catch (IOException e) {
                throw new RdesktopException(e.getMessage());
            } /* compressed */
            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -