public void ReadCompressedZip(string filepath) { while (BackgroundWriting) ; ZipInputStream instream = new ZipInputStream(filepath); BinaryFormatter formatter = new BinaryFormatter(); instream.GetNextEntry(); searchDump = new TCPTCPGecko.Dump((uint)formatter.Deserialize(instream), (uint)formatter.Deserialize(instream)); instream.Read(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress)); instream.GetNextEntry(); resultsList = (System.Collections.Generic.List<UInt32>)formatter.Deserialize(instream); instream.Close(); instream.Dispose(); }
public void SaveSearchBackground(int index, List<UInt32> resultsList, Dump searchDump) { SearchItem foo = new SearchItem(); // make a copy in case the user starts deleting, sorting, etc the original list foo.resultsList = new List<uint>(resultsList); foo.searchDump = searchDump; foo.index = index; // block in the event of a rapid-fire double call while (backgroundWriting) ; Thread zipThread = new Thread(new ParameterizedThreadStart(SaveSearchBackground)); // Set the state before calling the thread backgroundWriting = true; zipThread.Start(foo); }
public SearchHistoryItem() { resultsList = null; searchDump = null; backgroundWriting = false; }
public void SaveSearch(string filepath, List<UInt32> resultsList, Dump searchDump) { ZipOutputStream outstream = new ZipOutputStream(filepath); outstream.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed; BinaryFormatter formatter = new BinaryFormatter(); // First entry is the dump outstream.PutNextEntry("dump"); //DateTime start = Logger.WriteLineTimedStarted("compressing search dump"); // Must put the addresses first, so that it can derive the right number of bytes to read for the dump formatter.Serialize(outstream, searchDump.StartAddress); formatter.Serialize(outstream, searchDump.EndAddress); outstream.Write(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress)); //Logger.WriteLineTimedFinished("compressing search dump", start); // Second entry is the list outstream.PutNextEntry("list"); //start = Logger.WriteLineTimedStarted("compressing search list"); formatter.Serialize(outstream, resultsList); //Logger.WriteLineTimedFinished("compressing search list", start); outstream.Close(); outstream.Dispose(); }
public void SaveSearch(int index, List<UInt32> resultsList, Dump searchDump) { // TODO subdir? check file exists? char delim = Path.DirectorySeparatorChar; SaveSearch("DumpHistory" + delim + "DumpHistory" + index + ".zip", resultsList, searchDump); }
public Dump LoadSearchDump(string filepath) { // spin while background writing to prevent us from reading a file that has yet to be written while (BackgroundWriting) ; ZipInputStream instream = new ZipInputStream(filepath); BinaryFormatter formatter = new BinaryFormatter(); // First entry is the dump instream.GetNextEntry(); Dump searchDump = new Dump((uint)formatter.Deserialize(instream), (uint)formatter.Deserialize(instream)); instream.Read(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress)); instream.Close(); instream.Dispose(); return searchDump; }
public void Dump(UInt32 startdump, UInt32 enddump, Dump memdump) { //Reset connection InitGecko(); //How many bytes of data have to be transferred UInt32 memlength = enddump - startdump; //How many chunks do I need to split this data into //How big ist the last chunk UInt32 fullchunks = memlength / packetsize; UInt32 lastchunk = memlength % packetsize; //How many chunks do I need to transfer UInt32 allchunks = fullchunks; if (lastchunk > 0) allchunks++; UInt64 GeckoMemRange = ByteSwap.Swap((UInt64)(((UInt64)startdump << 32) + ((UInt64)enddump))); if (GeckoWrite(BitConverter.GetBytes(cmd_readmem), 1) != FTDICommand.CMD_OK) throw new ETCPGeckoException(ETCPErrorCode.FTDICommandSendError); //Read reply - expcecting GCACK -- nope, too slow, TCP is reliable! Byte retry = 0; /*while (retry < 10) { Byte[] response = new Byte[1]; if (GeckoRead(response, 1) != FTDICommand.CMD_OK) throw new ETCPGeckoException(ETCPErrorCode.FTDIReadDataError); Byte reply = response[0]; if (reply == GCACK) break; if (retry == 9) throw new ETCPGeckoException(ETCPErrorCode.FTDIInvalidReply); }*/ //Now let's send the dump information if (GeckoWrite(BitConverter.GetBytes(GeckoMemRange), 8) != FTDICommand.CMD_OK) throw new ETCPGeckoException(ETCPErrorCode.FTDICommandSendError); //We start with chunk 0 UInt32 chunk = 0; retry = 0; // Reset cancel flag bool done = false; CancelDump = false; Byte[] buffer = new Byte[packetsize]; //read buffer //GeckoApp.SubArray<Byte> buffer; while (chunk < fullchunks && !done) { //buffer = new SubArray<byte>(mem, chunk*packetsize, packetsize); //No output yet availible SendUpdate(startdump + chunk * packetsize, chunk, allchunks, chunk * packetsize, memlength, retry == 0, true); //Set buffer Byte[] response = new Byte[1]; if (GeckoRead(response, 1) != FTDICommand.CMD_OK) { //Major fail, give it up GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); throw new ETCPGeckoException(ETCPErrorCode.FTDIReadDataError); } Byte reply = response[0]; if (reply == BlockZero) { for (int i = 0; i < packetsize; i++) { buffer[i] = 0; } } else { FTDICommand returnvalue = GeckoRead(buffer, packetsize); if (returnvalue == FTDICommand.CMD_ResultError) { retry++; if (retry >= 3) { //Give up, too many retries GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); throw new ETCPGeckoException(ETCPErrorCode.TooManyRetries); } //GeckoWrite(BitConverter.GetBytes(GCRETRY), 1); continue; } else if (returnvalue == FTDICommand.CMD_FatalError) { //Major fail, give it up GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); throw new ETCPGeckoException(ETCPErrorCode.FTDIReadDataError); } } //write received package to output stream //foreach (Stream stream in saveStream) //{ // stream.Write(buffer, 0, ((Int32)packetsize)); //} Buffer.BlockCopy(buffer, 0, memdump.mem, (int)(chunk * packetsize + (startdump - memdump.StartAddress)), (int)packetsize); memdump.ReadCompletedAddress = (UInt32)((chunk + 1) * packetsize + startdump); //reset retry counter retry = 0; //next chunk chunk++; if (!CancelDump) { //ackowledge package -- nope, too slow, TCP is reliable! //GeckoWrite(BitConverter.GetBytes(GCACK), 1); } else { // User requested a cancel GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); done = true; } } //Final package? while (!done && lastchunk > 0) { //buffer = new SubArray<byte>(mem, chunk * packetsize, lastchunk); //No output yet availible SendUpdate(startdump + chunk * packetsize, chunk, allchunks, chunk * packetsize, memlength, retry == 0, true); //Set buffer // buffer = new Byte[lastchunk]; Byte[] response = new Byte[1]; if (GeckoRead(response, 1) != FTDICommand.CMD_OK) { //Major fail, give it up GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); throw new ETCPGeckoException(ETCPErrorCode.FTDIReadDataError); } Byte reply = response[0]; if (reply == BlockZero) { for (int i = 0; i < lastchunk; i++) { buffer[i] = 0; } } else { FTDICommand returnvalue = GeckoRead(buffer, lastchunk); if (returnvalue == FTDICommand.CMD_ResultError) { retry++; if (retry >= 3) { //Give up, too many retries GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); throw new ETCPGeckoException(ETCPErrorCode.TooManyRetries); } //GeckoWrite(BitConverter.GetBytes(GCRETRY), 1); continue; } else if (returnvalue == FTDICommand.CMD_FatalError) { //Major fail, give it up GeckoWrite(BitConverter.GetBytes(GCFAIL), 1); throw new ETCPGeckoException(ETCPErrorCode.FTDIReadDataError); } } //write received package to output stream //foreach (Stream stream in saveStream) //{ // stream.Write(buffer, 0, ((Int32)lastchunk)); //} Buffer.BlockCopy(buffer, 0, memdump.mem, (int)(chunk * packetsize + (startdump - memdump.StartAddress)), (int)lastchunk); //reset retry counter retry = 0; //cancel while loop done = true; //ackowledge package -- nope, too slow, TCP is reliable! //GeckoWrite(BitConverter.GetBytes(GCACK), 1); } SendUpdate(enddump, allchunks, allchunks, memlength, memlength, true, true); }
public void Dump(Dump dump) { //Stream[] tempStream = { dump.dumpStream, dump.getOutputStream() }; //Stream[] tempStream = { dump.dumpStream }; //Dump(dump.startAddress, dump.endAddress, tempStream); //dump.getOutputStream().Dispose(); //dump.WriteStreamToDisk(); Dump(dump.StartAddress, dump.EndAddress, dump); }