static void Main(string[] args) { string[] szInputFile = new string[1]; szInputFile[0] = ""; string szOutputFile = ""; Boolean bExitFlag = false; if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); } else { if (args.Length != 4 || (args[0] == "-f" && args[2] != "-o") || (args[0] == "-o" && args[2] != "-f")) { const string message = "Error in format, Enter as in format below:\n" + "Eg. FoxmailRecovery.exe -f [filename1];[filename2]...[filenameN] -o [outputfilepath]\n" + "Eg. FoxmailRecovery.exe -o [outputfilepath] -f [filename1];[filename2]...[filenameN]"; MessageBox.Show(message, "Error in format", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Boolean bLoop = true; string[] szTemp = new string[1]; szTemp[0] = null; for (int i = 0; i < 4; i++) { if (args[i].Equals("-f") && !args[i + 1].Equals("-o")) { szInputFile = args[i + 1].Split(';'); foreach (string input in szInputFile) { if (File.Exists(input)) { if (bLoop) { szTemp[0] = input; bLoop = false; } else { string[] szBuffer = new string[szTemp.Length + 1]; Array.Copy(szTemp, 0, szBuffer, 0, szTemp.Length); szBuffer[szTemp.Length] = input; szTemp = null; szTemp = szBuffer; szBuffer = null; } } } szInputFile = szTemp; i++; } else if (args[i].Equals("-o") && !args[i + 1].Equals("-f")) { //string directory; if (File.Exists(args[i + 1])) { var result = MessageBox.Show("File exist!, Do you want to overwrite?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { szOutputFile = args[i + 1]; } else { szOutputFile = "1"; } } else { if (args[i + 1].EndsWith(".csv")) { szOutputFile = String.Format(@"{0}\{1}", Application.StartupPath, args[i + 1]); } else { szOutputFile = "2"; } } } } if (szInputFile[0] == "") { MessageBox.Show("Invalid input(s)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); bExitFlag = true; } else { if (szOutputFile == "") { MessageBox.Show("Invalid output", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); bExitFlag = true; } else { if (szOutputFile == "1") { MessageBox.Show("Please enter a different output file name", "Renter", MessageBoxButtons.OK, MessageBoxIcon.Information); bExitFlag = true; } else if (szOutputFile == "2") { MessageBox.Show("Invalid output file format", "File format", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); bExitFlag = true; } } } if (!bExitFlag) { List <SharedFunctions.CsvRow> csvContent = new List <SharedFunctions.CsvRow>(); foreach (string word in szInputFile) { // Read the file into <bits> var fs = new FileStream(@word, FileMode.Open); var len = (int)fs.Length; var bits = new byte[len]; bool accfound = false; string tempstring = ""; int ver = 0; SharedFunctions.UserInfo test = new SharedFunctions.UserInfo(); List <SharedFunctions.UserInfo> userInfo = new List <SharedFunctions.UserInfo>(); fs.Read(bits, 0, len); if (bits[0] == 0xD0) { ver = 0; } else { ver = 1; } // Extract readable character from file for (int jx = 0; jx < len; ++jx) { // If it's within range of ascii alphanumerics if (bits[jx] > 0x20 && bits[jx] < 0x7f && bits[jx] != 0x3d) { // Form word from each character for checking tempstring += (char)bits[jx]; //Loop to extract data if the formed word is "Account" or "POP3Account" if (tempstring.Equals("Account") || tempstring.Equals("POP3Account")) { int index = jx + 9; if (ver == 0) { index = jx + 2; } while (bits[index] > 0x20 && bits[index] < 0x7f) { test.acc += (char)bits[index]; index++; } accfound = true; jx = index; } //Loop to extract data if the formed word is "Password" or "POP3Password" else if (accfound && (tempstring.Equals("Password") || tempstring.Equals("POP3Password"))) { int index = jx + 9; if (ver == 0) { index = jx + 2; } string pw = ""; while (bits[index] > 0x20 && bits[index] < 0x7f) { pw += (char)bits[index]; index++; } if (pw != "") { test.password = SharedFunctions.decodePW(ver, pw); } else { test.password = "******"; } bool duplicate = false; // Check for duplicate entry foreach (SharedFunctions.UserInfo user in userInfo) { if (user.acc.Equals(test.acc) && user.password.Equals(test.password)) { duplicate = true; break; } } if (!duplicate) { userInfo.Add(test); duplicate = false; } test = null; test = new SharedFunctions.UserInfo(); accfound = false; jx = index; } } else { tempstring = ""; } } // Add into csv object from output file foreach (SharedFunctions.UserInfo user in userInfo) { SharedFunctions.CsvRow row = new SharedFunctions.CsvRow(); row.Add(user.acc); row.Add(user.password); row.Add(word); csvContent.Add(row); } fs.Close(); } // Write file into csv file using (SharedFunctions.CsvFileWriter writer = new SharedFunctions.CsvFileWriter(szOutputFile)){ foreach (SharedFunctions.CsvRow r in csvContent) { writer.WriteRow(r); } } } } } }
// Handler after the drag and drop private void frmMain_DragDrop(object sender, DragEventArgs e) { //Clear previous print out txtData.Clear(); //Get the files that have been dragged and drop string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; foreach (string word in fileList) { // Read the file into <bits> var fs = new FileStream(@word, FileMode.Open); var len = (int)fs.Length; var bits = new byte[len]; bool accfound = false; string buffer = ""; int ver = 0; SharedFunctions.UserInfo userInfo = new SharedFunctions.UserInfo(); List <SharedFunctions.UserInfo> userInfoList = new List <SharedFunctions.UserInfo>(); String finaloutput = "------------------------------------------------------------------\r\n"; finaloutput += "From file: " + word + " \r\n"; finaloutput += "------------------------------------------------------------------\r\n"; fs.Read(bits, 0, len); // Check if the file version if (bits[0] == 0xD0) { // Version 6.X ver = 0; } else { // Version 7.0 and 7.1 ver = 1; } // Loop to filter out non alphanumeric characters. Form word from individual character // to see if it is the interested data for (int jx = 0; jx < len; ++jx) { // Filter out not alphanumeric character if (bits[jx] > 0x20 && bits[jx] < 0x7f && bits[jx] != 0x3d) { // Concat to from word buffer += (char)bits[jx]; // Check if the next word is going to the user account if (buffer.Equals("Account") || buffer.Equals("POP3Account")) { // Offset int index = jx + 9; // Additional offset required for version 6.5 if (ver == 0) { index = jx + 2; } // Loop till the entire data is extracted // (Data is in alphanumeric character, non alphanumeric mean end of data) while (bits[index] > 0x20 && bits[index] < 0x7f) { userInfo.acc += (char)bits[index]; index++; } // Flag to indicate account found accfound = true; // Shift the current "pointer" to the end index of the data jx = index; } // If there is an user account, check for its password else if (accfound && (buffer.Equals("Password") || buffer.Equals("POP3Password"))) { int index = jx + 9; if (ver == 0) { index = jx + 2; } string pw = ""; while (bits[index] > 0x20 && bits[index] < 0x7f) { pw += (char)bits[index]; index++; } if (pw != "") { userInfo.password = SharedFunctions.decodePW(ver, pw); } else { userInfo.password = "******"; } bool duplicate = false; //Check for duplicate data before inserting into userInfoList foreach (SharedFunctions.UserInfo user in userInfoList) { if (user.acc.Equals(userInfo.acc) && user.password.Equals(userInfo.password)) { duplicate = true; break; } } if (!duplicate) { userInfoList.Add(userInfo); duplicate = false; } userInfo = null; userInfo = new SharedFunctions.UserInfo(); accfound = false; jx = index; } } else { buffer = ""; } } bool empty = true; // Loop to output data foreach (SharedFunctions.UserInfo user in userInfoList) { SharedFunctions.CsvRow row = new SharedFunctions.CsvRow(); finaloutput += "Account : " + user.acc + "\r\nPassword : "******"\r\n\r\n"; row.Add(user.acc); row.Add(user.password); row.Add(word); csvContent.Add(row); btnExport.Enabled = true; empty = false; } if (empty) { finaloutput += "Empty\r\n\r\n"; } txtData.AppendText(finaloutput); fs.Close(); } }