/// <summary>
        /// Consturctor
        /// </summary>
        public App()
        {
            Sniffer = new PacketSniffer();

            // Load settings...

            string lan = NSA4Dummies.Properties.Settings.Default.lan;

            // Check if there is at least one language file existing

            if (null == LanguageFile.GetLanguages())
            {

                languageFileMissing = true;
                System.Windows.MessageBox.Show("There was no language file found! Please add one manually or reinstall the software.", "ERROR! No language file found", MessageBoxButton.OK, MessageBoxImage.Error);

            }
            else
            {
                // Load language file...

                translation = LanguageFile.GetTranslation(lan);

                this.niContextMenu = new System.Windows.Forms.ContextMenu();
                this.niStartSniffer = new System.Windows.Forms.MenuItem();
                this.niStopSniffer = new System.Windows.Forms.MenuItem();
                this.niExit = new System.Windows.Forms.MenuItem();
                this.components = new System.ComponentModel.Container();

                // Initialize niContextMenu.
                this.niContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.niStartSniffer, this.niStopSniffer, this.niExit });

                // Initialize niStartSniffer.
                this.niStartSniffer.Index = 0;
                this.niStartSniffer.Text = App.translation["notifyIcon.niStartSniffer"];
                this.niStartSniffer.Click += new System.EventHandler(this.niStart_Click);

                // Initialize niStopSniffer.
                this.niStopSniffer.Index = 1;
                this.niStopSniffer.Text = App.translation["notifyIcon.niStopSniffer"];
                this.niStopSniffer.Click += new System.EventHandler(this.niStop_Click);

                // Initialize niExit.
                this.niExit.Index = 2;
                this.niExit.Text = App.translation["notifyIcon.niExit"];
                this.niExit.Click += new System.EventHandler(this.niExit_Click);

                // Create the NotifyIcon.
                this.ntfyIcon = new System.Windows.Forms.NotifyIcon(this.components);

                // Set the icon for the systray.
                ntfyIcon.Icon = (Icon)NSA4Dummies.Properties.Resources.NotifyIcon;
                ntfyIcon.ContextMenu = this.niContextMenu;
                ntfyIcon.Text = App.translation["notifyIcon.niText"];
                ntfyIcon.Visible = true;

                // Click events for NotifyIcon.
                ntfyIcon.Click += new System.EventHandler(this.ntfyIcon_Click);
                ntfyIcon.DoubleClick += new System.EventHandler(this.ntfyIcon_DoubleClick);

                // Start network sniffing
                Sniffer.StartSniffer();
            }
        }
Beispiel #2
0
        public void Command(string CommandString)
        {
            Locallog.Add(CommandString);
            string[] Command = CommandString.Split(' ');
            switch (Command[0].ToLower())
            {
            case "view":
                if (Command.Length > 1)
                {
                    switch (Command[1].ToLower())
                    {
                    case "networkinterfaces":
                        foreach (NetworkInterface n in NetworkInterfaces.Values)
                        {
                            LocalLog("Name:------- " + n.Name);
                            LocalLog("MacAddress:- " + n.MyMACAddress);
                            LocalLog("Local IP:--- " + n.LocalIP);
                            LocalLog("NetMask:---- " + n.SubnetMask);
                            LocalLog("Type Of:---- " + n.GetType());
                        }
                        break;

                    case "apps":
                    case "applications":
                        for (int i = 0; i < Apps.Length; i++)
                        {
                            if (Apps[i] != null)
                            {
                                LocalLog("   Slot: " + i + "  Type: " + Apps[i].GetType());
                            }
                        }
                        break;

                    case "app":
                    case "application":
                        if (Command.Length > 2)
                        {
                            try
                            {
                                int id = int.Parse(Command[2]);
                                if (Apps[id]?.log != null)
                                {
                                    foreach (string s in Apps[id]?.log)
                                    {
                                        LocalLog("   " + s);
                                    }
                                }
                            }
                            catch (FormatException)
                            {
                                LocalLog("Error parsing Slot");
                            }
                            catch (OverflowException)
                            {
                                LocalLog("Error, Slot too large, overflow");
                            }
                            catch (IndexOutOfRangeException)
                            {
                                LocalLog("Error, Slot to large, out of range");
                            }
                        }
                        break;

                    case "help":
                        LocalLog("view item");
                        LocalLog("    networkinterfaces  -Dispalys info of each network interface");
                        LocalLog("    apps               -Displays list of loaded application");
                        LocalLog("    app appNo          -Displays log of selected appliation");
                        LocalLog("    help               -Displays this help screen");
                        break;

                    default:
                        LocalLog("invalid parameter " + Command[1] + "  use 'view help' for more info");
                        break;
                    }
                }
                break;

            case "as":
                if (Command.Length > 1)
                {
                    switch (Command[1].ToLower())
                    {
                    case "app":
                    case "application":
                        if (Command.Length > 2)
                        {
                            try
                            {
                                int id = int.Parse(Command[2]);

                                string newcommand = "";
                                for (int i = 3; i < Command.Length; i++)
                                {
                                    newcommand += Command[i] + " ";
                                }
                                Apps[id]?.Command(newcommand);
                            }
                            catch (FormatException)
                            {
                                LocalLog("Error parsing Slot");
                            }
                            catch (OverflowException)
                            {
                                LocalLog("Error, Slot too large, overflow");
                            }
                            catch (IndexOutOfRangeException)
                            {
                                LocalLog("Error, Slot too large, out of range");
                            }
                        }
                        else
                        {
                            LocalLog("Must specify a app to act as");
                        }
                        break;

                    case "help":
                        LocalLog("as item identifier      -runs a command as the selected item");
                        LocalLog("    items");
                        LocalLog("      app");
                        break;

                    default:
                        LocalLog("Must specify a type to act as");
                        LocalLog("use as help for more info");
                        break;
                    }
                }
                else
                {
                    LocalLog("Must specify a type to act as");
                    LocalLog("use as help for more info");
                }
                break;

            case "start":
                if (Command.Length > 1)
                {
                    if (int.TryParse(Command[1], out int app))
                    {
                        if (app >= Apps.Length || app < 0)
                        {
                            LocalLog("Failed to add app, slot out of bounds");
                            return;
                        }
                        bool isNull   = Apps[app] == null;
                        bool isClosed = true;
                        if (!isNull)
                        {
                            isClosed = Apps[app].closed;
                        }

                        if (isNull || isClosed)
                        {
                            if (Command.Length > 1)
                            {
                                switch (Command[2].ToLower())
                                {
                                case "packetsniffer":
                                    PacketSniffer a = new PacketSniffer();
                                    OnRecievedPacket += (b, s) => { a.onPacket(b); };
                                    if (AddApp(a, app))
                                    {
                                        LocalLog("Successfully added App");
                                    }
                                    else
                                    {
                                        LocalLog("Failed to add App");
                                    }
                                    break;

                                default:
                                    LocalLog("Invalid application " + Command[2]);
                                    break;
                                }
                            }
                            else
                            {
                                Log("Pleace specify an application to start");
                            }
                        }
                        else
                        {
                            LocalLog("Invalid app slot, app already exists there");
                        }
                    }
                    else if (Command[1].ToLower() == "help")
                    {
                        LocalLog("start slot application");
                        LocalLog("    slot - intiger application slot, use 'view apps' to see available slots");
                        LocalLog("    application - name of application to start");
                        LocalLog("       packetsniffer");
                    }
                    else
                    {
                        LocalLog("Invalid application slot: " + Command[1]);
                    }
                }
                break;

            case "help":
                LocalLog("view item otherparams   -shows infomation about selected item");
                LocalLog("as item identifier      -runs a command as the selected item");
                LocalLog("start slot application  -starts application in selected slot");
                LocalLog("help                    -shows this help text");
                LocalLog("use '[command] help' for more help with a spesific command");
                break;
            }
        }