Example #1
0
        /// <inheritdoc />
        public override SymbolicProgramState <CilInstruction> GetInitialState(long entrypointAddress)
        {
            var result = base.GetInitialState(entrypointAddress);

            foreach (var eh in _architecture.MethodBody.ExceptionHandlers)
            {
                if (eh.HandlerType == CilExceptionHandlerType.Fault ||
                    eh.HandlerType == CilExceptionHandlerType.Finally)
                {
                    continue;
                }

                var exceptionSource = default(ExternalDataSourceNode <CilInstruction>);
                if (eh.HandlerStart.Offset == entrypointAddress)
                {
                    exceptionSource = new ExternalDataSourceNode <CilInstruction>(
                        -(long)eh.HandlerStart.Offset,
                        $"HandlerException_{eh.HandlerStart.Offset:X4}");
                }
                else if (eh.FilterStart != null && eh.FilterStart.Offset == entrypointAddress)
                {
                    exceptionSource = new ExternalDataSourceNode <CilInstruction>(
                        -(long)eh.FilterStart.Offset,
                        $"FilterException_{eh.FilterStart.Offset:X4}");
                }

                if (exceptionSource is {})
        public void EntryPointPopWithSingleItemOnStackShouldAddDependencyToExternalSource()
        {
            var instructions = new[]
            {
                DummyInstruction.Pop(0, 1),
                DummyInstruction.Ret(1),
            };

            var dfgBuilder = new DummyTransitionResolver();
            var argument   = new ExternalDataSourceNode <DummyInstruction>(-1, "Argument 1");

            dfgBuilder.DataFlowGraph.Nodes.Add(argument);
            dfgBuilder.InitialState = new SymbolicProgramState <DummyInstruction>();
            dfgBuilder.InitialState.Stack.Push(new SymbolicValue <DummyInstruction>(argument));

            var cfgBuilder = new SymbolicFlowGraphBuilder <DummyInstruction>(
                DummyArchitecture.Instance,
                instructions,
                dfgBuilder);

            cfgBuilder.ConstructFlowGraph(0);
            var dfg = dfgBuilder.DataFlowGraph;

            Assert.Equal(new[] { argument }, dfg.Nodes[0].StackDependencies[0].GetNodes());
        }
        /// <inheritdoc />
        public override SymbolicProgramState <Instruction> GetInitialState(long entrypointAddress)
        {
            var result = base.GetInitialState(entrypointAddress);

            for (int i = 0; i < _architecture.MethodBody.ExceptionHandlers.Count; i++)
            {
                var handler = _architecture.MethodBody.ExceptionHandlers[i];
                if (handler.HandlerType == ExceptionHandlerType.Fault ||
                    handler.HandlerType == ExceptionHandlerType.Finally)
                {
                    continue;
                }

                var exceptionSource = default(ExternalDataSourceNode <Instruction>);
                if (handler.HandlerStart.Offset == entrypointAddress)
                {
                    exceptionSource = new ExternalDataSourceNode <Instruction>(
                        -handler.HandlerStart.Offset,
                        $"HandlerException_{handler.HandlerStart.Offset:X4}");
                }
                else if (handler.FilterStart != null && handler.FilterStart.Offset == entrypointAddress)
                {
                    exceptionSource = new ExternalDataSourceNode <Instruction>(
                        -handler.FilterStart.Offset,
                        $"FilterException_{handler.FilterStart.Offset:X4}");
                }

                if (exceptionSource is { })
Example #4
0
        internal AstVariable GetExternalVariable(ExternalDataSourceNode <TInstruction> external)
        {
            if (ExternalSources.TryGetValue(external, out var variable))
            {
                return(variable);
            }

            variable = new AstVariable(external.Name);
            ExternalSources.Add(external, variable);

            return(variable);
        }