Exemple #1
0
            public Tracker(TypedInstructionCollection instructions)
            {
                var graph        = new ControlFlowGraph(instructions);
                var initialState = new Lattice(instructions, new State(0));

                var data = new DataFlow <Lattice>(instructions, graph.Roots);
                Dictionary <BasicBlock, Lattice> lattices = data.Analyze(new Lattice.Functions(), initialState);

                m_states = new State[instructions.Length];
                foreach (var entry in lattices)
                {
                    BasicBlock block = entry.Key;
                    if (block.Length > 0)
                    {
                        Lattice lattice = entry.Value;

                        for (int index = block.First.Index; index <= block.Last.Index; ++index)                         // it'd be nice to assert that every index was set, but methods often have dead code so it's a little difficult
                        {
                            m_states[index] = lattice.State;
                            lattice         = lattice.Transform(index);
                        }
                    }
                }

                for (int index = 0; index < instructions.Length; ++index)
                {
                    Log.DebugLine(this, "{0:X2}: {1}", instructions[index].Untyped.Offset, m_states[index]);
                }
            }
Exemple #2
0
            public void Analyze(ControlFlowGraph graph)
            {
                DBC.Pre(graph != null, "graph is null");

                Profile.Start("Splicing");
                var visited = new List <BasicBlock>();

                foreach (BasicBlock root in graph.Roots)
                {
                    DoSpliceHandlers(m_instructions, root, visited);
                }

                visited.Clear();
                foreach (BasicBlock root in graph.Roots)
                {
                    DoSpliceNullCheck(m_instructions, root, visited);
                }
                var data = new DataFlow <Lattice>(m_instructions, graph.Roots);

                m_skipped = data.Skipped;
                Profile.Stop("Splicing");

                var functions = new Lattice.Functions();
                Dictionary <BasicBlock, Lattice> lattices = data.Analyze(functions, m_initialState);

                Profile.Start("Post Transform");
                m_states = new State[m_instructions.Length];
                foreach (var entry in lattices)
                {
                    BasicBlock block = entry.Key;
                    if (block.Length > 0)
                    {
                        Lattice lattice = entry.Value;

                        for (int index = block.First.Index; index <= block.Last.Index; ++index)                         // it'd be nice to assert that every index was set, but methods often have dead code so it's a little difficult
                        {
                            m_states[index] = lattice.State;
                            lattice         = lattice.Transform(index);
                        }
                    }
                }
                Profile.Stop("Post Transform");

                for (int index = 0; index < m_instructions.Length; ++index)
                {
                    Log.DebugLine(this, "{0:X2}: {1}", m_instructions[index].Untyped.Offset, m_states[index]);
                }
            }
Exemple #3
0
			public void Analyze(ControlFlowGraph graph)
			{				
				DBC.Pre(graph != null, "graph is null");

				Profile.Start("Splicing");
				var visited = new List<BasicBlock>();
				foreach (BasicBlock root in graph.Roots)
					DoSpliceHandlers(m_instructions, root, visited);

				visited.Clear();
				foreach (BasicBlock root in graph.Roots)
					DoSpliceNullCheck(m_instructions, root, visited);
				var data = new DataFlow<Lattice>(m_instructions, graph.Roots);
				m_skipped = data.Skipped;
				Profile.Stop("Splicing");
				
				var functions = new Lattice.Functions();
				Dictionary<BasicBlock, Lattice> lattices = data.Analyze(functions, m_initialState);
				
				Profile.Start("Post Transform");
				m_states = new State[m_instructions.Length];
				foreach (var entry in lattices)
				{
					BasicBlock block = entry.Key;
					if (block.Length > 0)
					{
						Lattice lattice = entry.Value;
						
						for (int index = block.First.Index; index <= block.Last.Index; ++index)	// it'd be nice to assert that every index was set, but methods often have dead code so it's a little difficult
						{
							m_states[index] = lattice.State;
							lattice = lattice.Transform(index);
						}
					}
				}
				Profile.Stop("Post Transform");
				
				for (int index = 0; index < m_instructions.Length; ++index)
				{
					Log.DebugLine(this, "{0:X2}: {1}", m_instructions[index].Untyped.Offset, m_states[index]);
				}
			}