public async Task CanParseAndInlineEmailACIDTestCSS() { var data = await _loader.LoadData("CanParseAndInlineEmailACIDTestCSS"); // TODO: this should attempt to produce exactly same result as Premailer. Inliner.ProcessHtml(data.Input); }
//[InlineData(":nth-child(n)")] //[InlineData(":nth-last-child(n)")] //[InlineData(":nth-of-type(n)")] //[InlineData(":nth-last-of-type(n)")] //[InlineData(":first-child")] //[InlineData(":last-child")] //[InlineData(":first-of-type")] //[InlineData(":last-of-type")] //[InlineData(":empty")] public void InlinerShouldHandlePsuedoSelectors(string psuedoSelector) { var input = Inputs.Inliner_Should_Support_PseudoClasses.Replace("~~TEST_SELECTOR~~", psuedoSelector); var processed = Inliner.ProcessHtml(input); Assert.Equal(Outputs.CssInliner_Should_Handle_PseudoClasses.Replace("~~TEST_SELECTOR~~", psuedoSelector).EliminateWhitespace(), processed.EliminateWhitespace()); }
/// <summary> /// Performs the actual (async) code generation. /// </summary> /// <param name="method">The method.</param> /// <param name="isExternalRequest">True, if processing of this method was requested by a user.</param> /// <param name="detectedMethods">The set of newly detected methods.</param> /// <param name="generatedMethod">The resolved IR method.</param> internal void GenerateCodeInternal( MethodBase method, bool isExternalRequest, HashSet <MethodBase> detectedMethods, out Method generatedMethod) { generatedMethod = Context.Declare(method, out bool created); if (!created & isExternalRequest) { return; } SequencePointEnumerator sequencePoints = DebugInformationManager?.LoadSequencePoints(method) ?? SequencePointEnumerator.Empty; var disassembler = new Disassembler(method, sequencePoints); var disassembledMethod = disassembler.Disassemble(); using (var builder = generatedMethod.CreateBuilder()) { var codeGenerator = new CodeGenerator( Frontend, builder, disassembledMethod, detectedMethods); codeGenerator.GenerateCode(); } // Evaluate inlining heuristic to adjust method declaration Inliner.SetupInliningAttributes( Context, generatedMethod, disassembledMethod); }
/// <summary> /// Performs the actual (asynchronous) code generation. /// </summary> /// <param name="method">The method.</param> /// <param name="isExternalRequest"> /// True, if processing of this method was requested by a user. /// </param> /// <param name="compilationStackLocation">The source location.</param> /// <param name="detectedMethods">The set of newly detected methods.</param> /// <param name="generatedMethod">The resolved IR method.</param> internal void GenerateCodeInternal( MethodBase method, bool isExternalRequest, CompilationStackLocation compilationStackLocation, Dictionary <MethodBase, CompilationStackLocation> detectedMethods, out Method generatedMethod) { ILocation location = null; try { generatedMethod = Context.Declare(method, out bool created); if (!created & isExternalRequest) { return; } location = generatedMethod; SequencePointEnumerator sequencePoints = DebugInformationManager?.LoadSequencePoints(method) ?? SequencePointEnumerator.Empty; var disassembler = new Disassembler( method, sequencePoints, compilationStackLocation); var disassembledMethod = disassembler.Disassemble(); using (var builder = generatedMethod.CreateBuilder()) { var codeGenerator = new CodeGenerator( Frontend, Context, builder, disassembledMethod, compilationStackLocation, detectedMethods); codeGenerator.GenerateCode(); builder.Complete(); } Verifier.Verify(generatedMethod); // Evaluate inlining heuristic to adjust method declaration Inliner.SetupInliningAttributes( Context, generatedMethod, disassembledMethod); } catch (InternalCompilerException) { // If we already have an internal compiler exception, re-throw it. throw; } catch (Exception e) { // Wrap generic exceptions with location information. location ??= new Method.MethodLocation(method); throw location.GetException(e); } }
public void TestInliningOfBasicProperty() { Expression<Func<ClassWithNames, bool>> predicate = c => c.FullNameSimple.Contains("Test"); // not a recommended database scenario var inliner = new Inliner(ExpressiveEngine.GetDecompiler()); var inlined = inliner.Inline(predicate, p => p.Name == "FullNameSimple"); Assert.AreEqual("c => String.Concat(c.FirstName, \" \", c.LastName).Contains(\"Test\")", ToStringVisitor.ToString(inlined)); }
public void TestInliningOfBasicProperty() { Expression <Func <ClassWithNames, bool> > predicate = c => c.FullNameSimple.Contains("Test"); // not a recommended database scenario var inliner = new Inliner(ExpressiveEngine.GetDecompiler()); var inlined = inliner.Inline(predicate, p => p.Name == "FullNameSimple"); Assert.AreEqual("c => String.Concat(c.FirstName, \" \", c.LastName).Contains(\"Test\")", ToStringVisitor.ToString(inlined)); }
private async Task VerifyTestCase(string key) { var data = await _loader.LoadData(key); var processed = Inliner.ProcessHtml(data.Input); Assert.Equal( data.Output.EliminateWhitespace(), processed.EliminateWhitespace()); }
private void doInlining(CBAProgram p) { inlineInput = new PersistentCBAProgram(p, p.mainProcName, p.contextBound); // Temporary fix for Boogie's bug while inlining calls // that have don't care expressions. This does not change the control // structure nor the number of commands per block -- hence, this transformation // need not be recorded. RewriteCallDontCares rdc = new RewriteCallDontCares(); rdc.VisitProgram(p); // Copy of OnlyBoogie.EliminateDeadVariablesAndInline var TopLevelDeclarations = p.TopLevelDeclarations; bool inline = false; foreach (Declaration d in TopLevelDeclarations) { if ((d is Procedure || d is Implementation) && d.FindExprAttribute("inline") != null) { inline = true; } } if (inline) { foreach (Declaration d in TopLevelDeclarations) { Implementation impl = d as Implementation; if (impl != null) { impl.OriginalBlocks = impl.Blocks; impl.OriginalLocVars = impl.LocVars; } } foreach (Declaration d in TopLevelDeclarations) { Implementation impl = d as Implementation; if (impl != null && !impl.SkipVerification) { Inliner.ProcessImplementation(p as Program, impl); } } foreach (Declaration d in TopLevelDeclarations) { Implementation impl = d as Implementation; if (impl != null) { impl.OriginalBlocks = null; impl.OriginalLocVars = null; } } } }
public void InlinerShouldRejectInvalidHtml() { Assert.Throws(typeof(Exception), () => { var html = Inliner.ProcessHtml(Inputs.Malformed_HTML_1); }); Assert.Throws(typeof(Exception), () => { var html = Inliner.ProcessHtml(Inputs.Malformed_HTML_2); }); }
//[InlineData(":nth-child(n)")] //[InlineData(":nth-last-child(n)")] //[InlineData(":nth-of-type(n)")] //[InlineData(":nth-last-of-type(n)")] //[InlineData(":first-child")] //[InlineData(":last-child")] //[InlineData(":first-of-type")] //[InlineData(":last-of-type")] //[InlineData(":empty")] public async Task ShouldHandlePseudoSelectors(string psuedoSelector) { var data = await _loader.LoadData("ShouldHandlePseudoSelectors"); var input = data.Input.Replace("~~TEST_SELECTOR~~", psuedoSelector); var output = data.Output.Replace("~~TEST_SELECTOR~~", psuedoSelector); var processed = Inliner.ProcessHtml(input); Assert.Equal(output.EliminateWhitespace(), processed.EliminateWhitespace()); }
public static void Inline(Program program) { Contract.Requires(program != null); // Inline var topLevelDeclarations = cce.NonNull(program.TopLevelDeclarations); if (CommandLineOptions.Clo.ProcedureInlining != CommandLineOptions.Inlining.None) { bool inline = false; foreach (var d in topLevelDeclarations) { if (d.FindExprAttribute("inline") != null) { inline = true; } } if (inline) { foreach (var d in topLevelDeclarations) { var impl = d as Implementation; if (impl != null) { impl.OriginalBlocks = impl.Blocks; impl.OriginalLocVars = impl.LocVars; } } foreach (var d in topLevelDeclarations) { var impl = d as Implementation; if (impl != null && !impl.SkipVerification) { Inliner.ProcessImplementation(program, impl); } } foreach (var d in topLevelDeclarations) { var impl = d as Implementation; if (impl != null) { impl.OriginalBlocks = null; impl.OriginalLocVars = null; } } } } }
private void InlineLeftAndRight() { var InlineImpl = new Action <Implementation>(i => { i.Proc.AddAttribute("inline", Expr.Literal(1)); i.OriginalBlocks = i.Blocks; i.OriginalLocVars = i.LocVars; }); InlineImpl(leftImpl); InlineImpl(rightImpl); Inliner.ProcessImplementation(mergedProg, eqImpl); Util.DumpBplAST(mergedProg, "mergedProg.bpl"); }
static void Main(string[] args) { Debug.Assert(args.Length > 0); ModuleDefMD targetModule = ModuleDefMD.Load(args[0]); ModuleDefMD runtimeModule = ModuleDefMD.Load("Confuser.Runtime.dll"); ClarifierContext ctx = new ClarifierContext { CurrentModule = targetModule, WriterListener = new MWListener(), //ILLanguage = il }; AntiDump antiDump = new AntiDump(); AntiDebug antiDebug = new AntiDebug(); Constants constants = new Constants(); AntiTamper antiTamper = new AntiTamper(); Inliner inliner = new Inliner(); inliner.PerformIdentification(ctx); inliner.PerformRemoval(ctx); antiTamper.Initialize(); antiTamper.PerformIdentification(ctx); antiTamper.PerformRemoval(ctx); antiDump.Initialize(ctx); antiDump.PerformIdentification(ctx); antiDump.PerformRemoval(ctx); antiDebug.Initialize(ctx); antiDebug.PerformIdentification(ctx); antiDebug.PerformRemoval(ctx); constants.Initialize(ctx); constants.PerformIdentification(ctx); constants.PerformRemoval(ctx); int lastBackslash = args[0].LastIndexOf('\\'); string targetExecutable = args[0].Substring(lastBackslash + 1, args[0].Length - 1 - lastBackslash); string parentDir = Directory.GetParent(Directory.GetParent(args[0]).FullName).FullName; parentDir = Path.Combine(parentDir, "Deobfuscated"); string destinationFile = Path.Combine(parentDir, targetExecutable); targetModule.Write(destinationFile); return; }
public void InliningBenchmark() { var runs = 5000; var startingHtmlContent = Inputs.EmailACIDTest; var runTime = Stopwatch.StartNew(); for (var i = 0; i < runs; i++) { var result = Inliner.ProcessHtml(startingHtmlContent); } runTime.Stop(); Console.WriteLine("Test Runs: {0}x, Total Time: {1}, Time/Run: {2}ms, Starting Content Length: {3}", runs, runTime.Elapsed, runTime.ElapsedMilliseconds / (double)runs, startingHtmlContent.Length); }
public static void Inline(Program program) { //perform inlining on the procedures IEnumerable <Declaration> impls = program.TopLevelDeclarations.Where(x => x is Implementation); foreach (Implementation impl in impls) { impl.OriginalBlocks = impl.Blocks; impl.OriginalLocVars = impl.LocVars; } foreach (Implementation impl in impls) { Inliner.ProcessImplementation(program, impl); } }
private static void RunOptionsAndReturnExitCode(Options opts) { var inputFile = opts.InputFile; var sourceHtml = GetDocument(inputFile); var processedHtml = Inliner.ProcessHtml(sourceHtml); var outputFile = opts.OutputFile; if (string.IsNullOrEmpty(outputFile)) { var name = System.IO.Path.GetFileNameWithoutExtension(inputFile); var ext = System.IO.Path.GetExtension(inputFile); outputFile = $"{name}.inline{ext}"; } System.IO.File.WriteAllText(outputFile, processedHtml); }
// This inlines a program to the given inline depth. // Note: Set the flag CommandLineOptions.Clo.ProcedureInlining to get the // desired effect on leaf-level procedure calls public static void InlineToDepth(Program program) { var impls = program.TopLevelDeclarations.OfType <Implementation>(); if (CommandLineOptions.Clo.InlineDepth < 0) { return; } /* * TODO: FIX! * foreach (Implementation impl in impls) * { * var inlineRequiresVisitor = new Microsoft.Boogie.Houdini.InlineRequiresVisitor(); * inlineRequiresVisitor.Visit(impl); * } * * foreach (Implementation impl in impls) * { * var freeRequiresVisitor = new Microsoft.Boogie.Houdini.FreeRequiresVisitor(); * freeRequiresVisitor.Visit(impl); * } */ foreach (Implementation impl in impls) { var inlineEnsuresVisitor = new Microsoft.Boogie.Houdini.InlineEnsuresVisitor(); inlineEnsuresVisitor.Visit(impl); } foreach (Implementation impl in impls) { impl.OriginalBlocks = impl.Blocks; impl.OriginalLocVars = impl.LocVars; } foreach (Implementation impl in impls) { Inliner.ProcessImplementationForHoudini(program, impl); } foreach (Implementation impl in impls) { impl.OriginalBlocks = null; impl.OriginalLocVars = null; } }
public void InlinerShouldApplyStylesAccordingToSpecificityValues() { var processed = Inliner.ProcessHtml(Inputs.InlinerShouldApplyStylesAccordingToSpecificityValues).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldApplyStylesAccordingToSpecificityValues.EliminateWhitespace(), processed); }
public void InlinerShouldNotApplyStylesToHead() { var processed = Inliner.ProcessHtml(Inputs.universal_selector_shouldnt_apply_styles_to_head_and_children).EliminateWhitespace(); Assert.Equal(Outputs.universal_selector_doesnt_apply_to_head.EliminateWhitespace(), processed); }
public void InlinerCanParseAndInlineEmailACIDTestCSS() { //TODO: this should attempt to produce exactly same result as Premailer. Inliner.ProcessHtml(Inputs.EmailACIDTest); }
public void InlinerShouldProperlyHandleDoubleQuotesInDeclarations() { var processed = Inliner.ProcessHtml(Inputs.inlined_url_declarations_should_not_have_spaces_added).EliminateWhitespace(); Assert.Equal(Outputs.style_sheet_attributes_with_quotes_should_be_handled_properly.EliminateWhitespace(), processed); }
public void InlinerShouldParseRawHtml() { //This not throwing implicitly means that the parsing is OK. var result = Inliner.ProcessHtml(Inputs.HTML5_Boilerplate); }
public void InlinerShouldFixDoctypeToOriginalAfterProcessing() { var processed = Inliner.ProcessHtml(Inputs.html_with_double_quote_doctype).EliminateWhitespace(); Assert.Equal((Inputs.html_with_double_quote_doctype).EliminateWhitespace(), processed); }
public void InlinerShouldSkipInvalidCSSDeclarations() { var html = Inliner.ProcessHtml(Inputs.InlinerShouldSkipInvalidCSSDeclarations).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldSkipInvalidCSSDeclarations.EliminateWhitespace(), html); }
public void InlinerShouldEliminateScriptBlocks() { var processed = Inliner.ProcessHtml(Inputs.InlinerShouldEliminateScriptBlocks).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldEliminateScriptBlocks.EliminateWhitespace(), processed); }
public static int RVTRunVerificationTask(SDiff.VerificationTask vt, VC.ConditionGeneration vcgen, Program prog, HashSet <int> inlinedFns1, HashSet <int> inlinedFns2, out bool crashed) { Log.Out(Log.Verifier, "Verifying " + vt.Eq.Name); crashed = false; var attList = new List <Object>(1); attList.Add(Expr.Literal(1)); //save attributes var sqkLeft = vt.Left.Attributes; var sqkpLeft = vt.Left.Proc.Attributes; var sqkRight = vt.Right.Attributes; var sqkpRight = vt.Right.Proc.Attributes; //save postconditions var leftPosts = vt.Left.Proc.Ensures; var rightPosts = vt.Right.Proc.Ensures; //Keep the postconditions correpsonding to the //free ensures (out == uf_Foo(inp)) //vt.Left.Proc.Ensures = new List<Ensures>(); //vt.Right.Proc.Ensures = new List<Ensures>(); //inline procedures under analysis vt.Left.Attributes = Util.MkInlinedAttribute(attList); vt.Left.Proc.Attributes = vt.Left.Attributes; vt.Right.Attributes = Util.MkInlinedAttribute(attList); vt.Right.Proc.Attributes = vt.Right.Attributes; vt.Left.OriginalBlocks = vt.Left.Blocks; vt.Left.OriginalLocVars = vt.Left.LocVars; vt.Right.OriginalBlocks = vt.Right.Blocks; vt.Right.OriginalLocVars = vt.Right.LocVars; IEnumerable <Declaration> procImplPIter = prog.TopLevelDeclarations.Where(x => x is Implementation); List <Implementation> inlinedImpls = new List <Implementation>(); foreach (Implementation currentProcImpl in procImplPIter) { bool match = false; int indx = -1; if (fnNameToIndex1.ContainsKey(currentProcImpl.Proc.Name)) { match = true; indx = fnNameToIndex1[currentProcImpl.Proc.Name]; } else if (fnNameToIndex2.ContainsKey(currentProcImpl.Proc.Name)) { match = true; indx = fnNameToIndex2[currentProcImpl.Proc.Name]; } //Inline if present in if (match && (inlinedFns1.Contains(indx) || inlinedFns2.Contains(indx))) { inlinedImpls.Add(currentProcImpl); currentProcImpl.Attributes = Util.MkInlinedAttribute(attList); currentProcImpl.Proc.Attributes = Util.MkInlinedAttribute(attList); //RUN INLINER OVER EQ FUNCTION currentProcImpl.OriginalBlocks = currentProcImpl.Blocks; currentProcImpl.OriginalLocVars = currentProcImpl.LocVars; } } //RUN INLINER OVER EQ FUNCTION // prog = EQ program // vt.Eq = EQ_f_f' procedure with f, f' having {inline} tags Inliner.ProcessImplementation(prog, vt.Eq); if (Options.TraceVerify) { Log.Out(Log.Normal, "Ready to verify:"); Log.LogEmit(Log.Normal, prog.Emit); } // To print the EQ files in Util.DumpBplAST(prog, vt.Eq.Name + "_out.bpl"); // prog = SDiff.Boogie.Process.ParseProgram(vt.Eq.Name + "_out.bpl"); if (BoogieUtils.ResolveAndTypeCheckThrow(prog, Options.MergedProgramOutputFile)) { return(1); } Implementation newEq = vt.Eq; var newProg = prog; vcgen = BoogieVerify.InitializeVC(newProg); //SDiff.Boogie.Process.ResolveAndTypeCheck(newProg, ""); var newDict = SDiff.Boogie.Process.BuildProgramDictionary(newProg.TopLevelDeclarations.ToList()); //newEq = (Implementation)newDict.Get(vt.Eq.Name + "$IMPL"); SDiffCounterexamples SErrors; List <Model> errModelList; //Clear up the state since it might call the same procedure twice vt.Result = BoogieVerify.VerifyImplementation(vcgen, newEq, newProg, out SErrors, out errModelList); switch (vt.Result) { case SDiff.VerificationResult.Error: Log.Out(Log.Verifier, "Result: Error"); break; case SDiff.VerificationResult.Verified: Log.Out(Log.Verifier, "Result: Verified"); break; default: Log.Out(Log.Verifier, "Result: Unhandled"); crashed = true; break; } //restore postconditions IN THE OLD IN-MEMORY PROGRAM vt.Left.Proc.Ensures = leftPosts; vt.Right.Proc.Ensures = rightPosts; //remove the inline annotation IN THE OLD IN-MEMORY PROGRAM vt.Left.Attributes = sqkLeft; vt.Left.Proc.Attributes = sqkpLeft; vt.Right.Attributes = sqkRight; vt.Right.Proc.Attributes = sqkpRight; //remove the inline annotation in the Inlined Procedures foreach (Implementation currentProcImpl in procImplPIter) { if (inlinedImpls.Contains(currentProcImpl)) { currentProcImpl.Attributes = null; currentProcImpl.Proc.Attributes = null; } } if (vt.Result == SDiff.VerificationResult.Verified) { return(1); } else { return(0); } }
public void InlinerShouldApplyStylesInDocumentOrder() { var processed = Inliner.ProcessHtml(Inputs.InlinerShouldApplyStylesInDocumentOrder).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldApplyStylesInDocumentOrder.EliminateWhitespace(), processed); }
public void InlinerShouldApplyStylesForRulesWithMultipleSelectors() { var processed = Inliner.ProcessHtml(Inputs.InlinerShouldApplyStylesForRulesWithMultipleSelectors).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldApplyStylesForRulesWithMultipleSelectors.EliminateWhitespace(), processed); }
public void InlinerShouldEliminateStyleBlocksWhereAllRulesAreInlined() { var processed = Inliner.ProcessHtml(Inputs.InlinerShouldEliminateStyleBlocksWhereAllRulesAreInlined).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldEliminateStyleBlocksWhereAllRulesAreInlined.EliminateWhitespace(), processed); }
public void InlinerShouldKeepMediaQueryStylesInStyleBlocks() { var processed = Inliner.ProcessHtml(Inputs.InlinerShouldKeepMediaQueryStylesInStyleBlocks).EliminateWhitespace(); Assert.Equal(Outputs.Expected_InlinerShouldKeepMediaQueryStylesInStyleBlocks.EliminateWhitespace(), processed); }
public void InlinerShouldMaintainImportantDeclarations() { var processed = Inliner.ProcessHtml(Inputs.inliner_should_maintain_important_stats).EliminateWhitespace(); Assert.Equal(Outputs.inliner_should_maintain_important_declaration.EliminateWhitespace(), processed); }