VBCopyMemory下标越界
Private Sub GetTCPDatas()Dim TcpRow As MIB_TCPROW
Dim Buffer() As Byte
Dim LngRequired As Long
Dim LngStructureSize As Long
Dim LngRows As Long
Dim LngCounter As Long
Dim strTemps As String
Dim ListX As ListItem
LvwTcpTable.ListItems.Clear
Call GetTcpTable(ByVal 0&, LngRequired, 1)
If LngRequired > 0 Then
ReDim Buffer(0 To LngRequired - 1) As Byte
If GetTcpTable(Buffer(0), LngRequired, 1) = ERROR_SUCCESS Then
LngStructureSize = LenB(TcpRow)
'起始的四个字节,是做为表示进入点的数字
CopyMemory LngRows, Buffer(0), 4
For LngCounter = 1 To LngRows
' 将上述获得四个字节的相关数据,拷贝到 TcpRow 的结构之中
CopyMemory TcpRow, Buffer(4 + (LngCounter - 1) * LngStructureSize), LngStructureSize
' 将结果传送到 ListView 之中
With TcpRow
Set ListX = LvwTcpTable.ListItems.Add(, , GetInetAddrStr(.dwLocalAddr))
ListX.SubItems(1) = .dwOwningPid
ListX.SubItems(2) = ntohs(.dwLocalPort)
ListX.SubItems(3) = GetInetAddrStr(.dwRemoteAddr)
ListX.SubItems(4) = ntohs(.dwRemotePort)
ListX.SubItems(5) = (.dwState)
Select Case .dwState
Case MIB_TCP_STATE_CLOSE_WAIT: strTemps = "结束等待"
Case MIB_TCP_STATE_CLOSED: strTemps = "已结束"
Case MIB_TCP_STATE_CLOSING: strTemps = "结束中..."
Case MIB_TCP_STATE_DELETE_TCB: strTemps = "已删除TCB"
Case MIB_TCP_STATE_ESTAB: strTemps = "已连接"
Case MIB_TCP_STATE_FIN_WAIT1: strTemps = "FIN延时处理1"
Case MIB_TCP_STATE_FIN_WAIT2: strTemps = "FIN延时处理2"
Case MIB_TCP_STATE_LAST_ACK: strTemps = "上次取得的确认信号"
Case MIB_TCP_STATE_LISTEN: strTemps = "监听中..."
Case MIB_TCP_STATE_SYN_SENT: strTemps = "传送"
Case MIB_TCP_STATE_SYN_RCVD: strTemps = "数据接收中"
Case MIB_TCP_STATE_TIME_WAIT: strTemps = "等候中..."
End Select
ListX.SubItems(5) = ListX.SubItems(4) & "(" & strTemps & ")"
strTemps = ""
End With
Next
End If
End If
End Sub