Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to edition 2021 and dependencies upgrade #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = ["rdp", "security", "network", "windows"]
categories = ["network"]
license = "MIT"
documentation = "https://docs.rs/rdp-rs"
edition = "2021"

[lib]
name = "rdp"
Expand All @@ -27,17 +28,17 @@ mstsc-rs = ["hex", "winapi", "minifb", "clap", "libc"]

[dependencies]
native-tls = "^0.2"
byteorder = "^1.3"
byteorder = "^1.4"
bufstream = "0.1"
indexmap = "^1.3"
yasna = { version = "^0.3" }
md4 = "^0.8"
hmac = "^0.7"
md-5 = "^0.8"
rand = "^0.7"
num-bigint = "^0.2"
x509-parser = "0.6.5"
num_enum = "0.4.3"
indexmap = "^1.8"
yasna = { version = "^0.5" }
md4 = "^0.10"
hmac = "^0.12"
md-5 = "^0.10"
rand = "^0.8"
num-bigint = "^0.4"
x509-parser = "0.13"
num_enum = "0.5"

# for mtsc-rs
hex = { version = "^0.4", optional = true }
Expand Down
10 changes: 0 additions & 10 deletions src/bin/mstsc-rs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(any(target_os = "linux", target_os = "macos"))]
extern crate libc;
extern crate minifb;
extern crate rdp;
extern crate hex;
extern crate clap;
extern crate hmac;

use minifb::{Key, Window, WindowOptions, MouseMode, MouseButton, KeyRepeat};
use std::net::{SocketAddr, TcpStream};
use std::io::{Read, Write};
Expand Down
16 changes: 8 additions & 8 deletions src/codec/rle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use std::io::{Cursor, Read};
use byteorder::{ReadBytesExt, LittleEndian};

Expand Down Expand Up @@ -31,7 +31,7 @@ fn process_plane(input: &mut dyn Read, width: u32, height: u32, output: &mut [u8
replen = code & 0xf;
collen = (code >> 4) & 0xf;
revcode = (replen << 4) | collen;
if (revcode <= 47) && (revcode >= 16) {
if (16..=47).contains(&revcode) {
replen = revcode;
collen = 0;
}
Expand All @@ -57,20 +57,20 @@ fn process_plane(input: &mut dyn Read, width: u32, height: u32, output: &mut [u8
replen = code & 0xf;
collen = (code >> 4) & 0xf;
revcode = (replen << 4) | collen;
if (revcode <= 47) && (revcode >= 16) {
if (16..=47).contains(&revcode) {
replen = revcode;
collen = 0;
}
while collen > 0 {
x = input.read_u8()?;
if x & 1 != 0{
x = x >> 1;
x = x + 1;
x >>= 1;
x += 1;
color = -(x as i32) as i8;
}
else
{
x = x >> 1;
x >>= 1;
color = x as i8;
}
x = (output[(last_line + (indexw * 4)) as usize] as i32 + color as i32) as u8;
Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn rle_16_decompress(input: &[u8], width: usize, mut height: usize, output:

while count > 0 {
if x >= width {
if height <= 0 {
if height == 0 {
return Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidData, "error during decompress")))
}
x = 0;
Expand Down Expand Up @@ -331,7 +331,7 @@ pub fn rle_16_decompress(input: &[u8], width: usize, mut height: usize, output:


pub fn rgb565torgb32(input: &[u16], width: usize, height: usize) -> Vec<u8> {
let mut result_32_bpp = vec![0 as u8; width as usize * height as usize * 4];
let mut result_32_bpp = vec![0_u8; width as usize * height as usize * 4];
for i in 0..height {
for j in 0..width {
let index = (i * width + j) as usize;
Expand Down
20 changes: 10 additions & 10 deletions src/core/capability.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use model::data::{Component, U16, U32, DynOption, MessageOption, Message, DataType, Check, Trame, to_vec};
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::data::{Component, U16, U32, DynOption, MessageOption, Message, DataType, Check, Trame, to_vec};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use std::io::Cursor;
use core::gcc::{KeyboardLayout, KeyboardType};
use crate::core::gcc::{KeyboardLayout, KeyboardType};
use num_enum::TryFromPrimitive;
use std::convert::TryFrom;

Expand Down Expand Up @@ -187,8 +187,8 @@ pub fn ts_general_capability_set(extra_flags: Option<u16>) -> Capability {
"updateCapabilityFlag" => Check::new(U16::LE(0)),
"remoteUnshareFlag" => Check::new(U16::LE(0)),
"generalCompressionLevel" => Check::new(U16::LE(0)),
"refreshRectSupport" => 0 as u8,
"suppressOutputSupport" => 0 as u8
"refreshRectSupport" => 0_u8,
"suppressOutputSupport" => 0_u8
]
}
}
Expand Down Expand Up @@ -219,8 +219,8 @@ pub fn ts_bitmap_capability_set(preferred_bits_per_pixel: Option<u16>, desktop_w
"pad2octets" => U16::LE(0),
"desktopResizeFlag" => U16::LE(0),
"bitmapCompressionFlag" => Check::new(U16::LE(0x0001)),
"highColorFlags" => Check::new(0 as u8),
"drawingFlags" => 0 as u8,
"highColorFlags" => Check::new(0_u8),
"drawingFlags" => 0_u8,
"multipleRectangleSupport" => Check::new(U16::LE(0x0001)),
"pad2octetsB" => U16::LE(0)
]
Expand Down Expand Up @@ -253,15 +253,15 @@ pub fn ts_order_capability_set(order_flags: Option<u16>) -> Capability {
Capability {
cap_type: CapabilitySetType::CapstypeOrder,
message: component![
"terminalDescriptor" => vec![0 as u8; 16],
"terminalDescriptor" => vec![0_u8; 16],
"pad4octetsA" => U32::LE(0),
"desktopSaveXGranularity" => U16::LE(1),
"desktopSaveYGranularity" => U16::LE(20),
"pad2octetsA" => U16::LE(0),
"maximumOrderLevel" => U16::LE(1),
"numberFonts" => U16::LE(0),
"orderFlags" => U16::LE(order_flags.unwrap_or(OrderFlag::NEGOTIATEORDERSUPPORT as u16)),
"orderSupport" => vec![0 as u8; 32],
"orderSupport" => vec![0_u8; 32],
"textFlags" => U16::LE(0),
"orderSupportExFlags" => U16::LE(0),
"pad4octetsB" => U32::LE(0),
Expand Down Expand Up @@ -375,7 +375,7 @@ pub fn ts_input_capability_set(input_flags: Option<u16>, keyboard_layout: Option
"keyboardType" => U32::LE(KeyboardType::Ibm101102Keys as u32),
"keyboardSubType" => U32::LE(0),
"keyboardFunctionKey" => U32::LE(12),
"imeFileName" => vec![0 as u8; 64]
"imeFileName" => vec![0_u8; 64]
]
}
}
Expand Down
28 changes: 17 additions & 11 deletions src/core/client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use core::x224;
use core::gcc::KeyboardLayout;
use core::mcs;
use core::tpkt;
use core::sec;
use core::global;
use crate::core::x224;
use crate::core::gcc::KeyboardLayout;
use crate::core::mcs;
use crate::core::tpkt;
use crate::core::sec;
use crate::core::global;
use std::io::{Read, Write};
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use model::link::{Link, Stream};
use core::event::{RdpEvent, PointerButton};
use core::global::{ts_pointer_event, PointerFlag, ts_keyboard_event, KeyboardFlag};
use nla::ntlm::Ntlm;
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::link::{Link, Stream};
use crate::core::event::{RdpEvent, PointerButton};
use crate::core::global::{ts_pointer_event, PointerFlag, ts_keyboard_event, KeyboardFlag};
use crate::nla::ntlm::Ntlm;

impl From<&str> for KeyboardLayout {
fn from(e: &str) -> Self {
Expand Down Expand Up @@ -348,4 +348,10 @@ impl Connector {
self.use_nla = use_nla;
self
}
}

impl Default for Connector {
fn default() -> Self {
Self::new()
}
}
10 changes: 5 additions & 5 deletions src/core/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use num_enum::TryFromPrimitive;
use codec::rle::{rle_32_decompress, rle_16_decompress, rgb565torgb32};
use crate::codec::rle::{rle_32_decompress, rle_16_decompress, rgb565torgb32};

/// A bitmap event is used
/// to notify client that it received
Expand Down Expand Up @@ -67,7 +67,7 @@ impl BitmapEvent {
// 32 bpp is straight forward
Ok(
if self.is_compress {
let mut result = vec![0 as u8; self.width as usize * self.height as usize * 4];
let mut result = vec![0_u8; self.width as usize * self.height as usize * 4];
rle_32_decompress(&self.data, self.width as u32, self.height as u32, &mut result)?;
result
} else {
Expand All @@ -78,11 +78,11 @@ impl BitmapEvent {
16 => {
// 16 bpp is more consumer
let result_16bpp = if self.is_compress {
let mut result = vec![0 as u16; self.width as usize * self.height as usize * 2];
let mut result = vec![0_u16; self.width as usize * self.height as usize * 2];
rle_16_decompress(&self.data, self.width as usize, self.height as usize, &mut result)?;
result
} else {
let mut result = vec![0 as u16; self.width as usize * self.height as usize];
let mut result = vec![0_u16; self.width as usize * self.height as usize];
for i in 0..self.height {
for j in 0..self.width {
let src = (((self.height - i - 1) * self.width + j) * 2) as usize;
Expand Down
22 changes: 11 additions & 11 deletions src/core/gcc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use model::data::{Component, U32, U16, Trame, to_vec, Message, DataType, DynOption, MessageOption, Check, Array};
use model::unicode::Unicode;
use model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use core::per;
use crate::model::data::{Component, U32, U16, Trame, to_vec, Message, DataType, DynOption, MessageOption, Check, Array};
use crate::model::unicode::Unicode;
use crate::model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use crate::core::per;
use std::io::{Cursor, Read};
use std::collections::HashMap;

Expand Down Expand Up @@ -223,11 +223,11 @@ pub fn client_core_data(parameter: Option<ClientData>) -> Component {
"sasSequence" => U16::LE(Sequence::RnsUdSasDel as u16),
"kbdLayout" => U32::LE(client_parameter.layout as u32),
"clientBuild" => U32::LE(3790),
"clientName" => client_name.to_string().to_unicode(),
"clientName" => client_name.to_unicode(),
"keyboardType" => U32::LE(KeyboardType::Ibm101102Keys as u32),
"keyboardSubType" => U32::LE(0),
"keyboardFnKeys" => U32::LE(12),
"imeFileName" => vec![0 as u8; 64],
"imeFileName" => vec![0_u8; 64],
"postBeta2ColorDepth" => U16::LE(ColorDepth::RnsUdColor8BPP as u16),
"clientProductId" => U16::LE(1),
"serialNumber" => U32::LE(0),
Expand All @@ -240,8 +240,8 @@ pub fn client_core_data(parameter: Option<ClientData>) -> Component {
),
"earlyCapabilityFlags" => U16::LE(CapabilityFlag::RnsUdCsSupportErrinfoPDU as u16),
"clientDigProductId" => vec![0; 64],
"connectionType" => 0 as u8,
"pad1octet" => 0 as u8,
"connectionType" => 0_u8,
"pad1octet" => 0_u8,
"serverSelectedProtocol" => U32::LE(client_parameter.server_selected_protocol)
]
}
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn server_security_data() -> Component {
}

/// Actually we have no more classic channel
pub fn channel_def(name: &String, options: u32) -> Component {
pub fn channel_def(name: &str, options: u32) -> Component {
component![
"name"=> name.as_bytes().to_vec(),
"options" => U32::LE(options)
Expand Down Expand Up @@ -352,7 +352,7 @@ pub fn read_conference_create_response(cc_response: &mut dyn Read) -> RdpResult<
break;
}

let mut buffer = vec![0 as u8; (cast!(DataType::U16, header["length"])? - header.length() as u16) as usize];
let mut buffer = vec![0_u8; (cast!(DataType::U16, header["length"])? - header.length() as u16) as usize];
sub.read_exact(&mut buffer)?;

match MessageType::from(cast!(DataType::U16, header["type"])?) {
Expand All @@ -377,7 +377,7 @@ pub fn read_conference_create_response(cc_response: &mut dyn Read) -> RdpResult<

// All section are important
Ok(ServerData{
channel_ids: cast!(DataType::Trame, result[&MessageType::ScNet]["channelIdArray"])?.into_iter().map(|x| cast!(DataType::U16, x).unwrap()).collect(),
channel_ids: cast!(DataType::Trame, result[&MessageType::ScNet]["channelIdArray"])?.iter().map(|x| cast!(DataType::U16, x).unwrap()).collect(),
rdp_version: Version::from(cast!(DataType::U32, result[&MessageType::ScCore]["rdpVersion"])?)
})
}
Loading