public static GraphProvider Create(MethodDef method)
        {
            var methodName = IdentifierEscaper.Escape(method.Name);

            switch (method.MethodBody)
            {
            case CilBody _:
            {
                var arch          = new CilArchitecture(method);
                var stateResolver = new CilStateTransitionResolver(arch);
                var cflowBuilder  = new SymbolicFlowGraphBuilder <Instruction>(arch, method.Body.Instructions, stateResolver);
                var cflow         = cflowBuilder.ConstructFlowGraph(0);
                return(new ControlFlowGraphProvider <Instruction>(methodName, cflow));
            }

            case NativeMethodBody _:
            {
                var cflow = IcedHelpers.ReadNativeMethodBody(method);
                return(new ControlFlowGraphProvider <Iced.Intel.Instruction>(methodName, cflow));
            }

            default:
                throw new Exception("Tried to create graph for method that has neither managed nor native body");
            }
        }
示例#2
0
        protected override void Execute(MethodDef method)
        {
            var encodedBytes = IcedHelpers.ReadNativeMethodBodyBytes(method);
            var is32Bit      = !method.Module.IsAMD64;

            var block = new NativeCodeBlock(NativeCodeBlockKind.Code, (uint)method.NativeBody.RVA, new ArraySegment <byte>(encodedBytes), null);
            var vars  = new NativeVariableInfo[method.Parameters.Count];

            for (var i = 0; i < method.Parameters.Count; i++)
            {
                vars[i] = new NativeVariableInfo(false, i, method.Parameters[i].Name);
            }

            var native = new NativeCode(is32Bit ? NativeCodeKind.X86_32 : NativeCodeKind.X86_64,
                                        NativeCodeOptimization.Unknown, new[] { block }, null, vars,
                                        method.FullName, IdentifierEscaper.Escape(method.Name), method.Module.Name);

            var contentProvider = fac.Create(native, DisassemblyContentFormatterOptions.None, null, null);

            disassemblyViewerService.Value.Show(contentProvider, true);
        }
示例#3
0
        public static GraphProvider Create(MethodDef method)
        {
            var methodName = IdentifierEscaper.Escape(method.Name);

            switch (method.MethodBody)
            {
            case CilBody cilBody:
            {
                var cflow = method.ConstructStaticFlowGraph();
                return(new ControlFlowGraphProvider <Instruction>(methodName, cflow));
            }

            case NativeMethodBody _:
            {
                var cflow = IcedHelpers.ReadNativeMethodBody(method);
                return(new ControlFlowGraphProvider <Iced.Intel.Instruction>(methodName, cflow));
            }

            default:
                throw new Exception("Tried to create graph for method that has neither managed nor native body");
            }
        }