protected override void RunTest(Program prog, TextWriter writer)
        {
            DataFlowAnalysis dfa = new DataFlowAnalysis(prog, new FakeDecompilerEventListener());
            dfa.UntangleProcedures();
            foreach (Procedure proc in prog.Procedures.Values)
            {
                var larw = new LongAddRewriter(proc, prog.Architecture);
                larw.Transform();

                Aliases alias = new Aliases(proc, prog.Architecture, dfa.ProgramDataFlow);
                alias.Transform();
                var sst = new SsaTransform(dfa.ProgramDataFlow, proc, proc.CreateBlockDominatorGraph());
                SsaState ssa = sst.SsaState;

                proc.Dump(true, false);

                var vp = new ValuePropagator(ssa.Identifiers, proc);
                vp.Transform();

                var cce = new ConditionCodeEliminator(ssa.Identifiers, prog.Platform);
                cce.Transform();
                DeadCode.Eliminate(proc, ssa);

                ssa.Write(writer);
                proc.Write(false, writer);
                writer.WriteLine();
            }
        }
Esempio n. 2
0
 protected override void RunTest(Program prog, TextWriter writer)
 {
     var dfa = new DataFlowAnalysis(prog, new FakeDecompilerEventListener());
     var eventListener = new FakeDecompilerEventListener();
     var trf = new TrashedRegisterFinder(prog, prog.Procedures.Values, dfa.ProgramDataFlow, eventListener);
     trf.Compute();
     trf.RewriteBasicBlocks();
     RegisterLiveness rl = RegisterLiveness.Compute(prog, dfa.ProgramDataFlow, eventListener);
     foreach (Procedure proc in prog.Procedures.Values)
     {
         LongAddRewriter larw = new LongAddRewriter(proc, prog.Architecture);
         larw.Transform();
         proc.Write(false, writer);
         writer.WriteLine();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Processes procedures individually, building complex expression trees out
        /// of the simple, close-to-the-machine code generated by the disassembly.
        /// </summary>
        /// <param name="rl"></param>
		public void BuildExpressionTrees()
		{
            int i = 0;
			foreach (Procedure proc in program.Procedures.Values)
			{
                eventListener.ShowProgress("Building complex expressions.", i, program.Procedures.Values.Count);
                ++i;

                try
                {
                    var larw = new LongAddRewriter(proc, program.Architecture);
                    larw.Transform();

                    Aliases alias = new Aliases(proc, program.Architecture, flow);
                    alias.Transform();

                    var doms = new DominatorGraph<Block>(proc.ControlGraph, proc.EntryBlock);
                    var sst = new SsaTransform(flow, proc, doms);
                    var ssa = sst.SsaState;

                    var cce = new ConditionCodeEliminator(ssa.Identifiers, program.Platform);
                    cce.Transform();
                    DeadCode.Eliminate(proc, ssa);

                    var vp = new ValuePropagator(ssa.Identifiers, proc);
                    vp.Transform();
                    DeadCode.Eliminate(proc, ssa);

                    // Build expressions. A definition with a single use can be subsumed
                    // into the using expression. 

                    var coa = new Coalescer(proc, ssa);
                    coa.Transform();
                    DeadCode.Eliminate(proc, ssa);

                    var liv = new LinearInductionVariableFinder(
                        proc,
                        ssa.Identifiers,
                        new BlockDominatorGraph(proc.ControlGraph, proc.EntryBlock));
                    liv.Find();

                    foreach (KeyValuePair<LinearInductionVariable, LinearInductionVariableContext> de in liv.Contexts)
                    {
                        var str = new StrengthReduction(ssa, de.Key, de.Value);
                        str.ClassifyUses();
                        str.ModifyUses();
                    }
                    var opt = new OutParameterTransformer(proc, ssa.Identifiers);
                    opt.Transform();
                    DeadCode.Eliminate(proc, ssa);

                    // Definitions with multiple uses and variables joined by PHI functions become webs.
                    var web = new WebBuilder(proc, ssa.Identifiers, program.InductionVariables);
                    web.Transform();
                    ssa.ConvertBack(false);
                }
                catch (Exception ex)
                {
                    eventListener.Error(new NullCodeLocation(proc.Name), ex, "An error occurred during data flow analysis.");
                }
			} 
		}
Esempio n. 4
0
 public void Setup()
 {
     m = new ProcedureBuilder(arch);
     frame = m.Frame;
     ax = frame.EnsureRegister(new RegisterStorage("ax", 0, PrimitiveType.Word16));
     bx = frame.EnsureRegister(new RegisterStorage("bx", 3, PrimitiveType.Word16));
     cx = frame.EnsureRegister(new RegisterStorage("cx", 1, PrimitiveType.Word16));
     dx = frame.EnsureRegister(new RegisterStorage("dx", 2, PrimitiveType.Word16));
     SCZ = frame.EnsureFlagGroup(7, "SCZ", PrimitiveType.Byte);
     CF = frame.EnsureFlagGroup(arch.CarryFlagMask, "C", PrimitiveType.Bool);
     rw = new LongAddRewriter(m.Procedure, arch);
     Procedure proc = new Procedure("test", frame);
     block = new Block(proc, "bloke");
 }