/// <summary> /// Create new C file access /// </summary> public CFile(Stream stream, Encoding encoding = null) { this._Stream = stream; EOF = _Stream == null; this._Encoding = encoding ?? Encoding.GetEncoding("Windows-1252"); this._Decoder = _Encoding.GetDecoder(); }
public void run() { Debug.Log("Starting Thread"); running = true; try { Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse("127.0.0.1"); System.Net.IPEndPoint remoteEP = new IPEndPoint(ipAdd, 1111); //soc.ReceiveTimeout = 5000; //soc.SendTimeout = 5000; soc.Connect(remoteEP); soc.Send(System.Text.Encoding.ASCII.GetBytes("Output\n")); while (running) { byte[] buffer = new byte[300000]; int iRx = soc.Receive(buffer); char[] chars = new char[iRx]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(buffer, 0, iRx, chars, 0); System.String recv = new System.String(chars); //Console.WriteLine(recv); //Debug.Log(recv); pos = recv; } soc.Close(); } catch (Exception e) { //Console.WriteLine(e); Debug.Log(e); } }
public HttpRequestStreamReader(Stream stream, Encoding encoding, int bufferSize) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (!stream.CanRead) { throw new ArgumentException(Resources.HttpRequestStreamReader_StreamNotReadable, nameof(stream)); } if (encoding == null) { throw new ArgumentNullException(nameof(encoding)); } _stream = stream; _encoding = encoding; _decoder = encoding.GetDecoder(); if (bufferSize < MinBufferSize) { bufferSize = MinBufferSize; } _byteBufferSize = bufferSize; _byteBuffer = new byte[bufferSize]; var maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); _charBuffer = new char[maxCharsPerBuffer]; }
public static string base64Decode(string sData) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(sData); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch (Exception ex) { throw new Exception("Error in base64Decode" + ex.Message); } }
static StaticUtils() { asciiDecoder = Encoding.ASCII.GetDecoder(); utf8Encoder = Encoding.UTF8.GetEncoder(); utf8Decoder = Encoding.UTF8.GetDecoder(); }
public static Highscore[] GetHighscores() { string path = Application.persistentDataPath + "/Highscores.lwhs"; if (File.Exists(path)) { Stream fs = File.Open(path, FileMode.Open); int count = fs.ReadByte(); if (count == 0) { fs.Close(); return(null); } else { if (count > MAX_HIGHSCORES_COUNT) { count = MAX_HIGHSCORES_COUNT; } var hsa = new Highscore[count]; System.Text.Decoder decoder = System.Text.Encoding.Default.GetDecoder(); for (int i = 0; i < count; i++) { hsa[i] = Load(fs, decoder); } fs.Close(); return(hsa); } } else { return(null); } }
/// <summary> /// Constructs a new binary reader with the given bit converter, reading /// to the given stream, using the given encoding. /// </summary> /// <param name="bitConverter">Converter to use when reading data</param> /// <param name="stream">Stream to read data from</param> /// <param name="encoding">Encoding to use when reading character data</param> public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream, Encoding encoding) { if (bitConverter == null) { throw new ArgumentNullException("bitConverter"); } if (stream == null) { throw new ArgumentNullException("stream"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (!stream.CanRead) { throw new ArgumentException("Stream isn't writable", "stream"); } this.stream = stream; this.bitConverter = bitConverter; this.encoding = encoding; this.decoder = encoding.GetDecoder(); this.minBytesPerChar = 1; if (encoding is UnicodeEncoding) { minBytesPerChar = 2; } }
public EndianReader(Stream input, Endianness endianess, Encoding encoding, bool leaveOpen) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (encoding == null) { throw new ArgumentNullException(nameof(encoding)); } if (!input.CanRead) throw new ArgumentException("Can't read from the output stream", nameof(input)); Contract.EndContractBlock(); BaseStream = input; decoder = encoding.GetDecoder(); maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize); var minBufferSize = encoding.GetMaxByteCount(1); // max bytes per one char if (minBufferSize < 16) minBufferSize = 16; buffer = new byte[minBufferSize]; // m_charBuffer and m_charBytes will be left null. // For Encodings that always use 2 bytes per char (or more), // special case them here to make Read() & Peek() faster. use2BytesPerChar = encoding is UnicodeEncoding; this.leaveOpen = leaveOpen; Endianness = endianess; resolvedEndianess = EndianessHelper.Resolve(endianess); Contract.Assert(decoder != null, "[EndianReader.ctor]m_decoder!=null"); }
public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream, System.Text.Encoding encoding) { this.disposed = false; this.buffer = new byte[0x10]; this.charBuffer = new char[1]; if (bitConverter == null) { throw new ArgumentNullException("bitConverter"); } if (stream == null) { throw new ArgumentNullException("stream"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (!stream.CanRead) { throw new ArgumentException("Stream isn't writable", "stream"); } this.stream = stream; this.bitConverter = bitConverter; this.encoding = encoding; this.decoder = encoding.GetDecoder(); this.minBytesPerChar = 1; if (encoding is UnicodeEncoding) { this.minBytesPerChar = 2; } }
public ContentReader(Stream stream, long length, Encoding encoding = null) { _stream = stream; _length = length; if (encoding != null) { _decoder = encoding.GetDecoder(); } }
static void Main(string[] args) { //第一个参数是第三方平台 //第二个参数是平台账号信息,若此处不设置Account,则需要在策略代码中设置默认值 var decoder = new Decoder(Platform.RuoKuai, new Account { SoftId = 0, // 软件ID(此ID需要注册开发者账号才可获得) TypeId = 0, // 验证码类型(四位字符或其他类型的验证码,根据各平台设置不同值) SoftKey = null, //软件Key (此Key也需要注册开发者账号才可获得) UserName = null, //账号(此账号为打码平台的普通用户账号,开发者账号不能进行图片识别) Password = null //密码 }); decoder.OnStart += (s, e) => { Console.WriteLine("验证码("+e.FilePath+")识别启动……"); }; decoder.OnCompleted += (s, e) => { Console.WriteLine("验证码(" + e.FilePath + ")识别完成:" + e.Code + ",耗时:" + (e.Milliseconds/1000) + "秒,线程ID:"+e.ThreadId); }; decoder.OnError += (s, e) => { Console.WriteLine("验证码识别出错:" + e.Exception.Message); }; for (var i = 1; i <= 3; i++) { decoder.Decode("c:\\checkcode"+i+".png"); } Console.ReadKey(); }
public BinaryReader(Stream input, Encoding encoding, bool leaveOpen) { if (input==null) { throw new ArgumentNullException(nameof(input)); } if (encoding==null) { throw new ArgumentNullException(nameof(encoding)); } if (!input.CanRead) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); Contract.EndContractBlock(); m_stream = input; m_decoder = encoding.GetDecoder(); m_maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize); int minBufferSize = encoding.GetMaxByteCount(1); // max bytes per one char if (minBufferSize < 16) minBufferSize = 16; m_buffer = new byte[minBufferSize]; // m_charBuffer and m_charBytes will be left null. // For Encodings that always use 2 bytes per char (or more), // special case them here to make Read() & Peek() faster. m_2BytesPerChar = encoding is UnicodeEncoding; // check if BinaryReader is based on MemoryStream, and keep this for it's life // we cannot use "as" operator, since derived classes are not allowed m_isMemoryStream = (m_stream.GetType() == typeof(MemoryStream)); m_leaveOpen = leaveOpen; Contract.Assert(m_decoder!=null, "[BinaryReader.ctor]m_decoder!=null"); }
public static Highscore Load(Stream fs, System.Text.Decoder decoder) { const int length = 4; byte[] data = new byte[length]; char[] chars; string name; fs.Read(data, 0, length); var bytesCount = System.BitConverter.ToInt32(data, 0); if (bytesCount > 0 && bytesCount < 100000) { data = new byte[bytesCount]; fs.Read(data, 0, bytesCount); chars = new char[decoder.GetCharCount(data, 0, bytesCount)]; decoder.GetChars(data, 0, bytesCount, chars, 0, true); name = new string(chars); } else { name = "highscore"; } // bytesCount = 9; data = new byte[bytesCount]; fs.Read(data, 0, bytesCount); return(new Highscore(System.BitConverter.ToInt32(data, 0), name, System.BitConverter.ToUInt32(data, 4), (GameEndingType)data[8])); }
public BinaryReader(Stream input, Encoding encoding) { if (input == null) { throw new ArgumentNullException("input"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (!input.CanRead) { throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); } this.m_stream = input; this.m_decoder = encoding.GetDecoder(); this.m_maxCharsSize = encoding.GetMaxCharCount(0x80); int maxByteCount = encoding.GetMaxByteCount(1); if (maxByteCount < 0x10) { maxByteCount = 0x10; } this.m_buffer = new byte[maxByteCount]; this.m_charBuffer = null; this.m_charBytes = null; this.m_2BytesPerChar = encoding is UnicodeEncoding; this.m_isMemoryStream = this.m_stream.GetType() == typeof(MemoryStream); }
void OnDataReceived(IAsyncResult asyn) { try { SocketPacket packet = (SocketPacket)asyn.AsyncState; int end = packet.TCPSocket.EndReceive(asyn); char[] chars = new char[end + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(packet.DataBuffer, 0, end, chars, 0); System.String data = new System.String(chars); ReceiveData(data); WaitForData(); } catch (ObjectDisposedException) { Console.WriteLine("WARNING: Socket closed unexpectedly"); } catch (SocketException se) { if (!_TCPSocket.Connected) { OnDisconnected(se); } } }
/// <summary> /// コンストラクタです。 /// </summary> public XmlParser(Stream stream) { this.stream = stream; this.element = this.name = this.data = ""; this.attr = new Hashtable(); this.dec = Encoding.Default.GetDecoder(); this.letter = false; }
/// <summary> /// Reads an ATTRIBUTEWORD from the byte buffer. /// </summary> /// <param name="buffer">buffer containing serialized data</param> /// <param name="offset">reference to an offset variable; upon entry offset /// reflects the position within the buffer where reading should begin. /// Upon success the offset will be incremented by the number of bytes that are used.</param> /// <param name="coder">Decoder used to translate byte data to character data</param> /// <returns>an ATTRIBUTEWORD value taken from the buffer</returns> public static string ReadATTRIBUTEWORD(byte[] buffer, ref int offset, Decoder coder) { #if DEBUG if (buffer == null) throw new ArgumentNullException("buffer"); if (offset < 0 || offset > buffer.Length - 1) throw new BadLwesDataException(String.Concat("Expected ATTRIBUTEWORD at offset ", offset)); #endif return ReadStringWithByteLengthPrefix(buffer, ref offset, coder); }
public PositionedStreamReader(Stream stream, Encoding encoding) { this.stream = stream; this.encoding = encoding; decoder = encoding.GetDecoder(); bufferpos = 0; readPosition = 0; }
public UTF8SanitizerStream(string pattern, string substitute, Stream output) { _pattern = pattern; _substitute = substitute; _output = output; _decoder = Encoding.UTF8.GetDecoder(); _buffer = String.Empty; }
//bool disposed; public RequestState() { BufferRead = new byte[BufferSize]; RequestData = new StringBuilder(String.Empty); Request = null; ResponseStream = null; StreamDecode = Encoding.UTF8.GetDecoder(); }
/// <summary> /// Unpacks next section of the compressed replay /// </summary> /// <param name="length">The length of the section</param> /// <returns>The decoded data</returns> protected byte[] UnpackNextSection(int length) { byte[] result = new byte[length]; Decoder decoder = new Decoder(); DecodeBuffer buffer = new DecodeBuffer(result); decoder.DecodeBuffer = buffer; int checksum = _reader.ReadInt32(); int blocks = _reader.ReadInt32(); for (int block = 0; block < blocks; block++) { // read the length of the next block of encoded data int encodedLength = _reader.ReadInt32(); // we error if there is no space for the next block of encoded data if (encodedLength > result.Length - buffer.ResultOffset) { throw new Exception("Insufficient space in decode buffer"); } // read the block of encoded data into the result (decoded data will overwrite). _reader.Read(result, buffer.ResultOffset, encodedLength); // skip decoding if the encoded data filled the remaining space if (encodedLength == Math.Min(result.Length - buffer.ResultOffset, buffer.BufferLength)) { continue; } // set the decode buffer parameters buffer.EncodedOffset = 0; buffer.DecodedLength = 0; buffer.EncodedLength = encodedLength; // decode the block if (decoder.DecodeBlock() != 0) { throw new Exception("Error decoding block offset " + block); } // sanity check the decoded length if (buffer.DecodedLength == 0 || buffer.DecodedLength > buffer.BufferLength || buffer.DecodedLength > result.Length) { throw new Exception("Decode data length mismatch"); } // flush the decoded bytes into the result buffer.WriteDecodedBytes(); } return result; }
public CancellableStreamReader(Stream stream, Encoding encoding) { _stream = stream; _decoder = encoding.GetDecoder(); _byteBuffer = new byte[BufferLength]; _buffer = new char[encoding.GetMaxCharCount(BufferLength)]; _bufferedLength = -1; _bufferCursor = -1; }
TextSource(Encoding encoding) { _buffer = new Byte[BufferSize]; _chars = new Char[BufferSize + 1]; _raw = new MemoryStream(); _index = 0; _encoding = encoding ?? TextEncoding.Utf8; _decoder = _encoding.GetDecoder(); }
public AsyncTextReader(IAsyncDataSource dataSource, Encoding encoding, int bufferSize = DefaultBufferSize) : base() { _DataSource = dataSource; _Encoding = encoding; _Decoder = _Encoding.GetDecoder(); _BufferSize = Math.Max(MinimumBufferSize, bufferSize); AllocateBuffer(); }
public AsyncLineReader(Stream stream, Encoding encoding, int bufferSize, int maxLineLength) { this.stream = stream; this.decoder = encoding.GetDecoder(); this.readBuffer = new byte[bufferSize]; this.decodeBuffer = new char[bufferSize]; this.maxLineLength = maxLineLength; StartRead(); }
public static Highscore[] GetHighscores() { string path = Application.persistentDataPath + "/Highscores.lwhs"; if (File.Exists(path)) { FileStream fs = File.Open(path, FileMode.Open); int count = fs.ReadByte(); if (count == 0) { fs.Close(); return(null); } else { if (count > MAX_HIGHSCORES_COUNT) { count = MAX_HIGHSCORES_COUNT; } var hsa = new Highscore[count]; string name = "highscore"; var data = new byte[4]; System.Text.Decoder decoder = System.Text.Encoding.Default.GetDecoder(); char[] chars; int bytesCount = 0; for (int i = 0; i < count; i++) { fs.Read(data, 0, 4); bytesCount = System.BitConverter.ToInt32(data, 0); if (bytesCount > 0 && bytesCount < 100000) { data = new byte[bytesCount]; fs.Read(data, 0, bytesCount); chars = new char[decoder.GetCharCount(data, 0, bytesCount)]; decoder.GetChars(data, 0, bytesCount, chars, 0, true); name = new string(chars); } else { name = "highscore"; } // bytesCount = 9; data = new byte[bytesCount]; fs.Read(data, 0, bytesCount); hsa[i] = new Highscore(name, System.BitConverter.ToUInt64(data, 0), (GameEndingType)data[bytesCount - 1]); } fs.Close(); return(hsa); } } else { return(null); } }
public void Load(System.IO.FileStream fs) { int LENGTH = 47; var data = new byte[LENGTH]; fs.Read(data, 0, LENGTH); ID = System.BitConverter.ToInt32(data, 0); atHome = data[4] == 1; membersCount = data[5]; if (data[6] == 2) { chanceMod = null; } else { chanceMod = data[6] == 1; } persistence = data[7]; survivalSkills = data[8]; secretKnowledge = data[9]; perception = data[10]; intelligence = data[11]; techSkills = data[12]; freePoints = data[13]; level = data[14]; RecalculatePath(); stamina = System.BitConverter.ToSingle(data, 15); confidence = System.BitConverter.ToSingle(data, 19); unity = System.BitConverter.ToSingle(data, 23); loyalty = System.BitConverter.ToSingle(data, 27); adaptability = System.BitConverter.ToSingle(data, 31); experience = System.BitConverter.ToInt32(data, 35); missionsParticipated = System.BitConverter.ToUInt16(data, 39); missionsSuccessed = System.BitConverter.ToUInt16(data, 41); int bytesCount = System.BitConverter.ToInt32(data, 43); //выдаст количество байтов, не длину строки if (bytesCount < 0 | bytesCount > 1000000) { Debug.Log("crew load error - name bytes count incorrect"); GameMaster.LoadingFail(); return; } if (bytesCount > 0) { data = new byte[bytesCount]; fs.Read(data, 0, bytesCount); System.Text.Decoder d = System.Text.Encoding.Default.GetDecoder(); var chars = new char[d.GetCharCount(data, 0, bytesCount)]; d.GetChars(data, 0, bytesCount, chars, 0, true); name = new string(chars); } }
public MiniStream (IMiniStreamSink sink, Encoding encoding, int buf_size) { if (sink == null) throw new ArgumentNullException (); this.sink = sink; this.sb = new StringBuilder (); this.decoder = encoding.GetDecoder (); this.buf = new char[buf_size]; }
/// <summary> /// Comment about constructing. /// </summary> private InterningBinaryReader(Stream input, Buffer buffer) : base(input, buffer.Encoding) { if (input == null) { throw new InvalidOperationException(); } _buffer = buffer; _decoder = buffer.Encoding.GetDecoder(); }
public MyBinaryReader(Stream stream, Encoding encoding) : base(stream, encoding) { this.m_decoder = encoding.GetDecoder(); this.m_maxCharsSize = encoding.GetMaxCharCount(0x80); int maxByteCount = encoding.GetMaxByteCount(1); if (maxByteCount < 0x10) { maxByteCount = 0x10; } }
public static string Decrypt(this string str) { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(str); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); return(new string(decoded_char)); }
/// <summary>Initializes a new reusable reader.</summary> /// <param name="encoding">The Encoding to use. Defaults to UTF8.</param> /// <param name="bufferSize">The size of the buffer to use when reading from the stream.</param> public ReusableTextReader(Encoding encoding = null, int bufferSize = 1024) { if (encoding == null) { encoding = Encoding.UTF8; } _decoder = encoding.GetDecoder(); _bytes = new byte[bufferSize]; _chars = new char[encoding.GetMaxCharCount(_bytes.Length)]; }
//bool disposed; public RequestState() { BufferRead = new byte[BufferSize]; RequestData = new StringBuilder(String.Empty); Request = null; ResponseStream = null; Response = null; StreamDecode = Encoding.UTF8.GetDecoder(); RequestByte=new MemoryStream(); //disposed = false; }
public string base64Decode(string sData) { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(sData); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); }
public BinaryReader(Stream input, Encoding encoding) { if (input == null || encoding == null) throw new ArgumentNullException(Locale.GetText ("Input or Encoding is a null reference.")); if (!input.CanRead) throw new ArgumentException(Locale.GetText ("The stream doesn't support reading.")); m_stream = input; m_encoding = encoding; decoder = encoding.GetDecoder (); m_buffer = new byte [32]; }
static MacUtil() { Encoding macencoding; try { macencoding = Encoding.GetEncoding("macintosh"); } catch (ArgumentException) { macencoding = Encoding.ASCII; } macdecoder = macencoding.GetDecoder(); }
//Test method to verify encode/decode service with orderclass static Boolean testOrder() { OrderClass order = new OrderClass(); order.setAmt(123); order.setID("test"); order.setCardNo(456418); Encoder enc = new Encoder(order); String encoded = enc.getOrder(); Decoder dec = new Decoder(encoded); return order == dec.getOrder(); }
public string DecryptCode(string code) { code = code.Substring(0, code.Length - 1); System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(code); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); code = new String(decoded_char); return(code); }
internal DryadLinqBinaryReader(NativeBlockStream stream, Encoding encoding) { this.m_nativeStream = stream; this.m_encoding = encoding; this.m_decoder = encoding.GetDecoder(); this.m_curDataBlockInfo.DataBlock = null; this.m_curDataBlockInfo.BlockSize = -1; this.m_curDataBlockInfo.ItemHandle = IntPtr.Zero; this.m_curDataBlock = this.m_curDataBlockInfo.DataBlock; this.m_curBlockSize = this.m_curDataBlockInfo.BlockSize; this.m_curBlockPos = -1; this.m_isClosed = false; }
public BinaryReader(Stream input, Encoding encoding) { if (input == null || encoding == null) throw new ArgumentNullException(Locale.GetText ("Input or Encoding is a null reference.")); if (!input.CanRead) throw new ArgumentException(Locale.GetText ("The stream doesn't support reading.")); m_stream = input; m_encoding = encoding; decoder = encoding.GetDecoder (); // internal buffer size is documented to be between 16 and the value // returned by GetMaxByteCount for the specified encoding m_buffer = new byte [Math.Max (16, encoding.GetMaxByteCount (1))]; }
public void run() { Debug.Log("Starting Thread"); running = true; try { Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse("10.19.186.134"); System.Net.IPEndPoint remoteEP = new IPEndPoint(ipAdd, 1234); soc.ReceiveTimeout = 1000; soc.SendTimeout = 1000; soc.Connect(remoteEP); soc.Send(System.Text.Encoding.ASCII.GetBytes("Output\n")); while (running) { byte[] buffer = new byte[300000]; int iRx = soc.Receive(buffer); char[] chars = new char[iRx]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(buffer, 0, iRx, chars, 0); System.String recv = new System.String(chars); //Console.WriteLine(recv); //Debug.Log(recv); //msg = recv; string[] msgs = recv.Split('@'); ori = msgs[0]; pos = msgs[1]; /* * if (msgs[0].Split(' ').Length == 4) * { * ori = msgs[0]; * pos = msgs[1]; * } * else { * pos = msgs[0]; * ori = msgs[1]; * }*/ } soc.Close(); } catch (Exception e) { //Console.WriteLine(e); Debug.Log(e); } }
public static void LoadStaticData(System.IO.Stream fs) { if (artifactsList == null) { artifactsList = new List <Artifact>(); } else { artifactsList.Clear(); } var data = new byte[4]; fs.Read(data, 0, 4); int artsCount = System.BitConverter.ToInt32(data, 0); int LENGTH = 23; while (artsCount > 0) { data = new byte[LENGTH]; fs.Read(data, 0, LENGTH); var a = new Artifact( System.BitConverter.ToSingle(data, 0), // stability System.BitConverter.ToSingle(data, 4), //saturation System.BitConverter.ToSingle(data, 8), //frequency (Path)data[12] ); a.ID = System.BitConverter.ToInt32(data, 13); a.researched = data[17] == 1; a.status = (ArtifactStatus)data[18]; int bytesCount = System.BitConverter.ToInt32(data, 19); //выдаст количество байтов, не длину строки if (bytesCount > 0) { data = new byte[bytesCount]; fs.Read(data, 0, bytesCount); System.Text.Decoder d = System.Text.Encoding.Default.GetDecoder(); var chars = new char[d.GetCharCount(data, 0, bytesCount)]; d.GetChars(data, 0, bytesCount, chars, 0, true); a.name = new string(chars); } artsCount++; } fs.Read(data, 0, 4); nextID = System.BitConverter.ToInt32(data, 0); }
public static string Decrypt(string cipherText, string passPhrasee = "ASD") { var rand = cipherText.Substring(0, 6); string passPhrase = passPhrasee; System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(cipherText.Decode()); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); }
public static string Base64Decode(string data) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); data = data.Replace("-", "+").Replace("_", "/"); byte[] todecode_byte = Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch (Exception e) { return(""); } }
String storeProfileImage(String _userImage, String _userID) { string profileImgURL = ""; if (_userImage != "") { string sSavePath = "App_Resources/"; System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] ret = Convert.FromBase64String(_userImage); // Save the stream to disk System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + _userID + ".jpg"), System.IO.FileMode.Create); newFile.Write(ret, 0, ret.Length); newFile.Close(); profileImgURL = "http://192.168.69.1/MTutorService/App_Resources/" + _userID + ".jpg"; } return(profileImgURL); }
public void LoginAccess() { string userName = usernameTxt.text + ";" + CalculateMD5Hash(passwordTxt.text); int i = 0; Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse("192.168.1.157"); System.Net.IPEndPoint remoteEP = new IPEndPoint(ipAdd, 10000); soc.Connect(remoteEP); outputTxt.text = "Connectected to server, authenticating..."; i++; byte[] byData = System.Text.Encoding.ASCII.GetBytes(userName); soc.Send(byData); byte[] buffer = new byte[1024]; int iRx = soc.Receive(buffer); char[] chars = new char[iRx]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(buffer, 0, iRx, chars, 0); System.String recv = new System.String(chars); if (recv == "s") { outputTxt.text = "Connection Success! Logging in..."; SceneManager.LoadScene("mainScreen", LoadSceneMode.Single); iRx = soc.Receive(buffer); char[] chars2 = new char[iRx]; System.Text.Decoder d2 = System.Text.Encoding.UTF8.GetDecoder(); int charLen2 = d.GetChars(buffer, 0, iRx, chars2, 0); System.String recv2 = new System.String(chars2); i++; } else { outputTxt.text = "Invalid Username or Password, try again."; } }
public string decryptPassword(string sData) { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); int mod4 = sData.Length % 4; if (mod4 > 0) { sData += new string('=', 4 - mod4); } byte[] todecode_byte = Convert.FromBase64String(sData); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); }
private static string base64Decode(string sData) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(sData); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch { throw new InvalidCastException("Error decoding DB password"); } }
/// <summary> /// Decodes a base64 string /// </summary> /// <param name="data">string that will be converted</param> /// <returns>true if the conversion succeeded or false if it didnt</returns> public static bool Base64StringDecode(string data) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = System.Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); data = new String(decoded_char); return(true); } catch (Exception) { return(false); } }
/* * Method : cmdReceiveData * Returns : none * Parameters : none * Description : recieves data from the previously connected address */ private void cmdReceiveData() { try { byte[] buffer = new byte[1024]; int iRx = m_socWorker.Receive(buffer); char[] chars = new char[iRx]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(buffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); IDValidLabel.Text = szData; } catch (System.Net.Sockets.SocketException se) { log.logger(se.Message); MessageBox.Show(se.Message); } }
/// <summary> /// This the call back function which will be invoked when the socket // detects any client writing of data on the stream /// </summary> /// <param name="asyn"></param> public void OnDataReceived(IAsyncResult asyn) { try { SocketPacket socketData = (SocketPacket)asyn.AsyncState; int iRx = 0; // Complete the BeginReceive() asynchronous call by EndReceive() method // which will return the number of characters written to the stream // by the client iRx = socketData.m_currentSocket.EndReceive(asyn); char[] chars = new char[iRx + 1]; System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0); System.String szData = new System.String(chars); this.Invoke(new System.Action(delegate() { richTextBoxReceivedMsg.AppendText(szData); //when we are sure we received the entire message //pass the Object received into parameter //after removing the flag indicating the end of message if (richTextBoxReceivedMsg.Text.Contains("ENDOFMESSAGE")) { RetrieveReceivedEventData( richTextBoxReceivedMsg.Text.Remove(richTextBoxReceivedMsg.Text.IndexOf("ENDOFMESSAGE"), 12), socketData.m_currentSocket.RemoteEndPoint ); } })); // Continue the waiting for data on the Socket WaitForData(socketData.m_currentSocket); } catch (ObjectDisposedException) { System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n"); } catch (SocketException se) { MessageBox.Show(se.Message); } }
private void Init(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { this.process = process; this.stream = stream; this.encoding = encoding; this.userCallBack = callback; this.decoder = encoding.GetDecoder(); if (bufferSize < 0x80) { bufferSize = 0x80; } this.byteBuffer = new byte[bufferSize]; this._maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); this.charBuffer = new char[this._maxCharsPerBuffer]; this.cancelOperation = false; this.eofEvent = new ManualResetEvent(false); this.sb = null; this.bLastCarriageReturn = false; }
public SerialPort() { this.baudRate = 0x2580; this.dataBits = 8; this.stopBits = System.IO.Ports.StopBits.One; this.portName = "COM1"; this.encoding = System.Text.Encoding.ASCII; this.decoder = System.Text.Encoding.ASCII.GetDecoder(); this.maxByteCountForSingleChar = System.Text.Encoding.ASCII.GetMaxByteCount(1); this.readTimeout = -1; this.writeTimeout = -1; this.receivedBytesThreshold = 1; this.parityReplace = 0x3f; this.newLine = "\n"; this.readBufferSize = 0x1000; this.writeBufferSize = 0x800; this.inBuffer = new byte[0x400]; this.oneChar = new char[1]; }
private void button10_Click_1(object sender, EventArgs e) { try { ButUpload.Enabled = false; dtgvFile.Rows.Clear(); if (files == null) { return; } byte[] share; string Str_share = "Share@"; foreach (FileInfo file in files) { share = new byte[1024]; Str_share += file.Name + "@" + file.Length.ToString() + "@" + UserName; share = System.Text.Encoding.ASCII.GetBytes(Str_share); this.S_loginConnect.Send(share); Str_share = "Share@"; //Receive "Next" to : byte[] Next = new byte[1024]; int i_Next = this.S_loginConnect.Receive(Next); char[] chars_Next = new char[i_Next]; System.Text.Decoder d_Next = System.Text.Encoding.UTF8.GetDecoder(); int charLenNext = d_Next.GetChars(Next, 0, i_Next, chars_Next, 0); System.String S_Next = new System.String(chars_Next); if (S_Next != "Next") { break; } else { dtgvFile.Rows.Add(file.Name, file.Length, file.Exists); } } //MessageBox.Show("Upload Complete!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (SocketException) { } }
public string base64Decode(string sData) { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); try { byte[] todecode_byte = Convert.FromBase64String(sData); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch (Exception err) { //Response.Redirect("~/error.aspx"); return(""); } }
protected string decodepwd(string depas) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(depas); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch (Exception ex) { CreateLogFile log = new CreateLogFile(); log.ErrorLog(Server.MapPath("../Logs/Errorlog"), "Decode method of AlumniProfileHome page for " + Session["loginname"] + ":" + ex.Message); return("conversion error"); } }
private string Decryptdata(string encryptpwd) { try { string decryptpwd = string.Empty; UTF8Encoding encodepwd = new UTF8Encoding(); System.Text.Decoder utf8Decode = encodepwd.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(encryptpwd); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); decryptpwd = new String(decoded_char); return(decryptpwd); } catch { return(null); } }
protected virtual void Dispose(bool disposing) { if (disposing && (this.stream != null)) { this.stream.Close(); } if (this.stream != null) { this.stream = null; this.encoding = null; this.decoder = null; this.byteBuffer = null; this.charBuffer = null; } if (this.eofEvent != null) { this.eofEvent.Close(); this.eofEvent = null; } }
//public static string profileidEncrypt(string clearText) //{ // string EncryptionKey = "MAKV2SPBNI99212"; // byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); // using (Aes encryptor = Aes.Create()) // { // Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); // encryptor.Key = pdb.GetBytes(32); // encryptor.IV = pdb.GetBytes(16); // using (MemoryStream ms = new MemoryStream()) // { // using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) // { // cs.Write(clearBytes, 0, clearBytes.Length); // cs.Close(); // } // clearText = Convert.ToBase64String(ms.ToArray()); // } // } // return clearText; //} public static string base64Decode(string data) { try { data = data.Replace("100", "=").Replace("200", "+").Replace("300", "#").Replace("400", "!").Replace("500", ";").Replace("600", "'").Replace("700", "/").Replace("800", "\\"); System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return(result); } catch (Exception e) { throw new Exception("Error in base64Decode" + e.Message); } }
private void Init(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) { this.stream = stream; this.encoding = encoding; this.decoder = encoding.GetDecoder(); if (bufferSize < 0x80) { bufferSize = 0x80; } this.byteBuffer = new byte[bufferSize]; this._maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); this.charBuffer = new char[this._maxCharsPerBuffer]; this.byteLen = 0; this.bytePos = 0; this._detectEncoding = detectEncodingFromByteOrderMarks; this._preamble = encoding.GetPreamble(); this._checkPreamble = this._preamble.Length > 0; this._isBlocked = false; this._closable = true; }