Пример #1
0
    // Token: 0x0600008C RID: 140 RVA: 0x00009F1C File Offset: 0x0000811C
    public static TCPGet.MIB_TCPROW_OWNER_PID[] GetAllTCPConnections()
    {
        TCPGet.MIB_TCPROW_OWNER_PID[] result = null;
        IntPtr pTCPTable;
        int    cb;

        TCPGet.GetExtendedTcpTable(pTCPTable, ref cb, false, 2, 5, 0);
        IntPtr intPtr = Marshal.AllocHGlobal(cb);

        if (TCPGet.GetExtendedTcpTable(intPtr, ref cb, false, 2, 5, 0) == 0)
        {
            object obj = Marshal.PtrToStructure(intPtr, typeof(TCPGet.MIB_TCPTABLE_OWNER_PID));
            TCPGet.MIB_TCPTABLE_OWNER_PID mib_TCPTABLE_OWNER_PID2;
            TCPGet.MIB_TCPTABLE_OWNER_PID mib_TCPTABLE_OWNER_PID = (obj != null) ? ((TCPGet.MIB_TCPTABLE_OWNER_PID)obj) : mib_TCPTABLE_OWNER_PID2;
            TCPGet.MIB_TCPROW_OWNER_PID[] array = new TCPGet.MIB_TCPROW_OWNER_PID[mib_TCPTABLE_OWNER_PID.NumberOfEntries - 1 + 1];
            int num  = 0;
            int num2 = mib_TCPTABLE_OWNER_PID.NumberOfEntries - 1;
            for (int i = num; i <= num2; i++)
            {
                IntPtr ptr = new IntPtr(intPtr.ToInt32() + Marshal.SizeOf <int>(mib_TCPTABLE_OWNER_PID.NumberOfEntries) + Marshal.SizeOf(typeof(TCPGet.MIB_TCPROW_OWNER_PID)) * i);
                TCPGet.MIB_TCPROW_OWNER_PID[] array2 = array;
                int    num3 = i;
                object obj2 = Marshal.PtrToStructure(ptr, typeof(TCPGet.MIB_TCPROW_OWNER_PID));
                TCPGet.MIB_TCPROW_OWNER_PID mib_TCPROW_OWNER_PID;
                array2[num3] = ((obj2 != null) ? ((TCPGet.MIB_TCPROW_OWNER_PID)obj2) : mib_TCPROW_OWNER_PID);
            }
            result = array;
        }
        Marshal.FreeHGlobal(intPtr);
        return(result);
    }
Пример #2
0
    // Token: 0x0600008D RID: 141 RVA: 0x0000A00C File Offset: 0x0000820C
    public static TCPGet.TcpConnection MIB_ROW_To_TCP(TCPGet.MIB_TCPROW_OWNER_PID row)
    {
        TCPGet.TcpConnection result = default(TCPGet.TcpConnection);
        result.State = (TcpState)row.state;
        IPAddress ipaddress = new IPAddress((long)((ulong)row.localAddress));

        result.localAddress  = ipaddress.ToString();
        result.LocalPort     = (int)Math.Round((double)row.LocalPort / 256.0 + (double)(row.LocalPort % 256 * 256));
        ipaddress            = new IPAddress((long)((ulong)row.RemoteAddress));
        result.RemoteAddress = ipaddress.ToString();
        result.remotePort    = (int)Math.Round((double)row.remotePort / 256.0 + (double)(row.remotePort % 256 * 256));
        Process processById = Process.GetProcessById(row.PID);

        result.Proc = processById.ProcessName + " (" + row.PID.ToString() + ")";
        processById.Dispose();
        return(result);
    }