public IWICBitmapDecoder CreateDecoderFromFilename( string fileName, FileAccess desiredAccess, DecodeOptions metadataOptions) { return(CreateDecoderFromFilename(fileName, null, desiredAccess, metadataOptions)); }
public override IPlatformBitmapDecoder CreateBitmapDecoder(Stream stream, BitmapCacheOption cacheOption) { DecodeOptions o = (cacheOption == BitmapCacheOption.OnLoad) ? DecodeOptions.CacheOnLoad : DecodeOptions.CacheOnDemand; return(new WicBitmapDecoder(this.wicFactory, stream, o)); }
/// <summary> /// Creates a new <see cref="ObjectReader"/> with a given <see cref="StreamReader"/>. /// </summary> /// <param name="context">The current <see cref="ScriptContext"/>.</param> /// <param name="reader">The reader to reader serialized data from.</param> /// <param name="decodeOptions"></param> internal ObjectReader(ScriptContext /*!*/ context, StreamReader /*!*/ reader, DecodeOptions /*!*/ decodeOptions) { Debug.Assert(context != null && reader != null && decodeOptions != null); this.context = context; this.reader = reader; this.decodeOptions = decodeOptions; }
public IWICBitmapDecoder CreateDecoderFromStream(Stream stream, Guid vendor, DecodeOptions metadataOptions = DecodeOptions.CacheOnDemand) { var wicStream = CreateStream(stream); var decoder = CreateDecoderFromStream_(wicStream, vendor, metadataOptions); decoder._wicStream = wicStream; return(decoder); }
public void CallSafeStaticMethod() { Expression <Func <int> > expected = () => MethodCallTest.GetOne(); var encoded = EncodedExpression.EncodeExpression(expected); var decodeOptions = new DecodeOptions(); decodeOptions.SafeStaticMethodTypes.Add(typeof(MethodCallTest)); var actual = (Expression <Func <int> >)EncodedExpression.DecodeExpression(encoded, decodeOptions); Assert.AreEqual(expected.ToString(), actual.ToString()); Assert.AreEqual(1, expected.Compile().Invoke()); }
///// <summary> ///// Creates a new <see cref="PhpFormatter"/> with <see cref="ASCIIEncoding"/> and ///// default <see cref="Context"/>. ///// </summary> //public JsonFormatter() // :this(new ASCIIEncoding(), new EncodeOptions(), new DecodeOptions()) //{ //} /// <summary> /// Creates a new <see cref="PhpFormatter"/> with a given <see cref="Encoding"/> and /// default <see cref="Context"/>. /// </summary> /// <param name="encoding">The encoding to be used when writing and reading the serialization stream.</param> /// <param name="encodeOptions">Options used to encode the data stream.</param> /// <param name="decodeOptions">Options used to decode the data stream.</param> /// <param name="caller">DTypeDesc of the caller's class context if it is known or UnknownTypeDesc if it should be determined lazily.</param> public JsonFormatter(Encoding encoding, EncodeOptions encodeOptions, DecodeOptions decodeOptions, DTypeDesc caller) { // no UTF8 BOM! if (encoding is UTF8Encoding) { this.encoding = new UTF8Encoding(false); } else { this.encoding = (encoding ?? new ASCIIEncoding()); } // options this.encodeOptions = encodeOptions; this.decodeOptions = decodeOptions; }
public void CallTwoParameterMethod() { Expression <Func <MethodCallTest, int> > expected = (a) => a.AddValues(1, 2); var encoded = EncodedExpression.EncodeExpression(expected); var decodeOptions = new DecodeOptions { AllowUnsafeCalls = true }; var actual = (Expression <Func <MethodCallTest, int> >)EncodedExpression.DecodeExpression(encoded, decodeOptions); Assert.AreEqual(expected.ToString(), actual.ToString()); var testObject = new MethodCallTest(); Assert.AreEqual(3, expected.Compile().Invoke(testObject)); testObject = new MethodCallTest(); Assert.AreEqual(3, actual.Compile().Invoke(testObject)); }
public void CallSafeMethod() { Expression <Action <MethodCallTest> > expected = (a) => a.AddOne(); var encoded = EncodedExpression.EncodeExpression(expected); var decodeOptions = new DecodeOptions(); decodeOptions.SafeMethods.Add(typeof(MethodCallTest).GetMethod(nameof(MethodCallTest.AddOne))); var actual = (Expression <Action <MethodCallTest> >)EncodedExpression.DecodeExpression(encoded, decodeOptions); Assert.AreEqual(expected.ToString(), actual.ToString()); var testObject = new MethodCallTest(); expected.Compile().Invoke(testObject); Assert.AreEqual(1, testObject.Value); testObject = new MethodCallTest(); actual.Compile().Invoke(testObject); Assert.AreEqual(1, testObject.Value); }
private static ExitCode RunDecodeOptionsAndReturnExitCode(DecodeOptions decodeOptions) { string decodedString = null; string errorMsg = null; switch (decodeOptions.DecodeType.ToLower()) { case "base64": { decodedString = Base64.ToString(decodeOptions.InputToDecode); } break; case "hex": { decodedString = HighPerformanceHexadecimal.ToString(decodeOptions.InputToDecode); } break; default: errorMsg = $"Unknown decode type \"{decodeOptions.DecodeType}\"."; break; } if (string.IsNullOrWhiteSpace(errorMsg)) { Console.WriteLine(decodedString); return(ExitCode.Sucess); } else { Console.WriteLine(errorMsg); return(ExitCode.Error); } }
/// <summary> /// Initializes a new instance of the <see cref="SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="options"><see cref="DecodeOptions" /> to determine how to do the decoding (must be combined as a bit map).</param> public SharpMessage(System.IO.Stream message, DecodeOptions options) : this(message, options, null, null) { }
internal static void DoDecode(DecodeOptions options) { DicConsole.DebugWriteLine("Decode command", "--debug={0}", options.Debug); DicConsole.DebugWriteLine("Decode command", "--verbose={0}", options.Verbose); DicConsole.DebugWriteLine("Decode command", "--input={0}", options.InputFile); DicConsole.DebugWriteLine("Decode command", "--start={0}", options.StartSector); DicConsole.DebugWriteLine("Decode command", "--length={0}", options.Length); DicConsole.DebugWriteLine("Decode command", "--disk-tags={0}", options.DiskTags); DicConsole.DebugWriteLine("Decode command", "--sector-tags={0}", options.SectorTags); FiltersList filtersList = new FiltersList(); IFilter inputFilter = filtersList.GetFilter(options.InputFile); if (inputFilter == null) { DicConsole.ErrorWriteLine("Cannot open specified file."); return; } IMediaImage inputFormat = ImageFormat.Detect(inputFilter); if (inputFormat == null) { DicConsole.ErrorWriteLine("Unable to recognize image format, not decoding"); return; } inputFormat.Open(inputFilter); Core.Statistics.AddMediaFormat(inputFormat.Format); Core.Statistics.AddMedia(inputFormat.Info.MediaType, false); Core.Statistics.AddFilter(inputFilter.Name); if (options.DiskTags) { if (inputFormat.Info.ReadableMediaTags.Count == 0) { DicConsole.WriteLine("There are no disk tags in chosen disc image."); } else { foreach (MediaTagType tag in inputFormat.Info.ReadableMediaTags) { switch (tag) { case MediaTagType.SCSI_INQUIRY: { byte[] inquiry = inputFormat.ReadDiskTag(MediaTagType.SCSI_INQUIRY); if (inquiry == null) { DicConsole.WriteLine("Error reading SCSI INQUIRY response from disc image"); } else { DicConsole.WriteLine("SCSI INQUIRY command response:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(Inquiry.Prettify(inquiry)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.ATA_IDENTIFY: { byte[] identify = inputFormat.ReadDiskTag(MediaTagType.ATA_IDENTIFY); if (identify == null) { DicConsole.WriteLine("Error reading ATA IDENTIFY DEVICE response from disc image"); } else { DicConsole.WriteLine("ATA IDENTIFY DEVICE command response:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(Identify.Prettify(identify)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.ATAPI_IDENTIFY: { byte[] identify = inputFormat.ReadDiskTag(MediaTagType.ATAPI_IDENTIFY); if (identify == null) { DicConsole .WriteLine("Error reading ATA IDENTIFY PACKET DEVICE response from disc image"); } else { DicConsole.WriteLine("ATA IDENTIFY PACKET DEVICE command response:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(Identify.Prettify(identify)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.CD_ATIP: { byte[] atip = inputFormat.ReadDiskTag(MediaTagType.CD_ATIP); if (atip == null) { DicConsole.WriteLine("Error reading CD ATIP from disc image"); } else { DicConsole.WriteLine("CD ATIP:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(ATIP.Prettify(atip)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.CD_FullTOC: { byte[] fulltoc = inputFormat.ReadDiskTag(MediaTagType.CD_FullTOC); if (fulltoc == null) { DicConsole.WriteLine("Error reading CD full TOC from disc image"); } else { DicConsole.WriteLine("CD full TOC:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(FullTOC.Prettify(fulltoc)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.CD_PMA: { byte[] pma = inputFormat.ReadDiskTag(MediaTagType.CD_PMA); if (pma == null) { DicConsole.WriteLine("Error reading CD PMA from disc image"); } else { DicConsole.WriteLine("CD PMA:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(PMA.Prettify(pma)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.CD_SessionInfo: { byte[] sessioninfo = inputFormat.ReadDiskTag(MediaTagType.CD_SessionInfo); if (sessioninfo == null) { DicConsole.WriteLine("Error reading CD session information from disc image"); } else { DicConsole.WriteLine("CD session information:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(Session.Prettify(sessioninfo)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.CD_TEXT: { byte[] cdtext = inputFormat.ReadDiskTag(MediaTagType.CD_TEXT); if (cdtext == null) { DicConsole.WriteLine("Error reading CD-TEXT from disc image"); } else { DicConsole.WriteLine("CD-TEXT:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(CDTextOnLeadIn.Prettify(cdtext)); DicConsole .WriteLine("================================================================================"); } break; } case MediaTagType.CD_TOC: { byte[] toc = inputFormat.ReadDiskTag(MediaTagType.CD_TOC); if (toc == null) { DicConsole.WriteLine("Error reading CD TOC from disc image"); } else { DicConsole.WriteLine("CD TOC:"); DicConsole .WriteLine("================================================================================"); DicConsole.WriteLine(TOC.Prettify(toc)); DicConsole .WriteLine("================================================================================"); } break; } default: DicConsole.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.", tag); break; } } } } if (options.SectorTags) { ulong length; if (options.Length.ToLowerInvariant() == "all") { length = inputFormat.Info.Sectors - 1; } else { if (!ulong.TryParse(options.Length, out length)) { DicConsole.WriteLine("Value \"{0}\" is not a valid number for length.", options.Length); DicConsole.WriteLine("Not decoding sectors tags"); return; } } if (inputFormat.Info.ReadableSectorTags.Count == 0) { DicConsole.WriteLine("There are no sector tags in chosen disc image."); } else { foreach (SectorTagType tag in inputFormat.Info.ReadableSectorTags) { switch (tag) { default: DicConsole.WriteLine("Decoder for disk tag type \"{0}\" not yet implemented, sorry.", tag); break; } } } // TODO: Not implemented } Core.Statistics.AddCommand("decode"); }
public IWICBitmapDecoder CreateDecoderFromFileName(string fileName, Guid?guidVendor, FileAccess desiredAccess = FileAccess.Read, DecodeOptions metadataOptions = DecodeOptions.CacheOnDemand) { NativeFileAccess nativeAccess = desiredAccess.ToNative(); return(CreateDecoderFromFilename_(fileName, guidVendor, (int)nativeAccess, metadataOptions)); }
public IWICBitmapDecoder CreateDecoderFromStream(IStream stream, Guid vendor, DecodeOptions metadataOptions = DecodeOptions.CacheOnDemand) { return(CreateDecoderFromStream_(stream, vendor, metadataOptions)); }
private void ParseMessage(MimeMessage part, MimeTopLevelMediaType types, bool html, DecodeOptions options, System.String preferredtextsubtype, System.String path) { if ((types & part.Header.TopLevelMediaType) != part.Header.TopLevelMediaType) { return; } switch (part.Header.TopLevelMediaType) { case MimeTopLevelMediaType.multipart: case MimeTopLevelMediaType.message: // TODO: allow other subtypes of "message" // Only message/rfc822 allowed, other subtypes ignored if (part.Header.TopLevelMediaType.Equals(MimeTopLevelMediaType.message) && !part.Header.SubType.Equals("rfc822")) break; if (part.Header.SubType.Equals("alternative")) { if (part.PartsCount > 0) { MimeMessage altenative = null; // Get the first mime part of the alternatives that has a accepted Mime-Type for (int i = part.PartsCount; i > 0; i--) { MimeMessage item = part.GetPart(i - 1); if ((types & part.Header.TopLevelMediaType) != part.Header.TopLevelMediaType || (!html && item.Header.TopLevelMediaType.Equals(MimeTopLevelMediaType.text) && item.Header.SubType.Equals("html")) ) { continue; } // First allowed one. if (altenative == null) { altenative = item; // We don't have to select body part based on subtype if not asked for, or not a text one // or it's already the preferred one if (preferredtextsubtype == null || item.Header.TopLevelMediaType != MimeTopLevelMediaType.text || (item.Header.SubType == preferredtextsubtype)) { break; } // This one is preferred over the last part } else if (item.Header.TopLevelMediaType == MimeTopLevelMediaType.text && item.Header.SubType == preferredtextsubtype) { altenative = item; break; } } if (altenative != null) { // If message body as html is allowed and part has a Content-ID field // add an anchor to mark this body part if (html && part.Header.Contains("Content-ID") && (options & DecodeOptions.NamedAnchors) == DecodeOptions.NamedAnchors) { // There is a previous text body, so enclose it in <pre> if (!this._bodyHtml && this._body.Length > 0) { this._body = System.String.Concat("<pre>", System.Web.HttpUtility.HtmlEncode(this._body), "</pre>"); this._bodyHtml = true; } // Add the anchor this._body = System.String.Concat(this._body, "<a name=\"", MimeTools.Rfc2392Url(this.MessageID), "_", MimeTools.Rfc2392Url(part.Header.ContentID), "\"></a>"); } this.ParseMessage(altenative, types, html, options, preferredtextsubtype, path); } } // TODO: Take into account each subtype of "multipart" } else if (part.PartsCount > 0) { foreach (MimeMessage item in part) { this.ParseMessage(item, types, html, options, preferredtextsubtype, path); } } break; case MimeTopLevelMediaType.text: if ((part.Disposition == null || !part.Disposition.Equals("attachment")) && (part.Header.SubType.Equals("plain") || part.Header.SubType.Equals("html"))) { bool body_was_html = this._bodyHtml; // HTML content not allowed if (part.Header.SubType.Equals("html")) { if (!html) break; this._bodyHtml = true; } if (html && part.Header.Contains("Content-ID") && (options & DecodeOptions.NamedAnchors) == DecodeOptions.NamedAnchors) { this._bodyHtml = true; } if (this._bodyHtml && !body_was_html && this._body.Length > 0) { this._body = System.String.Concat("<pre>", System.Web.HttpUtility.HtmlEncode(this._body), "</pre>"); } // If message body is html and this part has a Content-ID field // add an anchor to mark this body part if (this._bodyHtml && part.Header.Contains("Content-ID") && (options & DecodeOptions.NamedAnchors) == DecodeOptions.NamedAnchors) { this._body = System.String.Concat(this._body, "<a name=\"", MimeTools.Rfc2392Url(this.MessageID), "_", MimeTools.Rfc2392Url(part.Header.ContentID), "\"></a>"); } if (this._bodyHtml && part.Header.SubType.Equals("plain")) { this._body = System.String.Concat(this._body, "<pre>", System.Web.HttpUtility.HtmlEncode(part.BodyDecoded), "</pre>"); } else this._body = System.String.Concat(this._body, part.BodyDecoded); } else { if ((types & MimeTopLevelMediaType.application) != MimeTopLevelMediaType.application) { return; } goto case MimeTopLevelMediaType.application; } break; case MimeTopLevelMediaType.application: case MimeTopLevelMediaType.audio: case MimeTopLevelMediaType.image: case MimeTopLevelMediaType.video: // Attachments not allowed. if ((options & DecodeOptions.AllowAttachments) != DecodeOptions.AllowAttachments) break; SharpAttachment attachment = null; // Save to a file if (path != null) { System.IO.FileInfo file = part.DumpBody(path, true); if (file != null) { attachment = new SharpAttachment(file); attachment.Name = file.Name; attachment.Size = file.Length; } // Save to a stream } else { System.IO.MemoryStream stream = new System.IO.MemoryStream(); part.DumpBody(stream); attachment = new SharpAttachment(stream); attachment.Name = part.Name ?? System.String.Concat("generated_", part.GetHashCode(), ".", part.Header.SubType); attachment.Size = stream.Length; } if (attachment != null && part.Header.SubType == "ms-tnef" && (options & DecodeOptions.DecodeTnef) == DecodeOptions.DecodeTnef) { // Try getting attachments form a tnef stream System.IO.Stream stream = attachment.Stream; if (stream != null && stream.CanSeek) stream.Seek(0, System.IO.SeekOrigin.Begin); TnefMessage tnef = new TnefMessage(stream); if (tnef.Parse(path)) { if (tnef.Attachments != null) { this._attachments.AddRange(tnef.Attachments); } attachment.Close(); // Delete the raw tnef file if (attachment.SavedFile != null) { if (stream != null && stream.CanRead) stream.Close(); attachment.SavedFile.Delete(); } attachment = null; tnef.Close(); } else { // The read-only stream is no longer needed and locks the file if (attachment.SavedFile != null && stream != null && stream.CanRead) stream.Close(); } } if (attachment != null) { if (part.Disposition != null && part.Disposition == "inline") { attachment.Inline = true; } attachment.MimeTopLevelMediaType = part.Header.TopLevelMediaType; attachment.MimeMediaSubType = part.Header.SubType; // Store attachment's CreationTime if (part.Header.ContentDispositionParameters.ContainsKey("creation-date")) attachment.CreationTime = MimeTools.parseDate(part.Header.ContentDispositionParameters["creation-date"]); // Store attachment's LastWriteTime if (part.Header.ContentDispositionParameters.ContainsKey("modification-date")) attachment.LastWriteTime = MimeTools.parseDate(part.Header.ContentDispositionParameters["modification-date"]); if (part.Header.Contains("Content-ID")) attachment.ContentID = part.Header.ContentID; this._attachments.Add(attachment); } break; } }
private void ParseMessage(System.IO.Stream stream, MimeTopLevelMediaType types, DecodeOptions options, System.String preferredtextsubtype, System.String path) { this._attachments = new System.Collections.ArrayList(); MimeMessage message = new MimeMessage(stream); this.ParseMessage(message, types, (options & DecodeOptions.AllowHtml) == DecodeOptions.AllowHtml, options, preferredtextsubtype, path); this._headers = message.Header; message.Close(); // find and decode uuencoded content if configured to do so (and attachments a allowed) if ((options & DecodeOptions.UuDecode) == DecodeOptions.UuDecode && (options & DecodeOptions.AllowAttachments) == DecodeOptions.AllowAttachments) this.UuDecode(path); // Date this._date = MimeTools.parseDate(this._headers.Date); if (this._date.Equals(System.DateTime.MinValue)) { System.String date = this._headers["Received"] ?? System.String.Empty; if (date.IndexOf("\r\n", System.StringComparison.Ordinal) > 0) date = date.Substring(0, date.IndexOf("\r\n", System.StringComparison.Ordinal)); date = date.LastIndexOf(';') > 0 ? date.Substring(date.LastIndexOf(';') + 1).Trim() : System.String.Empty; this._date = MimeTools.parseDate(date); } // Subject this._subject = MimeTools.parserfc2047Header(this._headers.Subject); // To this._to = MimeAddressCollection.Parse(this._headers.To); // From MimeAddressCollection from = MimeAddressCollection.Parse(this._headers.From); foreach (MimeAddress item in from) { this._from_name = item["name"]; this._from_addr = item["address"]; if (this._from_name == null || this._from_name.Equals(System.String.Empty)) this._from_name = item["address"]; } }
/// <summary> /// Initializes a new instance of the <see cref="SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="types">A <see cref="MimeTopLevelMediaType" /> value that specifies the allowed Mime-Types to being decoded.</param> /// <param name="options"><see cref="DecodeOptions" /> to determine how to do the decoding (must be combined as a bit map).</param> /// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachments found.</param> /// <param name="preferredtextsubtype">A <see cref="System.String" /> specifying the subtype to select for text parts that contain aternative content (plain, html, ...). Specify the <b>null</b> reference to maintain the default behavior (prefer whatever the originator sent as the preferred part). If there is not a text part with this subtype, the default one is used.</param> public SharpMessage(System.IO.Stream message, MimeTopLevelMediaType types, DecodeOptions options, System.String path, System.String preferredtextsubtype) { if (path != null && (options & DecodeOptions.CreateFolder) != DecodeOptions.CreateFolder && !System.IO.Directory.Exists(path)) { path = null; } this.ParseMessage(message, types, options, preferredtextsubtype, path); }
/// <summary> /// Initializes a new instance of the <see cref="SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="options"><see cref="DecodeOptions" /> to determine how to do the decoding (must be combined as a bit map).</param> /// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachments found.</param> /// <param name="preferredtextsubtype">A <see cref="System.String" /> specifying the subtype to select for text parts that contain aternative content (plain, html, ...). Specify the <b>null</b> reference to maintain the default behavior (prefer whatever the originator sent as the preferred part). If there is not a text part with this subtype, the default one is used.</param> public SharpMessage(System.IO.Stream message, DecodeOptions options, System.String path, System.String preferredtextsubtype) { MimeTopLevelMediaType types = MimeTopLevelMediaType.text | MimeTopLevelMediaType.multipart | MimeTopLevelMediaType.message; if ((options & DecodeOptions.AllowAttachments) == DecodeOptions.AllowAttachments) { types = types | MimeTopLevelMediaType.application | MimeTopLevelMediaType.audio | MimeTopLevelMediaType.image | MimeTopLevelMediaType.video; } if (path != null && (options & DecodeOptions.CreateFolder) != DecodeOptions.CreateFolder && !System.IO.Directory.Exists(path)) { path = null; } this.ParseMessage(message, types, options, preferredtextsubtype, path); }
public WicBitmapDecoder(ImagingFactory factory, Stream stream, DecodeOptions metadataOptions) { this.factory = factory; this.wicImpl = new BitmapDecoder(factory, stream, metadataOptions); }
public IWICBitmapDecoder CreateDecoderFromFilename(string fileName, Guid?guidVendor, FileAccess desiredAccess, DecodeOptions metadataOptions) { var nativeAccess = desiredAccess.ToNative(); return(CreateDecoderFromFilename_(fileName, guidVendor, (uint)nativeAccess, metadataOptions)); }
public static void DecodeVerb(DecodeOptions opt) { var privDir = new DirectoryInfo(Path.Combine(opt.CacheDirectory)); if (!privDir.Exists) { Console.WriteLine("Cache directory not found?"); return; } var workDir = string.IsNullOrWhiteSpace(opt.WorkingDirectory) ? Environment.CurrentDirectory : opt.WorkingDirectory; var dbDir = new DirectoryInfo(Path.Combine(workDir, "db")); Console.WriteLine("Decrypting database"); DecryptDb(new DirectoryInfo(Path.Combine(privDir.FullName, "db")), dbDir); Console.WriteLine("Reading entries from database"); var entries = ReadDatabaseEntries(dbDir.FullName, out var errorCount); Console.WriteLine("Found {0} entries", entries.Count); Console.WriteLine("Errors reading {0} entries", errorCount); var entryLookup = entries.ToLookup(e => e.Filename); var files = new DirectoryInfo(privDir.FullName).GetFiles(); var filesLookup = files.ToLookup(f => f.Name); var entriesWithFiles = entries.Select(e => new { entry = e, file = filesLookup[e.Filename].FirstOrDefault() }).ToList(); Console.WriteLine("Skipping {0} entries", entriesWithFiles.Count(e => e.file == null)); Console.WriteLine("Skipping {0} files", files.Count(e => !entryLookup[e.Name].Any())); Console.WriteLine("Decrypting {0} files", entriesWithFiles.Count(e => e.file != null)); foreach (var g in entriesWithFiles.Where(e => e.file != null).GroupBy(e => Tuple.Create(e.entry.ResourceName, e.entry.OriginalFilename))) { foreach (var entryAndFile in g.OrderByDescending(e => e.file.LastWriteTimeUtc).ToList()) { var entry = entryAndFile.entry; var input = File.ReadAllBytes(filesLookup[entry.Filename].First().FullName); var output = Decrypt(DecryptStatic(input), entry.Key, entry.IV); var timeStamp = entryAndFile.file.LastWriteTimeUtc; var outDirStr = Regex.Replace(opt.OutputDirectory, "(%\\w)", res => { switch (res.Groups[1].Value) { case "%d": return(timeStamp.Day.ToString()); case "%m": return(timeStamp.Month.ToString()); case "%y": return(timeStamp.Year.ToString()); case "%h": return(entry.Hash); case "%n": return(entry.ResourceName); case "%s": var uri = new Uri(entry.From); return(uri.Host + "_" + uri.Port); } return(res.Groups[1].Value); }); var outDir = new DirectoryInfo(outDirStr); if (!outDir.Exists) { outDir.Create(); } Directory.SetLastWriteTimeUtc(outDir.FullName, timeStamp); if (Path.GetExtension(entry.OriginalFilename) == ".rpf") { var reader = new Rpf2Reader(new MemoryStream(output)); reader.Open(); foreach (var rpfEntry in reader.ReadEntries()) { var outFn = new FileInfo(Path.Combine(outDir.FullName, entry.OriginalFilename, rpfEntry.FullName)); if (!outFn.Directory.Exists) { outFn.Directory.Create(); } File.WriteAllBytes(outFn.FullName, rpfEntry.Data); File.SetLastWriteTimeUtc(outFn.FullName, timeStamp); } } else { var outFn = Path.Combine(outDir.FullName, entry.OriginalFilename); File.WriteAllBytes(outFn, output); File.SetLastWriteTimeUtc(outFn, timeStamp); } if (!opt.Duplicates) { break; } } } Console.WriteLine("Finished"); }
void Awake() { Result = DecodeResult.None; Options = new DecodeOptions(); }
public JsonSerializer(DecodeOptions decodeOptions = null, JsonEncodeOptions encodeOptions = JsonEncodeOptions.Default) { _decodeOptions = decodeOptions; _encodeOptions = encodeOptions; }
/// <summary> /// Initializes a new instance of the <see cref="SharpMessage" /> class based on the supplied <see cref="System.IO.Stream" />. /// </summary> /// <param name="message"><see cref="System.IO.Stream" /> that contains the message content</param> /// <param name="options"><see cref="DecodeOptions" /> to determine how to do the decoding (must be combined as a bit map).</param> /// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachments found.</param> public SharpMessage(System.IO.Stream message, DecodeOptions options, System.String path) : this(message, options, path, null) { }