public void OpenFile(string FileName) { var bw = new BinaryReader(File.OpenRead(FileName)); var buffer = new byte[btsnoop_magic.Length]; bw.Read(buffer, 0, buffer.Length); var fh = bw.ReadStruct <FileHeader>(new List <int>() { 4, 4 }); this.datalink = (DataLayerLink)fh.datalink; this.Version = fh.Version; while (bw.BaseStream.Position < bw.BaseStream.Length) { var record = bw.ReadStruct <RecordHeader>(new List <int>() { 4, 4, 4, 4, 8 }); var recbuf = new byte[record.incl_len]; bw.Read(recbuf, 0, recbuf.Length); var Record = new BTSnoopRecord() { cum_drops = record.cum_drops, flags = record.flags, orig_len = record.orig_len, Timestamp = new DateTime(1970, 1, 1).AddMilliseconds((record.ts_usec - SymbianTimeBaseDiffToUnixTimeBase) / 1000.0), Data = recbuf, }; this.Records.Add(Record); } bw.Close(); }
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")); }