示例#1
0
        public AnalysisNet.Types.MethodBody ExtractBody(Cecil.Cil.MethodBody cciBody)
        {
            cecilBody = cciBody;
            AnalysisNet.Types.MethodBody ourBody = new AnalysisNet.Types.MethodBody(AnalysisNet.Types.MethodBodyKind.Bytecode)
            {
                MaxStack = (ushort)cciBody.MaxStackSize
            };
            ExtractParameters(cciBody.Method, ourBody.Parameters);
            ExtractLocalVariables(cciBody.Variables, ourBody.LocalVariables);
            ExtractExceptionInformation(cciBody.ExceptionHandlers, ourBody.ExceptionInformation);
            ExtractInstructions(cciBody.Instructions, ourBody.Instructions);

            return(ourBody);
        }
示例#2
0
        private void CreateExceptionHandlers(IDictionary <Model.Bytecode.Instruction, IList <Mono.Cecil.Cil.Instruction> > map,
                                             AnalysisNet.Types.MethodBody analysisNetBody,
                                             Cecil.Cil.MethodBody cecilBody)
        {
            foreach (AnalysisNet.ProtectedBlock protectedBlock in analysisNetBody.ExceptionInformation)
            {
                Cecil.Cil.ExceptionHandler handler = new Cecil.Cil.ExceptionHandler(GetExceptionHandlerType(protectedBlock.Handler.Kind))
                {
                    TryStart = GetTarget(protectedBlock.Start, map),
                    TryEnd   = GetTarget(protectedBlock.End, map)
                };

                if (protectedBlock.Handler is AnalysisNet.FilterExceptionHandler filterHandler)
                {
                    handler.CatchType    = ReferenceGenerator.TypeReference(filterHandler.ExceptionType);
                    handler.FilterStart  = GetTarget(filterHandler.FilterStart, map);
                    handler.HandlerStart = GetTarget(filterHandler.Start, map);
                    handler.HandlerEnd   = GetTarget(filterHandler.End, map);
                }
                else if (protectedBlock.Handler is AnalysisNet.CatchExceptionHandler catchHandler)
                {
                    handler.CatchType    = ReferenceGenerator.TypeReference(catchHandler.ExceptionType);
                    handler.HandlerStart = GetTarget(catchHandler.Start, map);
                    handler.HandlerEnd   = GetTarget(catchHandler.End, map);
                }
                else if (protectedBlock.Handler is AnalysisNet.FaultExceptionHandler faultHandler)
                {
                    handler.HandlerStart = GetTarget(faultHandler.Start, map);
                    handler.HandlerEnd   = GetTarget(faultHandler.End, map);
                }
                else if (protectedBlock.Handler is AnalysisNet.FinallyExceptionHandler finallyHandler)
                {
                    handler.HandlerStart = GetTarget(finallyHandler.Start, map);
                    handler.HandlerEnd   = GetTarget(finallyHandler.End, map);
                }
                else
                {
                    throw new NotImplementedException();
                }

                cecilBody.ExceptionHandlers.Add(handler);
            }
        }