示例#1
0
        /// <summary>
        /// This method encrypts a process container.
        /// </summary>
        /// <param name="e"> The <see cref="ProcessListContainer"/> to encrypt. </param>
        /// <param name="hostname"> The hostname of the machine. </param>
        /// <returns> It returns a byte message. </returns>
        public static byte[] Serealize(ProcessListContainer e, string hostname)
        {
            ProcessListMessage messageType = new ProcessListMessage();

            List <byte> message;

            byte[] headerEnc = Encoding.UTF8.GetBytes(Header);
            byte[] hostEnc   = Encoding.UTF8.GetBytes(hostname);

            if (hostEnc.Length > 255)
            {
                throw new ArgumentException("Error hostname to long.");
            }

            try
            {
                using (var ms = new MemoryStream())
                {
                    BinaryFormatter writer = new BinaryFormatter();
                    writer.Serialize(ms, e);
                    message = ms.ToArray().ToList();
                }
            }
            catch (Exception)
            {
                throw new ArgumentException("Error couldnt serealize the message.");
            }

            List <byte> finalMessage = new List <byte>();

            finalMessage.AddRange(headerEnc);

            byte[] messageLength = new byte[100];

            for (int i = 0; i < BitConverter.GetBytes(hostEnc.Length + message.Count + 2).Length; i++)
            {
                messageLength[i] = BitConverter.GetBytes(hostEnc.Length + message.Count + 2)[i];
            }

            finalMessage.AddRange(messageLength);

            finalMessage.Add((byte)messageType.Type);

            finalMessage.Add((byte)hostEnc.Length);

            finalMessage.AddRange(hostEnc);

            finalMessage.AddRange(message);

            finalMessage.Add(CalculateCheckSum(finalMessage.ToArray()));

            return(finalMessage.ToArray());
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessListEventArgs"/> class.
 /// </summary>
 /// <param name="container"> The list of the new and old processes. </param>
 public ProcessListEventArgs(ProcessListContainer container)
 {
     this.List = container;
 }