| 1 |
// License: BSD/LGPL |
| 2 |
// Copyright (C) 2011-2018 Thomas d'Otreppe |
| 3 |
using System; |
| 4 |
using System.Data; |
| 5 |
|
| 6 |
namespace WirelessPanda.Readers |
| 7 |
{ |
| 8 |
public class UniversalReader : Reader |
| 9 |
{ |
| 10 |
/// <summary> |
| 11 |
/// Reader |
| 12 |
/// </summary> |
| 13 |
private Reader _reader = null; |
| 14 |
|
| 15 |
/// <summary> |
| 16 |
/// File type |
| 17 |
/// </summary> |
| 18 |
/// <remarks>So that we have to check it only once</remarks> |
| 19 |
private string _fileType = string.Empty; |
| 20 |
|
| 21 |
#region Properties |
| 22 |
/// <summary> |
| 23 |
/// DataSet containing 2 tables: "Access Points" and "Stations" |
| 24 |
/// </summary> |
| 25 |
public override DataSet Dataset |
| 26 |
{ |
| 27 |
get |
| 28 |
{ |
| 29 |
return this._reader.Dataset; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
/// <summary> |
| 34 |
/// Array of access points |
| 35 |
/// </summary> |
| 36 |
public override AccessPoint[] AccessPoints |
| 37 |
{ |
| 38 |
get |
| 39 |
{ |
| 40 |
return this._reader.AccessPoints; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/// <summary> |
| 45 |
/// Array of stations |
| 46 |
/// </summary> |
| 47 |
public override Station[] Stations |
| 48 |
{ |
| 49 |
get |
| 50 |
{ |
| 51 |
return this._reader.Stations; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/// <summary> |
| 56 |
/// Reader type |
| 57 |
/// </summary> |
| 58 |
public override string ReaderType |
| 59 |
{ |
| 60 |
get |
| 61 |
{ |
| 62 |
return "Universal: Airodump-ng CSV, Kismet CSV, Kismet NetXML"; |
| 63 |
} |
| 64 |
} |
| 65 |
#endregion |
| 66 |
|
| 67 |
/// <summary> |
| 68 |
/// Constructor |
| 69 |
/// </summary> |
| 70 |
/// <param name="filename">Filename (doesn't need to exist now but MUST when using Read() )</param> |
| 71 |
public UniversalReader(string filename) : base(filename) { } |
| 72 |
|
| 73 |
/// <summary> |
| 74 |
/// Read/Update the content of the file |
| 75 |
/// </summary> |
| 76 |
/// <returns>true if successful</returns> |
| 77 |
public override bool Read() |
| 78 |
{ |
| 79 |
this.ParseSuccess = false; |
| 80 |
|
| 81 |
if (string.IsNullOrEmpty(this._fileType)) |
| 82 |
{ |
| 83 |
this._fileType = Reader.getFileType(this.Filename); |
| 84 |
} |
| 85 |
|
| 86 |
switch (this._fileType) |
| 87 |
{ |
| 88 |
case "Airodump-ng CSV": |
| 89 |
this._reader = new CsvReader(this.Filename); |
| 90 |
break; |
| 91 |
case "Kismet CSV": |
| 92 |
this._reader = new KismetCsvReader(this.Filename); |
| 93 |
break; |
| 94 |
case "Kismet NetXML": |
| 95 |
this._reader = new NetXMLReader(this.Filename); |
| 96 |
break; |
| 97 |
default: |
| 98 |
throw new FormatException("Unknown file format, can't parse"); |
| 99 |
break; |
| 100 |
} |
| 101 |
|
| 102 |
this.ParseSuccess = this._reader.Read(); |
| 103 |
|
| 104 |
return this.ParseSuccess; |
| 105 |
} |
| 106 |
} |
| 107 |
} |