-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (76 loc) · 3.34 KB
/
Copy pathProgram.cs
File metadata and controls
91 lines (76 loc) · 3.34 KB
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
81
82
83
84
85
86
87
88
89
90
91
namespace USBTrace_BTSnoop
{
#region Usings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
#endregion
class Program
{
static void Main(string[] args)
{
if (args == null || args.Length < 1)
{
Console.WriteLine(" First argument: CSV File");
return;
}
var bts = new BTSnoop()
{
datalink= BTSnoop.DataLayerLink.H4,
Version = 1
};
var filename = args[0];
var csv = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read));
while (csv.BaseStream.Position < csv.BaseStream.Length)
{
string line = csv.ReadLine();
var entries = line.Split(new char[] { ',' });
// nur Bluetooth Entries
if (entries[1] == "Bluetooth")
{
double seconds = double.Parse(entries[2], CultureInfo.InvariantCulture.NumberFormat);
DateTime timeStamp = new DateTime(2012, 01, 01).AddSeconds(seconds);
var dt = entries[9].Split(new Char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
var data = new Byte[dt.Length+1];
for (int i = 0; i < dt.Length; i++)
{
data[i + 1] = Byte.Parse(dt[i], System.Globalization.NumberStyles.HexNumber);
}
UInt32 flag = 0;
switch (entries[5])
{
case "0":
flag = (UInt32)BTSnoop.BTSnoopDirectionFlags.HostToController | (UInt32)BTSnoop.BTSnoopACLCommand.CommandOrEvent;
data[0] = (byte)BTSnoop.HCI_H4_TYPE.CMD;
break;
case "2":
flag = (UInt32)BTSnoop.BTSnoopDirectionFlags.HostToController | (UInt32)BTSnoop.BTSnoopACLCommand.ACLDataFrame;
data[0] = (byte)BTSnoop.HCI_H4_TYPE.ACL;
break;
case "81":
flag = (UInt32)BTSnoop.BTSnoopDirectionFlags.ControllerToHost | (UInt32)BTSnoop.BTSnoopACLCommand.CommandOrEvent;
data[0] = (byte)BTSnoop.HCI_H4_TYPE.EVT;
break;
case "82":
flag = (UInt32)BTSnoop.BTSnoopDirectionFlags.ControllerToHost | (UInt32)BTSnoop.BTSnoopACLCommand.ACLDataFrame;
data[0] = (byte)BTSnoop.HCI_H4_TYPE.ACL;
break;
}
var Rec = new BTSnoopRecord()
{
Timestamp = timeStamp,
cum_drops = 0,
flags = (UInt32)flag,
orig_len = (UInt32)data.Length,
Data = data
};
bts.Records.Add(Rec);
}
}
bts.SaveFile(Path.ChangeExtension(filename,".log"));
}
}
}