protected static bool WriteIncomingFile(BinaryReader BinaryData, int FileIndex, string DestinationFolderPath) { try { Int32 CurrentFileIndex = BinaryData.ReadInt32(); if (CurrentFileIndex != FileIndex) { CrashReporterProcessServicer.WriteFailure("! WriteIncomingFile index mismatch: Required=" + FileIndex + " Read=" + CurrentFileIndex); return(false); } string Filename = FBinaryReaderHelper.ReadFixedSizeString(BinaryData); string SafeFilename = GetSafeFilename(Filename); Int32 FiledataLength = BinaryData.ReadInt32(); byte[] Filedata = BinaryData.ReadBytes(FiledataLength); Directory.CreateDirectory(DestinationFolderPath); File.WriteAllBytes(Path.Combine(DestinationFolderPath, SafeFilename), Filedata); return(true); } catch (Exception Ex) { throw new CrashReporterException(string.Format("! WriteIncomingFile failed writing FileIndex={0} FolderPath={1}", FileIndex, DestinationFolderPath), Ex); } }
public static CrashHeader ParseCrashHeader(BinaryReader Reader) { var OutCrashHeader = new CrashHeader(); OutCrashHeader.DirectoryName = FBinaryReaderHelper.ReadFixedSizeString(Reader); OutCrashHeader.FileName = FBinaryReaderHelper.ReadFixedSizeString(Reader); OutCrashHeader.UncompressedSize = Reader.ReadInt32(); OutCrashHeader.FileCount = Reader.ReadInt32(); return(OutCrashHeader); }
/// <summary> /// Decompresses a compressed crash report. /// </summary> unsafe private bool DecompressReport(string CompressedReportPath, FCompressedCrashInformation Meta) { string ReportPath = Path.GetDirectoryName(CompressedReportPath); using (FileStream FileStream = File.OpenRead(CompressedReportPath)) { Int32 UncompressedSize = Meta.GetUncompressedSize(); Int32 CompressedSize = Meta.GetCompressedSize(); if (FileStream.Length != CompressedSize) { return(false); } byte[] UncompressedBufferArray = new byte[UncompressedSize]; byte[] CompressedBufferArray = new byte[CompressedSize]; FileStream.Read(CompressedBufferArray, 0, CompressedSize); fixed(byte *UncompressedBufferPtr = UncompressedBufferArray, CompressedBufferPtr = CompressedBufferArray) { bool bResult = UE4UncompressMemoryZLIB((IntPtr)UncompressedBufferPtr, UncompressedSize, (IntPtr)CompressedBufferPtr, CompressedSize); if (!bResult) { CrashReporterProcessServicer.WriteFailure("! ZLibFail: Path=" + ReportPath); return(false); } } MemoryStream MemoryStream = new MemoryStream(UncompressedBufferArray, false); BinaryReader BinaryData = new BinaryReader(MemoryStream); for (int FileIndex = 0; FileIndex < Meta.GetNumberOfFiles(); FileIndex++) { Int32 CurrentFileIndex = BinaryData.ReadInt32(); if (CurrentFileIndex != FileIndex) { CrashReporterProcessServicer.WriteFailure("! ReadFail: Required=" + FileIndex + " Read=" + CurrentFileIndex); return(false); } string Filename = FBinaryReaderHelper.ReadFixedSizeString(BinaryData); Int32 FiledataLength = BinaryData.ReadInt32(); byte[] Filedata = BinaryData.ReadBytes(FiledataLength); File.WriteAllBytes(Path.Combine(ReportPath, Filename), Filedata); } } return(true); }