long recover_par_segment(string par_head_i, FileStream candRecStream, long sos_point) { long lastPosition = 0; long maxLastPosition = 0; int maxHuffmanIndex = 1; Program p; for (int i = 1; i < 2; i++) { try { Huffman.switchHuffman(i); p = new Program(par_head_i + "_" + i, candRecStream, sos_point); p.startDecoding(); //if (p.startDecoding()) //{ lastPosition = p.finalizeDecoding(); if (maxLastPosition < lastPosition) { maxLastPosition = lastPosition; maxHuffmanIndex = i; } //} } catch (Exception e) { Console.WriteLine(e.Message); } } try { if (maxHuffmanIndex < 2) { Huffman.switchHuffman(maxHuffmanIndex); p = new Program(par_head_i + "_" + maxHuffmanIndex, candRecStream, sos_point); p.startDecoding(); return(p.finalizeDecoding()); } } catch (Exception e) { Console.WriteLine(e.Message); } lastPosition = candRecStream.Position; return(lastPosition); }
static void Main(string[] args) { MainClass m = new MainClass(); Huffman.switchHuffman(1); Program p; OpenFileDialog openfiledialog1 = new OpenFileDialog(); openfiledialog1.InitialDirectory = @"e:\"; // int counter = m.initializeorphanedfragments(openfiledialog1.FileName); // m.recoverOrphanedFragments(counter, ""); Stopwatch watch = Stopwatch.StartNew(); //p = new Program(openfiledialog1.FileName); Console.WriteLine("Which procedure would you like to run(1-3)?"); string input = Console.ReadLine(); int choice; Int32.TryParse(input, out choice); if (choice == 1) { /* * Procedure 1- Recover single jpeg encoded data. * */ //String basePath = "G:\\HBKU\\QCRIInternship\\dfrws-2007-challenge\\dfrws-2007-challenge.img"; Console.WriteLine("Enter image fragment file path: "); string basePath = Console.ReadLine(); Procedures procedures = new Procedures(); var result = procedures.procedure_1(basePath); Console.WriteLine(result.Item1); //End of Procedure 1 } else if (choice == 2) { ///* // * Procedure 2- Recover whole storage volume. // * // */ //String basePath = "G:\\HBKU\\QCRIInternship\\dfrws-2007-challenge\\dfrws-2007-challenge.img"; Console.WriteLine("Enter full file path: "); string basePath = Console.ReadLine(); Procedures procedures = new Procedures(); var result = procedures.procedure_2(basePath); Console.WriteLine(result.Item1); //End of Procedure 2 } else if (choice == 3) { //Procedure 3: Network Packets //String packetPath = @"G:\HBKU\QCRIInternship\pcap.pcap"; Console.WriteLine("Enter network(pcap) file path: "); string basePath = Console.ReadLine(); Procedures procedures = new Procedures(); var result = procedures.procedure_3(basePath); Console.WriteLine(result.Item1); //End Procedure 3 } else { Console.WriteLine("Not valid choice"); } /* * foreach (var stream in memoryStreams) * { * stream.Dispose(); * } * memoryStreams.Clear(); * * if (memoryStream == null) * { * Console.WriteLine("Error - Memory stream is null"); * } * FileStream fileStream = new FileStream(packetPathTemp, FileMode.Create, FileAccess.Write); * memoryStream.CopyTo(fileStream); * memoryStream.Close(); * fileStream.Close(); * * fileStream = new FileStream(packetPathTemp, FileMode.Open); * bool isJpeg = preCheck.isJpeg(fileStream); * Console.WriteLine("Is Jpeg File?: " + isJpeg); * * fileStream.Seek(0, SeekOrigin.Begin); * var sos = preCheck.get_sos_cnt_and_point(fileStream); * int sos_index = sos.Item1; // which SOS code is hit * long sos_point = sos.Item2; // point of encoded data starts. go ahead and recover consequent jpeg * if (sos_index == -1) * { * Console.WriteLine("SOS marker not found"); * } * else * { * Console.WriteLine("SOS marker exists at:" + sos_point); * } * fileStream.Close(); * * p = new Program(packetPathTemp); * m.recoverSegment(packetPathTemp, p); */ ////m.recoverSegment(openfiledialog1.FileName, p); //Console.WriteLine(" Hell Yeah!!"); // //p.startDecoding(); // //p.finalizeDecoding(); //watch.Stop(); //Console.WriteLine(watch.Elapsed); //DialogResult result = openfiledialog1.ShowDialog(); //if (result == DialogResult.OK) // test result. //{ //} //for (int i = 1; i < 26; i++) //{ // String basePath = Global.recOrphanDir + i + "\\img_"; // int counter = m.initializeOrphanedFragments(Global.recOrphanDir + i + ".raw", basePath); // m.recoverOrphanedFragments(counter, basePath); // Console.WriteLine(i + " Done!!"); //} //// partial header //for (int i = 4; i < 26; i++) //{ // m.process_sd_par_head(i); //} //for (int i = 1; i < 2; i++) //{ // m.process_sd_non_head(i); // m.print_stats(); //} //m.process_sd_non_head(2); //m.print_stats(); DateTime dt = DateTime.Now; //m.process_sd_par_head(1); //m.process_sd_non_head(1); TimeSpan ts = DateTime.Now - dt; //m.print_stats(); Console.WriteLine("time: " + ts.TotalMilliseconds.ToString()); Console.ReadLine(); }
static void Main(string[] args) { MainClass m = new MainClass(); Huffman.switchHuffman(1); /* * Procedur 1- Recover single jpeg encoded data. * */ //Program p; //OpenFileDialog openFileDialog1 = new OpenFileDialog(); //openFileDialog1.InitialDirectory = @"E:\"; //DialogResult result = openFileDialog1.ShowDialog(); //if (result == DialogResult.OK) // Test result. //{ // int counter = m.initializeOrphanedFragments(openFileDialog1.FileName); // m.recoverOrphanedFragments(counter); // //Stopwatch watch = Stopwatch.StartNew(); // //p = new Program(openFileDialog1.FileName); // //p.startDecoding(); // //watch.Stop(); // //Console.WriteLine(watch.Elapsed); //} ///* // * Procedur 2- Recover whole storage volume. // * // */ //for (int i = 1; i < 26; i++) //{ // String basePath = Global.recOrphanDir + i + "\\img_"; // int counter = m.initializeOrphanedFragments(Global.recOrphanDir + i + ".raw", basePath); // m.recoverOrphanedFragments(counter, basePath); // Console.WriteLine(i+" Done!!"); //} //// partial header //for (int i = 4; i < 26; i++) //{ // m.process_sd_par_head(i); //} //for (int i = 1; i < 2; i++) //{ // m.process_sd_non_head(i); // m.print_stats(); //} //m.process_sd_non_head(2); //m.print_stats(); DateTime dt = DateTime.Now; //m.process_sd_par_head(1); m.process_sd_non_head(1); TimeSpan ts = DateTime.Now - dt; m.print_stats(); Console.WriteLine("time: " + ts.TotalMilliseconds.ToString()); Console.ReadLine(); }