public long recoverSegment(string file, Program p) { long recLength = 0; try { int dhtID = 1; Huffman.switchHuffman(dhtID); Console.WriteLine("HuffmanID" + dhtID); if (p.startDecoding()) { //first dht is ok return(p.finalizeDecoding()); } Program p2to7 = new Program(file); Huffman.switchHuffman(2); int maxdhtID = Huffman.maxDhtID; while (!p2to7.startDecoding() && dhtID < 8) { dhtID++; Console.WriteLine("HuffmanID" + dhtID); Huffman.switchHuffman(dhtID); p = new Program(file); } // if all is consumed, then, return 1st dht (the standard table) recLength = (dhtID == 8) ? p.finalizeDecoding() : p2to7.finalizeDecoding(); } catch (Exception e) { } return(recLength); }
/* * Procedure 1- Recover single jpeg encoded data. * */ public Tuple <String, String> procedure_1(String rawPath) { String outFile = "" + rawPath + ".jpg"; Console.WriteLine("Running Procedure 1"); if (!File.Exists(rawPath)) { String msg = "Error - File does not exists."; return(Tuple.Create(outFile, msg)); } Procedures main = new Procedures(); Huffman.switchHuffman(1); Stopwatch watch = Stopwatch.StartNew(); //String rawPath = @"C:\Users\Ahmad\Desktop\QCRIInternship\Code\jpeg-carver-csharp-master\Dataset\Original\deagon_test_4kib"; //Check if file is jpeg or not FileStream tempFileStream = new FileStream(rawPath, FileMode.Open); //Reading stream changes position, retain original long cpoint = tempFileStream.Position; bool isJpeg = preCheck.isJpeg(tempFileStream); tempFileStream.Position = cpoint; Console.WriteLine("Is Jpeg File?: " + isJpeg); //Check if jpeg partial headers exist utils.recoverHuffmanHdr(tempFileStream); tempFileStream.Close(); Program p = new Program(rawPath); utils.recoverSegment(rawPath, p); //Console.WriteLine(" Hell Yeah!!"); watch.Stop(); Console.WriteLine(watch.Elapsed); //Console.ReadLine(); return(Tuple.Create(outFile, "Success")); }