-
Notifications
You must be signed in to change notification settings - Fork 1
/
TCPBinaryReader.cs
80 lines (75 loc) · 2.03 KB
/
TCPBinaryReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Pcap.Object
{
public struct Header
{
}
public class TCPBinaryReader : BinaryReader
{
public TCPBinaryReader(Stream input) : base(input)
{
}
public TCPBinaryReader(Stream input, Encoding encoding) : base(input, encoding)
{
}
public override string ReadString()
{
ushort cnt = ReadUInt16();
byte[] buffer = ReadBytes(cnt);
ushort _ = ReadUInt16();
return Encoding.Unicode.GetString(buffer);
}
public T ReadObj<T>() where T : ITCPReadable, new()
{
T obj = new T();
obj.Read(this);
return obj;
}
public List<T> ReadList<T>() where T : ITCPReadable, new()
{
List<T> list = new List<T>();
ushort cnt = ReadUInt16();
for (int i = 0; i < cnt; i++)
{
list.Add(ReadObj<T>());
}
return list;
}
public List<uint> ReadUIntList()
{
List<uint> list = new List<uint>();
ushort cnt = ReadUInt16();
for (int i = 0; i < cnt; i++)
{
uint item = ReadUInt32();
list.Add(item);
}
return list;
}
public List<ulong> ReadUlongList()
{
List<ulong> list = new List<ulong>();
ushort cnt = ReadUInt16();
for (int i = 0; i < cnt; i++)
{
ulong item = ReadUInt64();
list.Add(item);
}
return list;
}
public List<int> ReadIntList()
{
List<int> list = new List<int>();
ushort cnt = ReadUInt16();
for (int i = 0; i < cnt; i++)
{
int item = ReadInt32();
list.Add(item);
}
return list;
}
}
}