コード例 #1
0
        public void UpdateModuleOrder()
        {
            lock (padlock)
            {
                ProcessingIndex.Clear();
                List <int> indexes = new List <int>();
                if (moduleOrder.Count == 0)
                {
                    for (int i = 0; i < Count; i++)
                    {
                        if (!indexes.Contains(i))
                        {
                            ProcessingIndex.Add(i);
                            modules[i].Enabled = true;
                            modules[i].ModuleStart();
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < moduleOrder.Count; i++)
                    {
                        int mindex = GetModuleIndex(moduleOrder[i].Value);
                        if (mindex != -1)
                        {
                            indexes.Add(mindex);
                            ProcessingIndex.Add(mindex);
                            if (modules[mindex].Enabled != moduleOrder[i].Key)
                            {
                                if (modules[mindex].Enabled)
                                {
                                    modules[mindex].ModuleStop();
                                }
                                else
                                {
                                    modules[mindex].ModuleStart();
                                }
                                modules[mindex].Enabled = moduleOrder[i].Key;
                            }
                        }
                    }

                    for (int i = 0; i < Count; i++)
                    {
                        if (!indexes.Contains(i))
                        {
                            ProcessingIndex.Add(i);
                        }
                    }
                }
                moduleOrder.Clear();
                for (int i = 0; i < Count; i++)
                {
                    FirewallModule fm = GetModule(i);
                    moduleOrder.Add(new KeyValuePair <bool, string>(fm.Enabled, fm.MetaData.Name));
                }
                SaveModuleOrder();
            }
        }
コード例 #2
0
 public void AddModule(FirewallModule fm)
 {
     lock (padlock)
     {
         modules.Add(fm);
         ProcessingIndex.Add(modules.Count - 1);
     }
 }
コード例 #3
0
        public void LoadModule(string file)
        {
            FirewallModule mod = null;

            lock (loadedAssemblies)
            {
                if (file.Contains("FirewallModule.dll") || !file.Contains(".dll"))
                {
                    return;
                }
                try
                {
                    if (loadedMods.ContainsValue(file))
                    {
                        return;
                    }
                    Assembly assembly;
                    if (!loadedAssemblies.TryGetValue(file, out assembly))
                    {
                        assembly = Assembly.Load(File.ReadAllBytes(file));
                        loadedAssemblies.Add(file, assembly);
                    }
                    Type[] type = assembly.GetTypes();
                    foreach (Type t in type)
                    {
                        if (typeof(FirewallModule).IsAssignableFrom(t))
                        {
                            mod         = (FirewallModule)Activator.CreateInstance(t);
                            mod.adapter = na;
                            mod.Enabled = false;
                            //mod.ModuleStart();
                            AddModule(mod);
                            loadedMods.Add(mod.MetaData.Name, file);
                        }
                    }
                }
                catch (ArgumentException ae)
                {
                    LogCenter.Instance.Push(mod.MetaData.Name, "Module attempted load twice.");
                    LogCenter.WriteErrorLog(ae);
                }
                catch (Exception e)
                {
                    LogCenter.WriteErrorLog(e);
                }
            }
        }
コード例 #4
0
ファイル: Help.cs プロジェクト: uroboros-security/fireBwall
        /// <summary>
        /// Set the labels as the user flips through them.  If the Help window is being
        /// called externally (i.e. from the module's frame), they can pass the module's object
        /// into a constructor and automatically set the selected module when it's drawn.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void modBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // if we need to initialize the window to a specific module
            if (selectedItem != null)
            {
                // set the idx to the selected item
                modBox.SelectedIndex = modBox.Items.IndexOf(this.selectedItem.ToString());
                // set it back to null
                selectedItem = null;
            }

            // valid idx...
            if (modBox.SelectedIndex >= 0)
            {
                FirewallModule temp = list.GetModule(modBox.SelectedIndex);

                modData.Text             = temp.MetaData.Name;
                modAuthorField.Text      = temp.MetaData.Author;
                modContactField.Text     = temp.MetaData.Contact;
                modVersionField.Text     = temp.MetaData.Version;
                modDescriptionField.Text = temp.MetaData.Description;
                modHelpBox.Text          = temp.MetaData.HelpString;
            }
        }
コード例 #5
0
        unsafe void ProcessLoop()
        {
            // Allocate and initialize packet structures
            ETH_REQUEST         Request      = new ETH_REQUEST();
            INTERMEDIATE_BUFFER PacketBuffer = new INTERMEDIATE_BUFFER();

            IntPtr PacketBufferIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(PacketBuffer));

            try
            {
                win32api.ZeroMemory(PacketBufferIntPtr, Marshal.SizeOf(PacketBuffer));

                Request.hAdapterHandle   = adapterHandle;
                Request.EthPacket.Buffer = PacketBufferIntPtr;

                modules = new ModuleList(this);

                modules.LoadExternalModules();

                modules.UpdateModuleOrder();

                string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                folder = folder + System.IO.Path.DirectorySeparatorChar + "firebwall";
                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }
                folder = folder + System.IO.Path.DirectorySeparatorChar + "pcapLogs";
                if (!System.IO.Directory.Exists(folder))
                {
                    System.IO.Directory.CreateDirectory(folder);
                }
                string f = folder + System.IO.Path.DirectorySeparatorChar + "blocked-" + this.InterfaceInformation.Name + "-" + PcapCreator.Instance.GetNewDate() + ".pcap";
                pcaplog = new PcapFileWriter(f);

                INTERMEDIATE_BUFFER *PacketPointer;

                while (true)
                {
                    hEvent.WaitOne();
                    while (Ndisapi.ReadPacket(hNdisapi, ref Request))
                    {
                        PacketPointer = (INTERMEDIATE_BUFFER *)PacketBufferIntPtr;
                        //PacketBuffer = (INTERMEDIATE_BUFFER)Marshal.PtrToStructure(PacketBufferIntPtr, typeof(INTERMEDIATE_BUFFER));

                        Packet pkt = new EthPacket(PacketPointer).MakeNextLayerPacket();

                        if (pkt.Outbound)
                        {
                            OutBandwidth.AddBits(pkt.Length());
                        }
                        else
                        {
                            InBandwidth.AddBits(pkt.Length());
                        }

                        bool drop = false;
                        bool edit = false;

                        if (enabled)
                        {
                            for (int x = 0; x < modules.Count; x++)
                            {
                                FirewallModule   fm  = modules.GetModule(x);
                                PacketMainReturn pmr = fm.PacketMain(ref pkt);
                                if (pmr == null)
                                {
                                    continue;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Log) == PacketMainReturnType.Log && pmr.logMessage != null)
                                {
                                    LogCenter.Instance.Push(pmr);
                                }
                                if ((pmr.returnType & PacketMainReturnType.Drop) == PacketMainReturnType.Drop)
                                {
                                    drop = true;
                                    break;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Edited) == PacketMainReturnType.Edited)
                                {
                                    edit = true;
                                }
                            }
                        }

                        if (!drop)
                        {
                            if (pkt.Outbound)
                            {
                                Ndisapi.SendPacketToAdapter(hNdisapi, ref Request);
                            }
                            else
                            {
                                Ndisapi.SendPacketToMstcp(hNdisapi, ref Request);
                            }
                        }
                        else
                        {
                            pcaplog.AddPacket(pkt.Data(), (int)pkt.Length());
                        }
                    }

                    //OM NOM NOM PASTA!
                    while (processQueue.Count != 0)
                    {
                        Packet pkt = processQueue.Dequeue().MakeNextLayerPacket();

                        if (pkt.Outbound)
                        {
                            OutBandwidth.AddBits(pkt.Length());
                        }
                        else
                        {
                            InBandwidth.AddBits(pkt.Length());
                        }

                        bool drop = false;
                        bool edit = false;

                        if (enabled)
                        {
                            for (int x = 0; x < modules.Count; x++)
                            {
                                FirewallModule   fm  = modules.GetModule(x);
                                PacketMainReturn pmr = fm.PacketMain(ref pkt);
                                if (pmr == null)
                                {
                                    continue;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Log) == PacketMainReturnType.Log && pmr.logMessage != null)
                                {
                                    LogCenter.Instance.Push(pmr.Module, pmr.logMessage);
                                }
                                if ((pmr.returnType & PacketMainReturnType.Drop) == PacketMainReturnType.Drop)
                                {
                                    drop = true;
                                    break;
                                }
                                if ((pmr.returnType & PacketMainReturnType.Edited) == PacketMainReturnType.Edited)
                                {
                                    edit = true;
                                }
                            }
                        }

                        if (!drop)
                        {
                            if (pkt.Outbound)
                            {
                                Ndisapi.SendPacketToAdapter(hNdisapi, ref Request);
                            }
                            else
                            {
                                Ndisapi.SendPacketToMstcp(hNdisapi, ref Request);
                            }
                        }
                        else
                        {
                            pcaplog.AddPacket(pkt.Data(), (int)pkt.Length());
                        }
                    }
                    hEvent.Reset();
                }
            }
            catch (Exception tae)
            {
                Marshal.FreeHGlobal(PacketBufferIntPtr);
            }
        }
コード例 #6
0
ファイル: ModuleList.cs プロジェクト: prashanthbc/firebwall
			public void AddModule(FirewallModule fm) 
            {
                lock (padlock)
                {
                    modules.Add(fm);
                    ProcessingIndex.Add(modules.Count - 1);
                }
			}