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

📄 rfbproto.java

📁 JAVA版vpn客户端,是在web上实现远程访问的最佳方式.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    int reasonLen = is.readInt();    byte[] reason = new byte[reasonLen];    readFully(reason);    throw new Exception(new String(reason));  }  //  // Initialize capability lists (TightVNC protocol extensions).  //  void initCapabilities() {    tunnelCaps    = new CapsContainer();    authCaps      = new CapsContainer();    serverMsgCaps = new CapsContainer();    clientMsgCaps = new CapsContainer();    encodingCaps  = new CapsContainer();    // Supported authentication methods    authCaps.add(AuthNone, StandardVendor, SigAuthNone,		 "No authentication");    authCaps.add(AuthVNC, StandardVendor, SigAuthVNC,		 "Standard VNC password authentication");    // Supported encoding types    encodingCaps.add(EncodingCopyRect, StandardVendor,		     SigEncodingCopyRect, "Standard CopyRect encoding");    encodingCaps.add(EncodingRRE, StandardVendor,		     SigEncodingRRE, "Standard RRE encoding");    encodingCaps.add(EncodingCoRRE, StandardVendor,		     SigEncodingCoRRE, "Standard CoRRE encoding");    encodingCaps.add(EncodingHextile, StandardVendor,		     SigEncodingHextile, "Standard Hextile encoding");    encodingCaps.add(EncodingZRLE, StandardVendor,		     SigEncodingZRLE, "Standard ZRLE encoding");    encodingCaps.add(EncodingZlib, TridiaVncVendor,		     SigEncodingZlib, "Zlib encoding");    encodingCaps.add(EncodingTight, TightVncVendor,		     SigEncodingTight, "Tight encoding");    // Supported pseudo-encoding types    encodingCaps.add(EncodingCompressLevel0, TightVncVendor,		     SigEncodingCompressLevel0, "Compression level");    encodingCaps.add(EncodingQualityLevel0, TightVncVendor,		     SigEncodingQualityLevel0, "JPEG quality level");    encodingCaps.add(EncodingXCursor, TightVncVendor,		     SigEncodingXCursor, "X-style cursor shape update");    encodingCaps.add(EncodingRichCursor, TightVncVendor,		     SigEncodingRichCursor, "Rich-color cursor shape update");    encodingCaps.add(EncodingPointerPos, TightVncVendor,		     SigEncodingPointerPos, "Pointer position update");    encodingCaps.add(EncodingLastRect, TightVncVendor,		     SigEncodingLastRect, "LastRect protocol extension");    encodingCaps.add(EncodingNewFBSize, TightVncVendor,		     SigEncodingNewFBSize, "Framebuffer size change");  }  //  // Setup tunneling (TightVNC protocol extensions)  //  void setupTunneling() throws IOException {    int nTunnelTypes = is.readInt();    if (nTunnelTypes != 0) {      readCapabilityList(tunnelCaps, nTunnelTypes);      // We don't support tunneling yet.      writeInt(NoTunneling);    }  }  //  // Negotiate authentication scheme (TightVNC protocol extensions)  //  int negotiateAuthenticationTight() throws Exception {    int nAuthTypes = is.readInt();    if (nAuthTypes == 0)      return AuthNone;    readCapabilityList(authCaps, nAuthTypes);    for (int i = 0; i < authCaps.numEnabled(); i++) {      int authType = authCaps.getByOrder(i);      if (authType == AuthNone || authType == AuthVNC) {	writeInt(authType);	return authType;      }    }    throw new Exception("No suitable authentication scheme found");  }  //  // Read a capability list (TightVNC protocol extensions)  //  void readCapabilityList(CapsContainer caps, int count) throws IOException {    int code;    byte[] vendor = new byte[4];    byte[] name = new byte[8];    for (int i = 0; i < count; i++) {      code = is.readInt();      readFully(vendor);      readFully(name);      caps.enable(new CapabilityInfo(code, vendor, name));    }  }  //  // Write a 32-bit integer into the output stream.  //  void writeInt(int value) throws IOException {    byte[] b = new byte[4];    b[0] = (byte) ((value >> 24) & 0xff);    b[1] = (byte) ((value >> 16) & 0xff);    b[2] = (byte) ((value >> 8) & 0xff);    b[3] = (byte) (value & 0xff);    os.write(b);  }  //  // Write the client initialisation message  //  void writeClientInit() throws IOException {    if (viewer.options.shareDesktop) {      os.write(1);    } else {      os.write(0);    }    viewer.options.disableShareDesktop();  }  //  // Read the server initialisation message  //  String desktopName;  int framebufferWidth, framebufferHeight;  int bitsPerPixel, depth;  boolean bigEndian, trueColour;  int redMax, greenMax, blueMax, redShift, greenShift, blueShift;  void readServerInit() throws IOException {    framebufferWidth = is.readUnsignedShort();    framebufferHeight = is.readUnsignedShort();    bitsPerPixel = is.readUnsignedByte();    depth = is.readUnsignedByte();    bigEndian = (is.readUnsignedByte() != 0);    trueColour = (is.readUnsignedByte() != 0);    redMax = is.readUnsignedShort();    greenMax = is.readUnsignedShort();    blueMax = is.readUnsignedShort();    redShift = is.readUnsignedByte();    greenShift = is.readUnsignedByte();    blueShift = is.readUnsignedByte();    byte[] pad = new byte[3];    readFully(pad);    int nameLength = is.readInt();    byte[] name = new byte[nameLength];    readFully(name);    desktopName = new String(name);    // Read interaction capabilities (TightVNC protocol extensions)    if (protocolTightVNC) {      int nServerMessageTypes = is.readUnsignedShort();      int nClientMessageTypes = is.readUnsignedShort();      int nEncodingTypes = is.readUnsignedShort();      is.readUnsignedShort();      readCapabilityList(serverMsgCaps, nServerMessageTypes);      readCapabilityList(clientMsgCaps, nClientMessageTypes);      readCapabilityList(encodingCaps, nEncodingTypes);    }    inNormalProtocol = true;  }  //  // Create session file and write initial protocol messages into it.  //  void startSession(String fname) throws IOException {    rec = new SessionRecorder(fname);    rec.writeHeader();    rec.write(versionMsg_3_3.getBytes());    rec.writeIntBE(SecTypeNone);    rec.writeShortBE(framebufferWidth);    rec.writeShortBE(framebufferHeight);    byte[] fbsServerInitMsg =	{      32, 24, 0, 1, 0,      (byte)0xFF, 0, (byte)0xFF, 0, (byte)0xFF,      16, 8, 0, 0, 0, 0    };    rec.write(fbsServerInitMsg);    rec.writeIntBE(desktopName.length());    rec.write(desktopName.getBytes());    numUpdatesInSession = 0;    // FIXME: If there were e.g. ZRLE updates only, that should not    //        affect recording of Zlib and Tight updates. So, actually    //        we should maintain separate flags for Zlib, ZRLE and    //        Tight, instead of one ``wereZlibUpdates'' variable.    //    if (wereZlibUpdates)      recordFromBeginning = false;    zlibWarningShown = false;    tightWarningShown = false;  }  //  // Close session file.  //  void closeSession() throws IOException {    if (rec != null) {      rec.close();      rec = null;    }  }  //  // Set new framebuffer size  //  void setFramebufferSize(int width, int height) {    framebufferWidth = width;    framebufferHeight = height;  }  //  // Read the server message type  //  int readServerMessageType() throws IOException {    int msgType = is.readUnsignedByte();    // If the session is being recorded:    if (rec != null) {      if (msgType == Bell) {	// Save Bell messages in session files.	rec.writeByte(msgType);	if (numUpdatesInSession > 0)	  rec.flush();      }    }    return msgType;  }  //  // Read a FramebufferUpdate message  //  int updateNRects;  void readFramebufferUpdate() throws IOException {    is.readByte();    updateNRects = is.readUnsignedShort();    // If the session is being recorded:    if (rec != null) {      rec.writeByte(FramebufferUpdate);      rec.writeByte(0);      rec.writeShortBE(updateNRects);    }    numUpdatesInSession++;  }  // Read a FramebufferUpdate rectangle header  int updateRectX, updateRectY, updateRectW, updateRectH, updateRectEncoding;  void readFramebufferUpdateRectHdr() throws Exception {    updateRectX = is.readUnsignedShort();    updateRectY = is.readUnsignedShort();    updateRectW = is.readUnsignedShort();    updateRectH = is.readUnsignedShort();    updateRectEncoding = is.readInt();    if (updateRectEncoding == EncodingZlib ||        updateRectEncoding == EncodingZRLE ||	updateRectEncoding == EncodingTight)      wereZlibUpdates = true;    // If the session is being recorded:    if (rec != null) {      if (numUpdatesInSession > 1)	rec.flush();		// Flush the output on each rectangle.      rec.writeShortBE(updateRectX);      rec.writeShortBE(updateRectY);      rec.writeShortBE(updateRectW);      rec.writeShortBE(updateRectH);      if (updateRectEncoding == EncodingZlib && !recordFromBeginning) {	// Here we cannot write Zlib-encoded rectangles because the	// decoder won't be able to reproduce zlib stream state.	if (!zlibWarningShown) {	  System.out.println("Warning: Raw encoding will be used " +			     "instead of Zlib in recorded session.");	  zlibWarningShown = true;	}	rec.writeIntBE(EncodingRaw);      } else {	rec.writeIntBE(updateRectEncoding);	if (updateRectEncoding == EncodingTight && !recordFromBeginning &&	    !tightWarningShown) {	  System.out.println("Warning: Re-compressing Tight-encoded " +			     "updates for session recording.");	  tightWarningShown = true;	}      }    }    if (updateRectEncoding < 0 || updateRectEncoding > MaxNormalEncoding)      return;    if (updateRectX + updateRectW > framebufferWidth ||	updateRectY + updateRectH > framebufferHeight) {      throw new Exception("Framebuffer update rectangle too large: " +			  updateRectW + "x" + updateRectH + " at (" +			  updateRectX + "," + updateRectY + ")");    }  }  // Read CopyRect source X and Y.  int copyRectSrcX, copyRectSrcY;  void readCopyRect() throws IOException {    copyRectSrcX = is.readUnsignedShort();    copyRectSrcY = is.readUnsignedShort();    // If the session is being recorded:    if (rec != null) {      rec.writeShortBE(copyRectSrcX);      rec.writeShortBE(copyRectSrcY);    }  }  //  // Read a ServerCutText message  //  String readServerCutText() throws IOException {    byte[] pad = new byte[3];    readFully(pad);    int len = is.readInt();    byte[] text = new byte[len];    readFully(text);    return new String(text);  }  //  // Read an integer in compact representation (1..3 bytes).  // Such format is used as a part of the Tight encoding.  // Also, this method records data if session recording is active and  // the viewer's recordFromBeginning variable is set to true.  //  int readCompactLen() throws IOException {    int[] portion = new int[3];    portion[0] = is.readUnsignedByte();    int byteCount = 1;    int len = portion[0] & 0x7F;    if ((portion[0] & 0x80) != 0) {      portion[1] = is.readUnsignedByte();      byteCount++;      len |= (portion[1] & 0x7F) << 7;      if ((portion[1] & 0x80) != 0) {	portion[2] = is.readUnsignedByte();	byteCount++;	len |= (portion[2] & 0xFF) << 14;      }    }    if (rec != null && recordFromBeginning)      for (int i = 0; i < byteCount; i++)	rec.writeByte(portion[i]);    return len;  }  //  // Write a FramebufferUpdateRequest message  //  void writeFramebufferUpdateRequest(int x, int y, int w, int h,				     boolean incremental)       throws IOException  {    byte[] b = new byte[10];    b[0] = (byte) FramebufferUpdateRequest;    b[1] = (byte) (incremental ? 1 : 0);    b[2] = (byte) ((x >> 8) & 0xff);    b[3] = (byte) (x & 0xff);    b[4] = (byte) ((y >> 8) & 0xff);    b[5] = (byte) (y & 0xff);    b[6] = (byte) ((w >> 8) & 0xff);    b[7] = (byte) (w & 0xff);    b[8] = (byte) ((h >> 8) & 0xff);    b[9] = (byte) (h & 0xff);    os.write(b);  }  //  // Write a SetPixelFormat message  //  void writeSetPixelFormat(int bitsPerPixel, int depth, boolean bigEndian,			   boolean trueColour,			   int redMax, int greenMax, int blueMax,			   int redShift, int greenShift, int blueShift)       throws IOException  {    byte[] b = new byte[20];    b[0]  = (byte) SetPixelFormat;    b[4]  = (byte) bitsPerPixel;    b[5]  = (byte) depth;    b[6]  = (byte) (bigEndian ? 1 : 0);    b[7]  = (byte) (trueColour ? 1 : 0);    b[8]  = (byte) ((redMax >> 8) & 0xff);    b[9]  = (byte) (redMax & 0xff);    b[10] = (byte) ((greenMax >> 8) & 0xff);    b[11] = (byte) (greenMax & 0xff);    b[12] = (byte) ((blueMax >> 8) & 0xff);    b[13] = (byte) (blueMax & 0xff);    b[14] = (byte) redShift;

⌨️ 快捷键说明

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