📄 rdp.java
字号:
// len_directory);
} else {
data.setLittleEndian16(0); // out_uint16_le(s, 0);
}
data.setLittleEndian16(2); // out_uint16_le(s, 2);
data.setLittleEndian16(len_ip + 2); // out_uint16_le(s, len_ip + 2);
// // Length of client ip
data.outUnicodeString("127.0.0.1", len_ip); // rdp_out_unistr(s,
// "127.0.0.1",
// len_ip);
data.setLittleEndian16(len_dll + 2); // out_uint16_le(s, len_dll
// + 2);
data.outUnicodeString("C:\\WINNT\\System32\\mstscax.dll", len_dll); // rdp_out_unistr(s,
// "C:\\WINNT\\System32\\mstscax.dll",
// len_dll);
data.setLittleEndian16(0xffc4); // out_uint16_le(s, 0xffc4);
data.setLittleEndian16(0xffff); // out_uint16_le(s, 0xffff);
data.outUnicodeString("GTB, normaltid", 2 * "GTB, normaltid"
.length()); // rdp_out_unistr(s, "GTB, normaltid", 2 *
// strlen("GTB, normaltid"));
data.incrementPosition(62 - 2 * "GTB, normaltid".length()); // out_uint8s(s,
// 62 -
// 2 *
// strlen("GTB,
// normaltid"));
data.setLittleEndian32(0x0a0000); // out_uint32_le(s, 0x0a0000);
data.setLittleEndian32(0x050000); // out_uint32_le(s, 0x050000);
data.setLittleEndian32(3); // out_uint32_le(s, 3);
data.setLittleEndian32(0); // out_uint32_le(s, 0);
data.setLittleEndian32(0); // out_uint32_le(s, 0);
data.outUnicodeString("GTB, sommartid", 2 * "GTB, sommartid"
.length()); // rdp_out_unistr(s, "GTB, sommartid", 2 *
// strlen("GTB, sommartid"));
data.incrementPosition(62 - 2 * "GTB, sommartid".length()); // out_uint8s(s,
// 62 -
// 2 *
// strlen("GTB,
// sommartid"));
data.setLittleEndian32(0x30000); // out_uint32_le(s, 0x30000);
data.setLittleEndian32(0x050000); // out_uint32_le(s, 0x050000);
data.setLittleEndian32(2); // out_uint32_le(s, 2);
data.setLittleEndian32(0); // out_uint32(s, 0);
data.setLittleEndian32(0xffffffc4); // out_uint32_le(s, 0xffffffc4);
data.setLittleEndian32(0xfffffffe); // out_uint32_le(s, 0xfffffffe);
data.setLittleEndian32(Options.rdp5_performanceflags); // out_uint32_le(s,
// 0x0f);
data.setLittleEndian32(0); // out_uint32(s, 0);
}
data.markEnd();
byte[] buffer = new byte[data.getEnd()];
data.copyToByteArray(buffer, 0, 0, data.getEnd());
SecureLayer.send(data, sec_flags);
}
/**
* Process an activation demand from the server (received between licence negotiation and 1st order)
* @param data Packet containing demand at current read position
* @throws RdesktopException
* @throws IOException
* @throws CryptoException
* @throws OrderException
*/
private void processDemandActive(RdpPacket_Localised data)
throws RdesktopException, IOException, CryptoException,
OrderException {
int type[] = new int[1];
this.rdp_shareid = data.getLittleEndian32();
this.sendConfirmActive();
this.sendSynchronize();
this.sendControl(RDP_CTL_COOPERATE);
this.sendControl(RDP_CTL_REQUEST_CONTROL);
this.receive(type); // Receive RDP_PDU_SYNCHRONIZE
this.receive(type); // Receive RDP_CTL_COOPERATE
this.receive(type); // Receive RDP_CTL_GRANT_CONTROL
this.sendInput(0, RDP_INPUT_SYNCHRONIZE, 0, 0, 0);
this.sendFonts(1);
this.sendFonts(2);
this.receive(type); // Receive an unknown PDU Code = 0x28
this.orders.resetOrderState();
}
/**
* Process a data PDU received from the server
* @param data Packet containing data PDU at current read position
* @param ext_disc_reason If a disconnect PDU is received, stores disconnection reason at ext_disc_reason[0]
* @return True if disconnect PDU was received
* @throws RdesktopException
* @throws OrderException
*/
private boolean processData(RdpPacket_Localised data, int[] ext_disc_reason)
throws RdesktopException, OrderException {
int data_type, ctype, clen, len, roff, rlen;
data_type = 0;
data.incrementPosition(6); // skip shareid, pad, streamid
len = data.getLittleEndian16();
data_type = data.get8();
ctype = data.get8(); // compression type
clen = data.getLittleEndian16(); // compression length
clen -= 18;
switch (data_type) {
case (Rdp.RDP_DATA_PDU_UPDATE):
logger.debug("Rdp.RDP_DATA_PDU_UPDATE");
this.processUpdate(data);
break;
case RDP_DATA_PDU_CONTROL:
logger.debug(("Received Control PDU\n"));
break;
case RDP_DATA_PDU_SYNCHRONISE:
logger.debug(("Received Sync PDU\n"));
break;
case (Rdp.RDP_DATA_PDU_POINTER):
logger.debug("Received pointer PDU");
this.processPointer(data);
break;
case (Rdp.RDP_DATA_PDU_BELL):
logger.debug("Received bell PDU");
Toolkit tx = Toolkit.getDefaultToolkit();
tx.beep();
break;
case (Rdp.RDP_DATA_PDU_LOGON):
logger.debug("User logged on");
Rdesktop.loggedon = true;
break;
case RDP_DATA_PDU_DISCONNECT:
/*
* Normally received when user logs out or disconnects from a
* console session on Windows XP and 2003 Server
*/
ext_disc_reason[0] = processDisconnectPdu(data);
logger.debug(("Received disconnect PDU\n"));
return true;
default:
logger.warn("Unimplemented Data PDU type " + data_type);
}
return false;
}
private void processUpdate(RdpPacket_Localised data) throws OrderException,
RdesktopException {
int update_type = 0;
update_type = data.getLittleEndian16();
switch (update_type) {
case (Rdp.RDP_UPDATE_ORDERS):
data.incrementPosition(2); // pad
int n_orders = data.getLittleEndian16();
data.incrementPosition(2); // pad
this.orders.processOrders(data, next_packet, n_orders);
break;
case (Rdp.RDP_UPDATE_BITMAP):
this.processBitmapUpdates(data);
break;
case (Rdp.RDP_UPDATE_PALETTE):
this.processPalette(data);
break;
case (Rdp.RDP_UPDATE_SYNCHRONIZE):
break;
default:
logger.warn("Unimplemented Update type " + update_type);
}
}
private void sendConfirmActive() throws RdesktopException, IOException,
CryptoException {
int caplen = RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER
+ RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE
+ RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER
+ RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN + 4; // this is a fix
// for W2k.
// Purpose
// unknown
int sec_flags = Options.encryption ? (RDP5_FLAG | Secure.SEC_ENCRYPT)
: RDP5_FLAG;
RdpPacket_Localised data = SecureLayer.init(sec_flags, 6 + 14 + caplen
+ RDP_SOURCE.length);
// RdpPacket_Localised data = this.init(14 + caplen +
// RDP_SOURCE.length);
data.setLittleEndian16(2 + 14 + caplen + RDP_SOURCE.length);
data.setLittleEndian16((RDP_PDU_CONFIRM_ACTIVE | 0x10));
data.setLittleEndian16(Common.mcs.getUserID() /* McsUserID() */+ 1001);
data.setLittleEndian32(this.rdp_shareid);
data.setLittleEndian16(0x3ea); // user id
data.setLittleEndian16(RDP_SOURCE.length);
data.setLittleEndian16(caplen);
data.copyFromByteArray(RDP_SOURCE, 0, data.getPosition(),
RDP_SOURCE.length);
data.incrementPosition(RDP_SOURCE.length);
data.setLittleEndian16(0xd); // num_caps
data.incrementPosition(2); // pad
this.sendGeneralCaps(data);
// ta.incrementPosition(this.RDP_CAPLEN_GENERAL);
this.sendBitmapCaps(data);
this.sendOrderCaps(data);
if (Options.use_rdp5 && Options.persistent_bitmap_caching) {
logger.info("Persistent caching enabled");
this.sendBitmapcache2Caps(data);
} else
this.sendBitmapcacheCaps(data);
this.sendColorcacheCaps(data);
this.sendActivateCaps(data);
this.sendControlCaps(data);
this.sendPointerCaps(data);
this.sendShareCaps(data);
// this.sendUnknownCaps(data);
this.sendUnknownCaps(data, 0x0d, 0x58, caps_0x0d); // rdp_out_unknown_caps(s,
// 0x0d, 0x58,
// caps_0x0d); /*
// international? */
this.sendUnknownCaps(data, 0x0c, 0x08, caps_0x0c); // rdp_out_unknown_caps(s,
// 0x0c, 0x08,
// caps_0x0c);
this.sendUnknownCaps(data, 0x0e, 0x08, caps_0x0e); // rdp_out_unknown_caps(s,
// 0x0e, 0x08,
// caps_0x0e);
this.sendUnknownCaps(data, 0x10, 0x34, caps_0x10); // rdp_out_unknown_caps(s,
// 0x10, 0x34,
// caps_0x10); /*
// glyph cache? */
data.markEnd();
logger.debug("confirm active");
// this.send(data, RDP_PDU_CONFIRM_ACTIVE);
Common.secure.send(data, sec_flags);
}
private void sendGeneralCaps(RdpPacket_Localised data) {
data.setLittleEndian16(RDP_CAPSET_GENERAL);
data.setLittleEndian16(RDP_CAPLEN_GENERAL);
data.setLittleEndian16(1); /* OS major type */
data.setLittleEndian16(3); /* OS minor type */
data.setLittleEndian16(0x200); /* Protocol version */
data.setLittleEndian16(Options.use_rdp5 ? 0x40d : 0);
// data.setLittleEndian16(Options.use_rdp5 ? 0x1d04 : 0); // this seems
/*
* Pad, according to T.128. 0x40d seems to trigger the server to start
* sending RDP5 packets. However, the value is 0x1d04 with W2KTSK and
* NT4MS. Hmm.. Anyway, thankyou, Microsoft, for sending such
* information in a padding field..
*/
data.setLittleEndian16(0); /* Compression types */
data.setLittleEndian16(0); /* Pad */
data.setLittleEndian16(0); /* Update capability */
data.setLittleEndian16(0); /* Remote unshare capability */
data.setLittleEndian16(0); /* Compression level */
data.setLittleEndian16(0); /* Pad */
}
private void sendBitmapCaps(RdpPacket_Localised data) {
data.setLittleEndian16(RDP_CAPSET_BITMAP);
data.setLittleEndian16(RDP_CAPLEN_BITMAP);
data.setLittleEndian16(Options.server_bpp); /* Preferred BPP */
data.setLittleEndian16(1); /* Receive 1 BPP */
data.setLittleEndian16(1); /* Receive 4 BPP */
data.setLittleEndian16(1); /* Receive 8 BPP */
data.setLittleEndian16(Options.width); /* Desktop width */
data.setLittleEndian16(Options.height); /* Desktop height */
data.setLittleEndian16(0); /* Pad */
data.setLittleEndian16(1); /* Allow resize */
data.setLittleEndian16(Options.bitmap_compression ? 1 : 0); /*
* Support
* compression
*/
data.setLittleEndian16(0); /* Unknown */
data.setLittleEndian16(1); /* Unknown */
data.setLittleEndian16(0); /* Pad */
}
private void sendOrderCaps(RdpPacket_Localised data) {
byte[] order_caps = new byte[32];
order_caps[0] = 1; /* dest blt */
order_caps[1] = 1; /* pat blt */// nb no rectangle orders if this is 0
order_caps[2] = 1; /* screen blt */
order_caps[3] = (byte) (Options.bitmap_caching ? 1 : 0); /* memblt */
order_caps[4] = 0; /* triblt */
order_caps[8] = 1; /* line */
order_caps[9] = 1; /* line */
order_caps[10] = 1; /* rect */
order_caps[11] = (Constants.desktop_save ? 1 : 0); /* desksave */
order_caps[13] = 1; /* memblt */
order_caps[14] = 1; /* triblt */
order_caps[20] = (byte) (Options.polygon_ellipse_orders ? 1 : 0); /* polygon */
order_caps[21] = (byte) (Options.polygon_ellipse_orders ? 1 : 0); /* polygon2 */
order_caps[22] = 1; /* polyline */
order_caps[25] = (byte) (Options.polygon_ellipse_orders ? 1 : 0); /* ellipse */
order_caps[26] = (byte) (Options.polygon_ellipse_orders ? 1 : 0); /* ellipse2 */
order_caps[27] = 1; /* text2 */
data.setLittleEndian16(RDP_CAPSET_ORDER);
data.setLittleEndian16(RDP_CAPLEN_ORDER);
data.incrementPosition(20); /* Terminal desc, pad */
data.setLittleEndian16(1); /* Cache X granularity */
data.setLittleEndian16(20); /* Cache Y granularity */
data.setLittleEndian16(0); /* Pad */
data.setLittleEndian16(1); /* Max order level */
data.setLittleEndian16(0x147); /* Number of fonts */
data.setLittleEndian16(0x2a); /* Capability flags */
data.copyFromByteArray(order_caps, 0, data.getPosition(), 32); /*
* Orders
* supported
*/
data.incrementPosition(32);
data.setLittleEndian16(0x6a1); /* Text capability flags */
data.incrementPosition(6); /* Pad */
data.setLittleEndian32(Constants.desktop_save ? 0x38400 : 0); /*
* Desktop
* cache
* size
*/
data.setLittleEndian32(0); /* Unknown */
data.setLittleEndian32(0x4e4); /* Unknown */
}
private void sendBitmapcacheCaps(RdpPacket_Localised data) {
data.setLittleEndian16(RDP_CAPSET_BMPCACHE);
data.setLittleEndian16(RDP_CAPLEN_BMPCACHE);
data.incrementPosition(24); /* unused */
data.setLittleEndian16(0x258); /* entries */
data.setLittleEndian16(0x100); /* max cell size */
data.setLittleEndian16(0x12c); /* entries */
data.setLittleEndian16(0x400); /* max cell size */
data.setLittleEndian16(0x106); /* entries */
data.setLittleEndian16(0x1000); /* max cell size */
}
/* Output bitmap cache v2 capability set */
private void sendBitmapcache2Caps(RdpPacket_Localised data) {
data.setLittleEndian16(RDP_CAPSET_BMPCACHE2); // out_uint16_le(s,
// RDP_CAPSET_BMPCACHE2);
data.setLittleEndian16(RDP_CAPLEN_BMPCACHE2); // out_uint16_le(s,
// RDP_CAPLEN_BMPCACHE2);
data.setLittleEndian16(Options.persistent_bitmap_caching ? 2 : 0); /* version */
data.setBigEndian16(3); /* number of caches in this set */
/* max cell size for cache 0 is 16x16, 1 = 32x32, 2 = 64x64, etc */
data.setLittleEndian32(BMPCACHE2_C0_CELLS); // out_uint32_le(s,
// BMPCACHE2_C0_CELLS);
data.setLittleEndian32(BMPCACHE2_C1_CELLS); // out_uint32_le(s,
// BMPCACHE2_C1_CELLS);
// data.setLittleEndian32(PstCache.pstcache_init(2) ?
// (BMPCACHE2_NUM_PSTCELLS | BMPCACHE2_FLAG_PERSIST) :
// BMPCACHE2_C2_CELLS);
if (PstCache.pstcache_init(2)) {
logger.info("Persistent cache initialized");
data.setLittleEndian32(BMPCACHE2_NUM_PSTCELLS
| BMPCACHE2_FLAG_PERSIST);
} else {
logger.info("Persistent cache not initialized");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -