示例#1
0
        public unsafe void Dump(Packet packet)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }
            pcap_pkthdr pcapPkthdr;

            PacketHeader.GetPcapHeader(&pcapPkthdr, packet);
            basic_string\u003Cchar\u002Cstd\u003A\u003Achar_traits\u003Cchar\u003E\u002Cstd\u003A\u003Aallocator\u003Cchar\u003E\u0020\u003E stdAllocatorChar;

            MarshalingServices.ManagedToUnmanagedString(&stdAllocatorChar, this._filename);
            // ISSUE: fault handler
            try
            {
                fixed(byte *numPtr = &packet.Buffer[0])
                \u003CModule\u003E.pcap_dump((byte *)this._pcapDumper, &pcapPkthdr, numPtr);
            }
            __fault
            {
                // ISSUE: method pointer
                // ISSUE: cast to a function pointer type
                \u003CModule\u003E.___CxxCallUnwindDtor((__FnPtr <void (void *)>)__methodptr(std\u002Ebasic_string\u003Cchar\u002Cstd\u003A\u003Achar_traits\u003Cchar\u003E\u002Cstd\u003A\u003Aallocator\u003Cchar\u003E\u0020\u003E\u002E\u007Bdtor\u007D), (void *)&stdAllocatorChar);
            }
            // ISSUE: cast to a reference type
            // ISSUE: explicit reference operation
            if (16UL > (ulong) ^ (long&)((IntPtr) & stdAllocatorChar + 24))
            {
                return;
            }
            // ISSUE: explicit reference operation
            // ISSUE: cast to a reference type
            // ISSUE: explicit reference operation
            \u003CModule\u003E.delete((void *) ^ (long&)@stdAllocatorChar);
        }
示例#2
0
        public unsafe PacketCommunicatorReceiveResult ReceivePacket(out Packet packet)
        {
            this.AssertMode(PacketCommunicatorMode.Capture);
            pcap_pkthdr *pcapPkthdrPtr1;
            byte *       numPtr;
            PacketCommunicatorReceiveResult communicatorReceiveResult = this.RunPcapNextEx(&pcapPkthdrPtr1, &numPtr);

            if (communicatorReceiveResult != PacketCommunicatorReceiveResult.Ok)
            {
                packet = (Packet)null;
                return(communicatorReceiveResult);
            }
            IDataLink    dataLink           = (IDataLink) new PcapDataLink(\u003CModule\u003E.pcap_datalink(this._pcapDescriptor));
            byte *       unmanagedByteArray = numPtr;
            pcap_pkthdr *pcapPkthdrPtr2     = pcapPkthdrPtr1;
            DateTime     dateTime           = new DateTime();

            PacketTimestamp.PcapTimestampToDateTime((timeval *)pcapPkthdrPtr1, out dateTime);
            int offset = 0;
            int count  = *(int *)((IntPtr)pcapPkthdrPtr2 + 8L);

            byte[] data = MarshalingServices.UnamangedToManagedByteArray(unmanagedByteArray, offset, count);
            packet = new Packet(data, dateTime, dataLink);
            return(PacketCommunicatorReceiveResult.Ok);
        }
        private unsafe void Initialize(pcap *pcapDescriptor, string filterString, IpV4SocketAddress netmask)
        {
            // ISSUE: untyped stack allocation
            long num1 = (long)__untypedstackalloc(\u003CModule\u003E.__CxxQueryExceptionSize());
            basic_string\u003Cchar\u002Cstd\u003A\u003Achar_traits\u003Cchar\u003E\u002Cstd\u003A\u003Aallocator\u003Cchar\u003E\u0020\u003E stdAllocatorChar;

            MarshalingServices.ManagedToUnmanagedString(&stdAllocatorChar, filterString);
            // ISSUE: fault handler
            try
            {
                uint num2 = 0U;
                if (netmask != null)
                {
                    num2 = netmask.Address.ToValue();
                }
                bpf_program *bpfProgramPtr1 = (bpf_program *)\u003CModule\u003E.@new(16UL);
                bpf_program *bpfProgramPtr2;
                if ((IntPtr)bpfProgramPtr1 != IntPtr.Zero)
                {
                    // ISSUE: initblk instruction
                    __memset((IntPtr)bpfProgramPtr1, 0, 16L);
                    bpfProgramPtr2 = bpfProgramPtr1;
                }
                else
                {
                    bpfProgramPtr2 = (bpf_program *)0;
                }
                this._bpf = bpfProgramPtr2;
                try
                {
                    if (\u003CModule\u003E.pcap_compile(pcapDescriptor, this._bpf, \u003CModule\u003E.std\u002Ebasic_string\u003Cchar\u002Cstd\u003A\u003Achar_traits\u003Cchar\u003E\u002Cstd\u003A\u003Aallocator\u003Cchar\u003E\u0020\u003E\u002Ec_str(&stdAllocatorChar), 1, num2) < 0)
                    {
                        throw new ArgumentException("An error has occured when compiling the filter <" + filterString + ">: " + PcapError.GetErrorMessage(pcapDescriptor));
                    }
                }
                catch (Exception ex1) when(
                {
                    // ISSUE: unable to correctly present filter
                    uint num3 = (uint)Marshal.GetExceptionCode();
                    if (\u003CModule\u003E.__CxxExceptionFilter((void *)Marshal.GetExceptionPointers(), (void *)0, 0, (void *)0) != 0)
                    {
                        SuccessfulFiltering;
                    }
                    else
                    {
                        throw;
                    }
                }
                    )
                {
                    uint num4 = 0U;

                    \u003CModule\u003E.__CxxRegisterExceptionObject((void *)Marshal.GetExceptionPointers(), (void *)num1);
                    try
                    {
                        try
                        {
                            \u003CModule\u003E.delete((void *)this._bpf);
                            \u003CModule\u003E._CxxThrowException((void *)0, (_s__ThrowInfo *)0);
                        }
                        catch (Exception ex2) when(
                        {
                            // ISSUE: unable to correctly present filter
                            num4 = (uint)\u003CModule\u003E.__CxxDetectRethrow((void *)Marshal.GetExceptionPointers());
                            if ((int)num4 != 0)
                            {
                                SuccessfulFiltering;
                            }
                            else
                            {
                                throw;
                            }
                        }
                            )
                        {
                        }
                        if ((int)num4 != 0)
                        {
                            throw;
                        }
                    }