public static bool IsMacBinStream(Stream stream) { MacBinaryHeader macBinaryHeader = null; try { macBinaryHeader = MimeAppleTranscoder.ExtractMacBinHeader(stream); } catch (MimeException) { stream.Position = 0L; return(false); } long num = 128L; if (macBinaryHeader.SecondaryHeaderLength > 0) { num += (long)(macBinaryHeader.SecondaryHeaderLength + MimeAppleTranscoder.GetMacBinPaddingSize(macBinaryHeader.SecondaryHeaderLength)); } if (macBinaryHeader.DataForkLength > 0L) { num += macBinaryHeader.DataForkLength + (long)MimeAppleTranscoder.GetMacBinPaddingSize((int)macBinaryHeader.DataForkLength); } if (macBinaryHeader.ResourceForkLength > 0L) { num += macBinaryHeader.ResourceForkLength + (long)MimeAppleTranscoder.GetMacBinPaddingSize((int)macBinaryHeader.ResourceForkLength); } if (macBinaryHeader.GetInfoLength > 0) { num += (long)macBinaryHeader.GetInfoLength; } stream.Position = 0L; return(stream.Length == num); }
public static Stream ExtractDataFork(Stream macBinStream) { MacBinaryHeader macBinaryHeader = MimeAppleTranscoder.ExtractMacBinHeader(macBinStream); int num = 128; if (macBinaryHeader.SecondaryHeaderLength > 0) { num += macBinaryHeader.SecondaryHeaderLength + MimeAppleTranscoder.GetMacBinPaddingSize(macBinaryHeader.SecondaryHeaderLength); } return(new BoundedStream(macBinStream, (long)num, macBinaryHeader.DataForkLength)); }
public static void MacBinToApplefile(Stream macBinStream, Stream outStream, out string fileName, out byte[] additionalInfo) { MacBinaryHeader macBinaryHeader = MimeAppleTranscoder.ExtractMacBinHeader(macBinStream); fileName = macBinaryHeader.FileName; if (outStream == null) { additionalInfo = null; return; } additionalInfo = MimeAppleTranscoder.EncodeAdditionalInfo(macBinaryHeader.FileCreator, macBinaryHeader.FileType); List <MimeAppleTranscoder.EntryDescriptor> descriptors = new List <MimeAppleTranscoder.EntryDescriptor>(6); int entryOffset = 0; byte[] array = null; if (macBinaryHeader.FileName != null) { MimeAppleTranscoder.EntryDescriptor descr = new MimeAppleTranscoder.EntryDescriptor(3, entryOffset, macBinaryHeader.FileNameLength); try { array = MimeAppleTranscoder.macEncoding.GetBytes(fileName); } catch (ArgumentOutOfRangeException innerException) { throw new MimeException(EmailMessageStrings.MacBinWrongFilename, innerException); } MimeAppleTranscoder.AddEntry(descriptors, descr, ref entryOffset); } MimeAppleTranscoder.EntryDescriptor entryDescriptor = new MimeAppleTranscoder.EntryDescriptor(8, entryOffset, 16); MimeAppleTranscoder.AddEntry(descriptors, entryDescriptor, ref entryOffset); int appleDate = MimeAppleTranscoder.GetAppleDate(macBinaryHeader.CreationDate); int appleDate2 = MimeAppleTranscoder.GetAppleDate(macBinaryHeader.ModificationDate); byte[] array2 = new byte[entryDescriptor.EntryLength]; int num = 0; MimeAppleTranscoder.WriteIntData(appleDate, array2, ref num); MimeAppleTranscoder.WriteIntData(appleDate2, array2, ref num); MimeAppleTranscoder.WriteIntData(0, array2, ref num); MimeAppleTranscoder.WriteIntData(0, array2, ref num); MimeAppleTranscoder.EntryDescriptor entryDescriptor2 = new MimeAppleTranscoder.EntryDescriptor(9, entryOffset, 28); MimeAppleTranscoder.AddEntry(descriptors, entryDescriptor2, ref entryOffset); byte[] array3 = new byte[entryDescriptor2.EntryLength]; num = 0; MimeAppleTranscoder.WriteIntData(macBinaryHeader.FileType, array3, ref num); MimeAppleTranscoder.WriteIntData(macBinaryHeader.FileCreator, array3, ref num); MimeAppleTranscoder.WriteShortData((int)((short)macBinaryHeader.FinderFlags), array3, ref num); MimeAppleTranscoder.WriteShortData((int)((short)macBinaryHeader.YIcon), array3, ref num); MimeAppleTranscoder.WriteShortData((int)((short)macBinaryHeader.XIcon), array3, ref num); MimeAppleTranscoder.WriteShortData((int)((short)macBinaryHeader.FileId), array3, ref num); MimeAppleTranscoder.WriteIntData(0, array3, ref num); MimeAppleTranscoder.WriteIntData(0, array3, ref num); MimeAppleTranscoder.WriteIntData(0, array3, ref num); MimeAppleTranscoder.EntryDescriptor entryDescriptor3 = new MimeAppleTranscoder.EntryDescriptor(10, entryOffset, 4); MimeAppleTranscoder.AddEntry(descriptors, entryDescriptor3, ref entryOffset); byte[] array4 = new byte[entryDescriptor3.EntryLength]; array4[0] = 0; array4[1] = 0; array4[2] = 0; array4[3] = (macBinaryHeader.Protected ? 1 : 0); if (macBinaryHeader.ResourceForkLength > 0L) { MimeAppleTranscoder.EntryDescriptor descr2 = new MimeAppleTranscoder.EntryDescriptor(2, entryOffset, (int)macBinaryHeader.ResourceForkLength); MimeAppleTranscoder.AddEntry(descriptors, descr2, ref entryOffset); } if (macBinaryHeader.GetInfoLength > 0) { MimeAppleTranscoder.EntryDescriptor descr3 = new MimeAppleTranscoder.EntryDescriptor(4, entryOffset, macBinaryHeader.GetInfoLength); MimeAppleTranscoder.AddEntry(descriptors, descr3, ref entryOffset); } MimeAppleTranscoder.WriteApplefileHeader(descriptors, true, outStream); if (array != null) { outStream.Write(array, 0, array.Length); } outStream.Write(array2, 0, array2.Length); outStream.Write(array3, 0, array3.Length); outStream.Write(array4, 0, array4.Length); if (macBinaryHeader.SecondaryHeaderLength > 0) { macBinStream.Position += (long)(macBinaryHeader.SecondaryHeaderLength + MimeAppleTranscoder.GetMacBinPaddingSize(macBinaryHeader.SecondaryHeaderLength)); } if (macBinaryHeader.DataForkLength > 0L) { macBinStream.Position += macBinaryHeader.DataForkLength + (long)MimeAppleTranscoder.GetMacBinPaddingSize((int)macBinaryHeader.DataForkLength); } if (macBinaryHeader.ResourceForkLength > 0L) { MimeAppleTranscoder.CopyStreamData(macBinStream, outStream, new int?((int)macBinaryHeader.ResourceForkLength)); macBinStream.Position += (long)MimeAppleTranscoder.GetMacBinPaddingSize((int)macBinaryHeader.ResourceForkLength); } if (macBinaryHeader.GetInfoLength > 0) { MimeAppleTranscoder.CopyStreamData(macBinStream, outStream, new int?(macBinaryHeader.GetInfoLength)); macBinStream.Position += (long)MimeAppleTranscoder.GetMacBinPaddingSize(macBinaryHeader.GetInfoLength); } }