Exemple #1
0
        public virtual void SaveAsync(Dump dump, DumpFormat format, Stream stream, object taskId)
        {
            SaveInfo info = new SaveInfo(dump, format, stream);

            AsyncOperation asyncOp = CreateOperation(taskId);

            m_workerDelegate = new WorkerEventHandler(SaveWorker);
            m_workerDelegate.BeginInvoke(info, asyncOp, m_completionMethodDelegate, null, null);
        }
Exemple #2
0
 private void ReadAndVerifyBody(Stream stream, DumpFormat dumpFormat)
 {
     XmlDocument doc = new XmlDocument();
     if (dumpFormat == DumpFormat.Compressed)
         stream = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(stream);
     doc.Load(stream);
     Assert.That(doc.DocumentElement.ChildNodes.Count, Is.EqualTo(3));
     Assert.That(doc.DocumentElement.ChildNodes.Item(0).OuterXml,
                 Is.EqualTo(XmlString.Canonicalize(TestEventXml.E001_Error)));
     Assert.That(doc.DocumentElement.ChildNodes.Item(1).OuterXml,
                 Is.EqualTo(XmlString.Canonicalize(TestEventXml.E083_CreateSocket)));
     Assert.That(doc.DocumentElement.ChildNodes.Item(2).OuterXml,
                 Is.EqualTo(XmlString.Canonicalize(TestEventXml.E084_Connect)));
 }
Exemple #3
0
 private void ReadAndVerifyHeader(BinaryReader reader, DumpFormat dumpFormat)
 {
     string magic = new string(reader.ReadChars(4));
     uint version = reader.ReadUInt32();
     uint isCompressed = reader.ReadUInt32();
     uint numEvents = reader.ReadUInt32();
     Assert.That(magic, Is.EqualTo("oSpy"));
     Assert.That(version, Is.EqualTo(2));
     if (dumpFormat == DumpFormat.Compressed)
         Assert.That(isCompressed, Is.EqualTo(1));
     else
         Assert.That(isCompressed, Is.EqualTo(0));
     Assert.That(numEvents, Is.EqualTo(3));
 }
Exemple #4
0
 void dumpData(FileStream fs, DumpFormat fmt, string prefix, ArraySegment <byte> data)
 {
     if (fmt == DumpFormat.Binary)
     {
         fs.Write(data.Array, data.Offset, data.Count);
     }
     else
     {
         string s = (string.IsNullOrEmpty(prefix) ? string.Empty : prefix)
                    + data.Array.ToDumpString(fmt, data.Offset, data.Count, true);
         var b = Encoding.ASCII.GetBytes(s);
         fs.Write(b, 0, b.Length);
     }
 }
Exemple #5
0
        private void SaveAndLoadFullCycle(DumpFormat dumpFormat)
        {
            DumpSaver    saver         = new DumpSaver();
            MemoryStream outStream     = new MemoryStream();
            Dump         canonicalDump = GenerateTestDump();

            saver.Save(canonicalDump, dumpFormat, outStream);

            DumpLoader loader     = new DumpLoader();
            Dump       loadedDump = loader.Load(new MemoryStream(outStream.ToArray()));

            foreach (KeyValuePair <uint, Event> entry in loadedDump.Events)
            {
                Assert.That(entry.Value.RawData, Is.EqualTo(canonicalDump.Events[entry.Key].RawData));
            }
        }
Exemple #6
0
        private void SaveAndVerifyOutput(DumpFormat dumpFormat)
        {
            DumpSaver saver = new DumpSaver();
            MemoryStream outstream = new MemoryStream();
            Dump dump = GenerateTestDump();
            saver.Save(dump, dumpFormat, outstream);
            byte[] buffer = outstream.ToArray();

            Stream stream = new MemoryStream(buffer);
            BinaryReader reader = new BinaryReader(stream);

            ReadAndVerifyHeader(reader, dumpFormat);
            ReadAndVerifyBody(stream, dumpFormat);

            Assert.That(stream.Position, Is.EqualTo(stream.Length),
                         "Should not be any trailing data");
        }
Exemple #7
0
        private void ReadAndVerifyBody(Stream stream, DumpFormat dumpFormat)
        {
            XmlDocument doc = new XmlDocument();

            if (dumpFormat == DumpFormat.Compressed)
            {
                stream = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(stream);
            }
            doc.Load(stream);
            Assert.That(doc.DocumentElement.ChildNodes.Count, Is.EqualTo(3));
            Assert.That(doc.DocumentElement.ChildNodes.Item(0).OuterXml,
                        Is.EqualTo(XmlString.Canonicalize(TestEventXml.E001_Error)));
            Assert.That(doc.DocumentElement.ChildNodes.Item(1).OuterXml,
                        Is.EqualTo(XmlString.Canonicalize(TestEventXml.E083_CreateSocket)));
            Assert.That(doc.DocumentElement.ChildNodes.Item(2).OuterXml,
                        Is.EqualTo(XmlString.Canonicalize(TestEventXml.E084_Connect)));
        }
Exemple #8
0
        private DumpFormat ParseDumpFormat(string format, DumpFormat defaultFormat)
        {
            if (String.IsNullOrEmpty(format))
            {
                return(defaultFormat);
            }

            try
            {
                return((DumpFormat)Enum.Parse(typeof(DumpFormat), format, ignoreCase: true));
            }
            catch (Exception ex)
            {
                _tracer.TraceError(ex);

                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Exemple #9
0
        private void SaveAndVerifyOutput(DumpFormat dumpFormat)
        {
            DumpSaver    saver     = new DumpSaver();
            MemoryStream outstream = new MemoryStream();
            Dump         dump      = GenerateTestDump();

            saver.Save(dump, dumpFormat, outstream);
            byte[] buffer = outstream.ToArray();

            Stream       stream = new MemoryStream(buffer);
            BinaryReader reader = new BinaryReader(stream);

            ReadAndVerifyHeader(reader, dumpFormat);
            ReadAndVerifyBody(stream, dumpFormat);

            Assert.That(stream.Position, Is.EqualTo(stream.Length),
                        "Should not be any trailing data");
        }
Exemple #10
0
        private void ReadAndVerifyHeader(BinaryReader reader, DumpFormat dumpFormat)
        {
            string magic        = new string(reader.ReadChars(4));
            uint   version      = reader.ReadUInt32();
            uint   isCompressed = reader.ReadUInt32();
            uint   numEvents    = reader.ReadUInt32();

            Assert.That(magic, Is.EqualTo("oSpy"));
            Assert.That(version, Is.EqualTo(2));
            if (dumpFormat == DumpFormat.Compressed)
            {
                Assert.That(isCompressed, Is.EqualTo(1));
            }
            else
            {
                Assert.That(isCompressed, Is.EqualTo(0));
            }
            Assert.That(numEvents, Is.EqualTo(3));
        }
    public DumpFormat GetBaseDumpFormat(Game game)
    {
        string baseDumpFormatName = "";

        switch (game)
        {
        case Game.RE1:
            baseDumpFormatName = "RE1 Classic Rebirth";
            break;

        case Game.RE2:
            baseDumpFormatName = "RE2 Classic Rebirth";
            break;

        case Game.RE3:
            baseDumpFormatName = "RE3 SourceNext";
            break;
        }

        DumpFormat baseDumpFormat = new DumpFormat();

        for (int i = 0; i < dumpFormats.Length; i++)
        {
            if (dumpFormats[i].name == baseDumpFormatName)
            {
                baseDumpFormat = dumpFormats[i];
                break;
            }
        }

        if (string.IsNullOrEmpty(baseDumpFormat.name))
        {
            //ChangeState(State.Error);
            //errorMessage.ChangeMessage("The dump format named " + baseDumpFormatName + " is missing. Check the Dump Format folder.");
            Debug.LogError("The dump format named " + baseDumpFormatName + " is missing. Check the Dump Formats folder.");
            ChangeState(State.None);
        }

        return(baseDumpFormat);
    }
Exemple #12
0
 public SaveInfo(Dump dump, DumpFormat format, Stream stream)
 {
     m_dump = dump;
     m_format = format;
     m_stream = stream;
 }
Exemple #13
0
        /// <summary>
        /// Dumps contents of dayfile to the console
        /// </summary>
        public DataTable Dump(string outputFilename, DumpFormat fmt)
        {
            DataTable rval = new DataTable();

            int recordCount = 0;


            FileStream   fs = File.OpenRead(m_filename);
            StreamWriter sw = new StreamWriter(outputFilename);

            if (fmt == DumpFormat.CSV)
            {
                sw.WriteLine("DateTime, id,format,site,time,Rmode,tType,tZone,cType,pcode,value,flag");
            }
            if (fmt == DumpFormat.DataTable)
            {
                //sw.WriteLine("DateTime, site,pcode,value,flag");
                rval.Columns.Add("DateTime", typeof(DateTime));
                rval.Columns.Add("site");
                rval.Columns.Add("pcode");
                rval.Columns.Add("value", typeof(double));
                rval.Columns.Add("flag");
            }
            if (fmt == DumpFormat.SQL)
            {
                sw.WriteLine("-- Auto Generated SQL --");
            }


            BinaryReader br = new BinaryReader(fs, Encoding.ASCII);

            DayFileRecord rec;

            while (br.PeekChar() != -1)
            {
                rec = ReadRecordV2(br);
                recordCount++;
                if (!rec.Valid)
                {
                    Console.WriteLine("[" + br.BaseStream.Position + "/" + br.BaseStream.Length + "]skipping invalid record :" + BuildRecordPrefix(ref rec));
                    continue;
                }
                if (rec.Rmode == 'R' && !m_keepRandom)
                {
                    continue;
                }

                if (rec.Format == 'Q' && !m_keepQuality)
                {
                    continue;
                }


                if (rec.Id == 0)
                {
                    break;
                }
                if (fmt == DumpFormat.CSV)
                {
                    WriteCsvRecord(sw, rec);
                }
                if (fmt == DumpFormat.DataTable)
                {
                    AddDataTableRow(rval, rec);
                }
                if (fmt == DumpFormat.SQL)
                {
                    WriteSqlRecord(sw, rec);
                }
            }

            br.Close();
            sw.Close();
            //p.Report();
            return(rval);
        }
Exemple #14
0
        /// <summary>
        /// Convert a buffer to a printable string
        /// </summary>
        /// <param name="buf">Buffer to convert</param>
        /// <param name="fmt">Dumping format</param>
        /// <param name="offset">Starting index</param>
        /// <param name="count">Number of bytes to process (-1 means all bytes in the buffer)</param>
        /// <param name="eol">If true, terminate with end-of-line</param>
        /// <param name="encoding">Encoding to use for writing data in Binary format</param>
        /// <param name="maxLen">Max length of the returned string. Pass 0 for unlimited length</param>
        /// <returns></returns>
        public static string ToDumpString(this byte[] buf, DumpFormat fmt, int offset = 0,
                                          int count = -1, bool eol = false, Encoding encoding = null, int maxLen = 0)
        {
            if (count == -1)
            {
                count = buf.Length - offset;
            }

            int n;

            switch (fmt)
            {
            case DumpFormat.Decimal:    n = count * 4 + 4; break;

            case DumpFormat.Hex:        n = count * 3; break;

            case DumpFormat.Printable:  n = count * 4; break;

            default:                    throw new NFXException(StringConsts.OPERATION_NOT_SUPPORTED_ERROR + fmt.ToString());
            }

            var sb = new StringBuilder(n);

            int  k      = offset + count;
            int  m      = maxLen > 0 ? Math.Max(2, maxLen) : Int16.MaxValue;
            bool shrink = maxLen > 0;

            switch (fmt)
            {
            case DumpFormat.Decimal:
                m -= 5;
                sb.Append("<<");
                for (int i = offset; i < k && sb.Length < m; i++)
                {
                    sb.Append(buf[i]);
                    sb.Append(',');
                }
                if (sb.Length > 2)
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                sb.Append(shrink && sb.Length == maxLen ? "...>>" : ">>");
                break;

            case DumpFormat.Hex:
                m -= 3;
                for (int i = offset, j = 0; i < k && sb.Length < m; i++, j++)
                {
                    sb.AppendFormat("{0:X2}{1}", buf[i], (j & 3) == 3 ? " " : "");
                }
                if (sb.Length > 0 && sb[sb.Length - 1] == ' ')
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                if (shrink)
                {
                    sb.Append("...");
                }
                break;

            case DumpFormat.Printable:
                m -= 3;
                for (int i = offset; i < k && sb.Length < m; i++)
                {
                    byte c = buf[i];
                    if (c >= 32 && c < 127)
                    {
                        sb.Append((char)c);
                    }
                    else
                    {
                        sb.AppendFormat("\\{0,3:D3}", c);
                    }
                }
                if (shrink)
                {
                    sb.Append("...");
                }
                break;
            }

            if (eol)
            {
                sb.Append('\n');
            }

            return(sb.ToString());
        }
Exemple #15
0
        public HttpResponseMessage MiniDump(int id, int dumpType = 0, string format = null)
        {
            using (_tracer.Step("ProcessController.MiniDump"))
            {
                DumpFormat dumpFormat = ParseDumpFormat(format, DumpFormat.Raw);
                if (dumpFormat != DumpFormat.Raw && dumpFormat != DumpFormat.Zip)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                       String.Format(CultureInfo.CurrentCulture, Resources.Error_DumpFormatNotSupported, dumpFormat)));
                }

                string sitePolicy = _settings.GetWebSitePolicy();
                if ((MINIDUMP_TYPE)dumpType == MINIDUMP_TYPE.WithFullMemory && sitePolicy.Equals(FreeSitePolicy, StringComparison.OrdinalIgnoreCase))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError,
                                                       String.Format(CultureInfo.CurrentCulture, Resources.Error_FullMiniDumpNotSupported, sitePolicy)));
                }

                var process = GetProcessById(id);

                string dumpFile = Path.Combine(_environment.LogFilesPath, "minidump", "minidump.dmp");
                FileSystemHelpers.EnsureDirectory(_fileSystem, Path.GetDirectoryName(dumpFile));
                FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);

                try
                {
                    using (_tracer.Step(String.Format("MiniDump pid={0}, name={1}, file={2}", process.Id, process.ProcessName, dumpFile)))
                    {
                        process.MiniDump(dumpFile, (MINIDUMP_TYPE)dumpType);
                        _tracer.Trace("MiniDump size={0}", new FileInfo(dumpFile).Length);
                    }
                }
                catch (Exception ex)
                {
                    _tracer.TraceError(ex);
                    FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
                }

                if (dumpFormat == DumpFormat.Raw)
                {
                    string responseFileName = GetResponseFileName(process.ProcessName, "dmp");

                    HttpResponseMessage response = Request.CreateResponse();
                    response.Content = new StreamContent(FileStreamWrapper.OpenRead(dumpFile, _fileSystem));
                    response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                    response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                    response.Content.Headers.ContentDisposition.FileName = responseFileName;
                    return(response);
                }
                else if (dumpFormat == DumpFormat.Zip)
                {
                    string responseFileName = GetResponseFileName(process.ProcessName, "zip");

                    HttpResponseMessage response = Request.CreateResponse();
                    response.Content = ZipStreamContent.Create(responseFileName, _tracer, zip =>
                    {
                        try
                        {
                            zip.AddFile(dumpFile, String.Empty);
                        }
                        finally
                        {
                            FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);
                        }

                        foreach (var fileName in new[] { "sos.dll", "mscordacwks.dll" })
                        {
                            string filePath = Path.Combine(ProcessExtensions.ClrRuntimeDirectory, fileName);
                            if (_fileSystem.File.Exists(filePath))
                            {
                                zip.AddFile(filePath, String.Empty);
                            }
                        }
                    });
                    return(response);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                       String.Format(CultureInfo.CurrentCulture, Resources.Error_DumpFormatNotSupported, dumpFormat)));
                }
            }
        }
Exemple #16
0
 public virtual void Save(Dump dump, DumpFormat format, Stream stream)
 {
     SaveInfo info = new SaveInfo(dump, format, stream);
     DoSave(info, null);
 }
Exemple #17
0
		public void Setup(DumpFormat format, DumpType type)
		{
			this.format = format;
			this.type = type;

			switch(format)
			{
				case DumpFormat.Text:
					file = Path.Combine(directory, string.Format("TagIndexDump.{0:yyyy}{0:MM}{0:dd}_{0:HH}{0:mm}({0:ss}).{1}", DateTime.Now, "txt"));
					provider = new TextProvider(file, type);
					break;

				case DumpFormat.Xml:
					file = Path.Combine(directory, string.Format("TagIndexDump.{0:yyyy}{0:MM}{0:dd}_{0:HH}{0:mm}({0:ss}).{1}", DateTime.Now, "xml"));
					provider = new XmlProvider(file);
					break;
			}
		}
Exemple #18
0
        public virtual void Save(Dump dump, DumpFormat format, Stream stream)
        {
            SaveInfo info = new SaveInfo(dump, format, stream);

            DoSave(info, null);
        }
Exemple #19
0
 public SaveInfo(Dump dump, DumpFormat format, Stream stream)
 {
     m_dump   = dump;
     m_format = format;
     m_stream = stream;
 }
Exemple #20
0
        private void SaveAndLoadFullCycle(DumpFormat dumpFormat)
        {
            DumpSaver saver = new DumpSaver();
            MemoryStream outStream = new MemoryStream();
            Dump canonicalDump = GenerateTestDump();
            saver.Save(canonicalDump, dumpFormat, outStream);

            DumpLoader loader = new DumpLoader();
            Dump loadedDump = loader.Load(new MemoryStream(outStream.ToArray()));
            foreach (KeyValuePair<uint, Event> entry in loadedDump.Events)
            {
                Assert.That(entry.Value.RawData, Is.EqualTo(canonicalDump.Events[entry.Key].RawData));
            }
        }