Example #1
0
 private bool WriteCsv(string pathFileNameStr, List<DeviceTabsForm.CsvData> csvData)
 {
     bool flag = false;
     try
     {
         if (csvData == null || csvData.Count <= 0)
             throw new ArgumentException(string.Format("There Is No Data To Save\n"));
         using (StreamWriter streamWriter = new StreamWriter(pathFileNameStr))
         {
             int count = csvData.Count;
             string str1 = string.Empty;
             DeviceTabsForm.CsvData csvData1 = new DeviceTabsForm.CsvData();
             for (int index = 0; index < count; ++index)
             {
                 DeviceTabsForm.CsvData csvData2 = csvData[index];
                 streamWriter.WriteLine(string.Format("{0:S},{1:S},{2:S},{3:S},{4:S}", csvData2.addr, csvData2.auth, csvData2.ltk, csvData2.div, csvData2.rand));
             }
         }
     }
     catch (Exception ex)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Write The CSV File\n\n{0}\n", ex.Message));
         flag = true;
     }
     return flag;
 }
Example #2
0
 private bool AddToEndCsv(DeviceTabsForm.CsvData newCsvData, ref List<DeviceTabsForm.CsvData> csvData)
 {
     bool flag = false;
     try
     {
         if (newCsvData == null)
             throw new ArgumentException(string.Format("There Is No Data To Add.\n"));
         DeviceTabsForm.CsvData csvData1 = new DeviceTabsForm.CsvData();
         csvData.Add(new DeviceTabsForm.CsvData()
         {
             addr = newCsvData.addr,
             auth = newCsvData.auth,
             ltk = newCsvData.ltk,
             div = newCsvData.div,
             rand = newCsvData.rand
         });
     }
     catch (Exception ex)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Add Data To End Of The CSV List.\n\n{0}\n", ex.Message));
         flag = true;
     }
     return flag;
 }
Example #3
0
 private bool ReplaceAddrDataInCsv(DeviceTabsForm.CsvData newCsvData, ref List<DeviceTabsForm.CsvData> csvData, int csvIndex)
 {
     bool flag = false;
     try
     {
         if (csvData == null || csvData.Count <= 0)
             throw new ArgumentException(string.Format("There Is No Csv Data To Replace\n"));
         DeviceTabsForm.CsvData csvData1 = new DeviceTabsForm.CsvData();
         DeviceTabsForm.CsvData csvData2 = csvData[csvIndex];
         if (csvData2.addr != newCsvData.addr)
             throw new ArgumentException(string.Format("The Addresses Do Not Match\nCSV Replace Is Cancelled\nExpected {0:S}\nFound {1:S}\n", csvData2.addr, newCsvData.addr));
         csvData2.addr = newCsvData.addr;
         csvData2.auth = newCsvData.auth;
         csvData2.ltk = newCsvData.ltk;
         csvData2.div = newCsvData.div;
         csvData2.rand = newCsvData.rand;
         csvData[csvIndex] = csvData2;
     }
     catch (Exception ex)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Access The Data To Replace The Addr In The CSV List\n\n{0}\n", ex.Message));
         flag = true;
     }
     return flag;
 }
Example #4
0
 private List<DeviceTabsForm.CsvData> ReadCsv(string pathFileNameStr, ref bool fileError)
 {
     List<DeviceTabsForm.CsvData> list = new List<DeviceTabsForm.CsvData>();
     fileError = false;
     try
     {
         if (pathFileNameStr == null)
             throw new ArgumentException(string.Format("There Is No Filename And/Or Path For Reading Csv Data.\n"));
         using (StreamReader streamReader = new StreamReader(pathFileNameStr))
         {
             string str1 = string.Empty;
             int num = 0;
             string str2;
             while ((str2 = streamReader.ReadLine()) != null)
             {
                 ++num;
                 string[] strArray = str2.Split(new char[1] { ',' });
                 if (strArray.Length != CsvNumberOfLineElements)
                     throw new ArgumentException(string.Format("Not Enough Data Items On Line {0:D}\nExpected {1:D} Data Items On Each Line.\n", num, CsvNumberOfLineElements));
                 for (int index = 0; index < CsvNumberOfLineElements; ++index)
                 {
                     strArray[index] = strArray[index].Trim();
                     strArray[index] = strArray[index].Replace("\"", "");
                 }
                 DeviceTabsForm.CsvData csvData = new DeviceTabsForm.CsvData();
                 list.Add(new DeviceTabsForm.CsvData()
                 {
                     addr = strArray[0],
                     auth = strArray[1],
                     ltk = strArray[2],
                     div = strArray[3],
                     rand = strArray[4]
                 });
             }
         }
     }
     catch (Exception ex)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Load Or Parse The CSV File.\n\n{0}\n", ex.Message));
         fileError = true;
     }
     return list;
 }
Example #5
0
 private bool FindAddrInCsv(string addr, List<DeviceTabsForm.CsvData> csvData, ref int csvIndex)
 {
     bool flag = false;
     csvIndex = -1;
     try
     {
         if (addr == null || csvData == null || csvData.Count <= 0)
         {
             csvIndex = -1;
             return flag;
         }
         else
         {
             int count = csvData.Count;
             DeviceTabsForm.CsvData csvData1 = new DeviceTabsForm.CsvData();
             for (int index = 0; index < count; ++index)
             {
                 if (csvData[index].addr == addr)
                 {
                     csvIndex = index;
                     break;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Access The Data To Find The Addr In The CSV List\n\n{0}\n", ex.Message));
         flag = true;
     }
     return flag;
 }
Example #6
0
 private void btnSaveLongTermKey_Click(object sender, EventArgs e)
 {
     SaveFileDialog saveFileDialog = new SaveFileDialog();
     saveFileDialog.Filter = "Text Files|*.txt";
     saveFileDialog.Title = "Select a Long-Term Key Data File To Save";
     bool fileError = false;
     if (saveFileDialog.ShowDialog() != DialogResult.OK)
         return;
     csvKeyData.Clear();
     if (File.Exists(saveFileDialog.FileName))
         csvKeyData = ReadCsv(saveFileDialog.FileName, ref fileError);
     ConnectInfo connectInfo = devForm.GetConnectInfo();
     DeviceTabsForm.CsvData newCsvData = new DeviceTabsForm.CsvData();
     newCsvData.addr = connectInfo.BDA;
     newCsvData.auth = lastAuthStr;
     newCsvData.ltk = lastGAP_AuthenticationComplete.devSecInfo_LTK;
     newCsvData.div = Convert.ToString((int)lastGAP_AuthenticationComplete.devSecInfo_DIV, 16).ToUpper();
     newCsvData.rand = lastGAP_AuthenticationComplete.devSecInfo_RAND;
     if (newCsvData.addr == null || newCsvData.addr.Length == 0)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Connection Address Is Invalid\nDevice Must Be Connected To Save Data\n"));
     }
     else
     {
         int csvIndex = -1;
         if (FindAddrInCsv(newCsvData.addr, csvKeyData, ref csvIndex))
             return;
         if (csvIndex == -1)
         {
             if (AddToEndCsv(newCsvData, ref csvKeyData))
                 return;
         }
         else if (ReplaceAddrDataInCsv(newCsvData, ref csvKeyData, csvIndex))
             return;
         fileError = WriteCsv(saveFileDialog.FileName, csvKeyData);
         int num = fileError ? 1 : 0;
     }
 }
Example #7
0
 private void btnLoadLongTermKey_Click(object sender, EventArgs e)
 {
     OpenFileDialog openFileDialog = new OpenFileDialog();
     openFileDialog.Filter = "Text Files|*.txt";
     openFileDialog.Title = "Select a Long-Term Key Data File To Load";
     bool fileError = false;
     string str = (string)null;
     if (openFileDialog.ShowDialog() == DialogResult.OK && devForm.numConnections > 1)
     {
         List<string> dataItems = new List<string>();
         for (int index = 0; index < devForm.Connections.Count; ++index)
             dataItems.Add(devForm.Connections[index].BDA);
         listSelectForm.LoadFormData(dataItems);
         int num = (int)listSelectForm.ShowDialog();
         if (listSelectForm.DialogResult != DialogResult.OK)
             return;
         str = listSelectForm.GetUserSelection();
     }
     csvKeyData.Clear();
     csvKeyData = ReadCsv(openFileDialog.FileName, ref fileError);
     if (fileError)
         return;
     ConnectInfo connectInfo = devForm.GetConnectInfo();
     DeviceTabsForm.CsvData csvData1 = new DeviceTabsForm.CsvData();
     csvData1.addr = devForm.numConnections <= 1 ? connectInfo.BDA : str;
     if (csvData1.addr == null || csvData1.addr.Length == 0)
     {
         msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Connection Address Is Invalid\nA Device Must Be Connected To Read Data\n"));
     }
     else
     {
         int csvIndex = -1;
         if (FindAddrInCsv(csvData1.addr, csvKeyData, ref csvIndex))
             return;
         if (csvIndex == -1)
         {
             msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, string.Format("Cannot Find The Device Address In The Specified File\nSearch Address = {0:S}\nNo Data Was Loaded.\n", csvData1.addr));
         }
         else
         {
             DeviceTabsForm.CsvData csvData2 = csvKeyData[csvIndex];
             if (csvData2.auth == "TRUE")
             {
                 rbAuthBondTrue.Checked = true;
                 rbAuthBondFalse.Checked = false;
             }
             else
             {
                 rbAuthBondTrue.Checked = false;
                 rbAuthBondFalse.Checked = true;
             }
             tbLongTermKey.Text = csvData2.ltk;
             tbLTKDiversifier.Text = csvData2.div;
             tbLTKRandom.Text = csvData2.rand;
         }
     }
 }