• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cil.ExceptionHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Mono.Cecil.Cil.ExceptionHandler的典型用法代码示例。如果您正苦于以下问题:C# ExceptionHandler类的具体用法?C# ExceptionHandler怎么用?C# ExceptionHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ExceptionHandler类属于Mono.Cecil.Cil命名空间,在下文中一共展示了ExceptionHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: readExceptionHandler

        protected override ExceptionHandler readExceptionHandler()
        {
            var eh = new ExceptionHandler((ExceptionHandlerType)reader.ReadInt32());

            int tryOffset = reader.ReadInt32();
            eh.TryStart = getInstruction(tryOffset);
            eh.TryEnd = getInstructionOrNull(tryOffset + reader.ReadInt32());

            int handlerOffset = reader.ReadInt32();
            eh.HandlerStart = getInstruction(handlerOffset);
            eh.HandlerEnd = getInstructionOrNull(handlerOffset + reader.ReadInt32());

            switch (eh.HandlerType) {
            case ExceptionHandlerType.Catch:
                eh.CatchType = (TypeReference)module.LookupToken(reader.ReadInt32());
                break;

            case ExceptionHandlerType.Filter:
                eh.FilterStart = getInstruction(reader.ReadInt32());
                break;

            case ExceptionHandlerType.Finally:
            case ExceptionHandlerType.Fault:
            default:
                reader.ReadInt32();
                break;
            }

            return eh;
        }
开发者ID:Joelone,项目名称:de4dot,代码行数:30,代码来源:MethodBodyReader.cs


示例2: InitForm

        public void InitForm(MethodDefinition md, int ehIndex)
        {
            if (_method == md && _ehIndex == ehIndex) return;

            _method = md;
            _ehIndex = ehIndex;
            if (_ehIndex < 0)
            {
                _eh = new ExceptionHandler(ExceptionHandlerType.Catch);
                _eh.CatchType = _method.Module.Import(typeof(System.Exception));                
                InitTypes(ExceptionHandlerType.Catch);
            }
            else
            {
                _eh = _method.Body.ExceptionHandlers[_ehIndex];
                if(_eh.CatchType == null)
                    _eh.CatchType = _method.Module.Import(typeof(System.Exception));                
                InitTypes(_eh.HandlerType);
            }

            txtCatchType.Text = _eh.CatchType.FullName;

            InsUtils.InitInstructionsCombobox(cboTryStart, _method, _eh.TryStart, ref instructionsStr);
            InsUtils.InitInstructionsCombobox(cboTryEnd, _method, _eh.TryEnd, ref instructionsStr);

            InsUtils.InitInstructionsCombobox(cboHandlerStart, _method, _eh.HandlerStart, ref instructionsStr);
            InsUtils.InitInstructionsCombobox(cboHandlerEnd, _method, _eh.HandlerEnd, ref instructionsStr);

            InsUtils.InitInstructionsCombobox(cboFilterStart, _method, _eh.FilterStart, ref instructionsStr);
            //InsUtils.InitInstructionsCombobox(cboFilterEnd, _method, _eh.FilterEnd, ref instructionsStr);

        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:32,代码来源:frmClassEditExceptionHandler.cs


示例3: ThrowsGeneralException

		private bool ThrowsGeneralException (ExceptionHandler exceptionHandler) 
		{
			for (Instruction currentInstruction = exceptionHandler.HandlerStart; currentInstruction != exceptionHandler.HandlerEnd; currentInstruction = currentInstruction.Next) {
				if (currentInstruction.OpCode.Code == Code.Rethrow)
					return true;
			}
			return false;
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:8,代码来源:DontSwallowErrorsCatchingNonspecificExceptionsRule.cs


示例4: Debug_RemoveExceptionHandler

 internal void Debug_RemoveExceptionHandler(ExceptionHandler eh, MethodBody mb)
 {
     var catchStart = mb.Instructions.IndexOf(eh.HandlerStart) - 1;
     var catchEnd = mb.Instructions.IndexOf(eh.HandlerEnd);
     for (var i = catchEnd - 1; i >= catchStart; i--)
     {
         mb.Instructions.RemoveAt(i);
     }
     mb.ExceptionHandlers.Remove(eh);
 }
开发者ID:Gnomodia,项目名称:Gnomodia,代码行数:10,代码来源:Injector.cs


示例5: ComputeExceptionHandlerData

 private void ComputeExceptionHandlerData(Dictionary<int, ExceptionHandlerData> datas, ExceptionHandler handler)
 {
     ExceptionHandlerData data;
     if (!datas.TryGetValue(handler.TryStart.Offset, out data))
     {
         data = new ExceptionHandlerData(this.ComputeRange(handler.TryStart, handler.TryEnd));
         datas.Add(handler.TryStart.Offset, data);
     }
     this.ComputeExceptionHandlerData(data, handler);
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:10,代码来源:ControlFlowGraphBuilder.cs


示例6: ProcessMethod

        private static void ProcessMethod(AssemblyDefinition def, TypeDefinition type, MethodDefinition method)
        {
            if (!method.HasBody || method.Body.Instructions.Count < 1)
                return;

            var newHandler = new ExceptionHandler(ExceptionHandlerType.Catch);
            newHandler.TryStart = method.Body.Instructions[0];
            newHandler.TryEnd = method.Body.Instructions[method.Body.Instructions.Count - 1];
            // todo: add handler to body (create new static class to avoid code bloat) and register bounds with newHandler
            method.Body.ExceptionHandlers.Add(newHandler);
        }
开发者ID:stschake,项目名称:obfuscatus,代码行数:11,代码来源:ExceptionReporter.cs


示例7: FormatHandlerType

        static string FormatHandlerType(ExceptionHandler handler)
        {
            var handler_type = handler.HandlerType;
            var type = handler_type.ToString ().ToLowerInvariant ();

            switch (handler_type) {
            case ExceptionHandlerType.Catch:
                return string.Format ("{0} {1}", type, handler.CatchType.FullName);
            case ExceptionHandlerType.Filter:
                throw new NotImplementedException ();
            default:
                return type;
            }
        }
开发者ID:jbevain,项目名称:cecil,代码行数:14,代码来源:Formatter.cs


示例8: getExceptionString

 string getExceptionString(ExceptionHandler ex)
 {
     var sb = new StringBuilder();
     if (ex.TryStart != null)
         sb.Append(string.Format("TRY: {0}-{1}", getLabel(ex.TryStart), getLabel(ex.TryEnd)));
     if (ex.FilterStart != null)
         sb.Append(string.Format(", FILTER: {0}", getLabel(ex.FilterStart)));
     if (ex.HandlerStart != null)
         sb.Append(string.Format(", HANDLER: {0}-{1}", getLabel(ex.HandlerStart), getLabel(ex.HandlerEnd)));
     sb.Append(string.Format(", TYPE: {0}", ex.HandlerType));
     if (ex.CatchType != null)
         sb.Append(string.Format(", CATCH: {0}", ex.CatchType));
     return sb.ToString();
 }
开发者ID:Joelone,项目名称:de4dot,代码行数:14,代码来源:MethodPrinter.cs


示例9: patchXamarinFormsCoreDll

        static void patchXamarinFormsCoreDll(string path, string typeName, string methodName)
        {
            var assembly = AssemblyDefinition.ReadAssembly (path);
            ModuleDefinition module = assembly.MainModule;
            TypeDefinition mainClass = module.GetType (typeName);
            MethodDefinition method = mainClass.Methods.Single (m => m.Name == methodName);

            var printPath = Path.GetFileName (path.Replace ("\\", "/").Replace ("../", ""));
            Console.WriteLine (string.Format ("Patch {0}.dll: {1}: {2}", printPath, methodName, method.Body.ExceptionHandlers.Count > 0 ? "already done" : "patch now"));
            if (method.Body.ExceptionHandlers.Count == 0) {

                var il = method.Body.GetILProcessor ();

                var write = il.Create (OpCodes.Call, module.Import (typeof(Console).GetMethod ("WriteLine", new [] { typeof(object) })));
                var ret = il.Create (OpCodes.Ret);
                var leave = il.Create (OpCodes.Leave, ret);

                il.InsertAfter (method.Body.Instructions.Last (), write);
                il.InsertAfter (write, leave);
                il.InsertAfter (leave, ret);

                var handler = new ExceptionHandler (ExceptionHandlerType.Catch) {
                    TryStart = method.Body.Instructions.First (),
                    TryEnd = write,
                    HandlerStart = write,
                    HandlerEnd = ret,
                    CatchType = module.Import (typeof(Exception)),
                };

                method.Body.ExceptionHandlers.Add (handler);

                string pathPatched = path + ".patched.dll";
                assembly.Write (pathPatched);
                File.Copy (pathPatched, path, true);
                File.Delete (pathPatched);
            }
        }
开发者ID:tobiasschulz,项目名称:xamarin-patch-24402,代码行数:37,代码来源:Program.cs


示例10: ReadSection

		void ReadSection (MethodBody body, BinaryReader br)
		{
			br.BaseStream.Position += 3;
			br.BaseStream.Position &= ~3;

			byte flags = br.ReadByte ();
			if ((flags & (byte) MethodDataSection.FatFormat) == 0) {
				int length = br.ReadByte () / 12;
				br.ReadBytes (2);

				for (int i = 0; i < length; i++) {
					ExceptionHandler eh = new ExceptionHandler (
						(ExceptionHandlerType) (br.ReadInt16 () & 0x7));
					eh.TryStart = GetInstruction (body, Convert.ToInt32 (br.ReadInt16 ()));
					eh.TryEnd = GetInstruction (body, eh.TryStart.Offset + Convert.ToInt32 (br.ReadByte ()));
					eh.HandlerStart = GetInstruction (body, Convert.ToInt32 (br.ReadInt16 ()));
					eh.HandlerEnd = GetInstruction (body, eh.HandlerStart.Offset + Convert.ToInt32 (br.ReadByte ()));
					ReadExceptionHandlerEnd (eh, br, body);
					body.ExceptionHandlers.Add (eh);
				}
			} else {
				br.BaseStream.Position--;
				int length = (br.ReadInt32 () >> 8) / 24;
				if ((flags & (int) MethodDataSection.EHTable) == 0)
					br.ReadBytes (length * 24);
				for (int i = 0; i < length; i++) {
					ExceptionHandler eh = new ExceptionHandler (
						(ExceptionHandlerType) (br.ReadInt32 () & 0x7));
					eh.TryStart = GetInstruction (body, br.ReadInt32 ());
					eh.TryEnd = GetInstruction (body, eh.TryStart.Offset + br.ReadInt32 ());
					eh.HandlerStart = GetInstruction (body, br.ReadInt32 ());
					eh.HandlerEnd = GetInstruction (body, eh.HandlerStart.Offset + br.ReadInt32 ());
					ReadExceptionHandlerEnd (eh, br, body);
					body.ExceptionHandlers.Add (eh);
				}
			}

			if ((flags & (byte) MethodDataSection.MoreSects) != 0)
				ReadSection (body, br);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:40,代码来源:CodeReader.cs


示例11: CreateCoroutine

        // FIXME: Clean up.. factor out functionality into smaller, better pieces? Remove some generated nops?
        protected virtual void CreateCoroutine()
        {
            // create coroutine method
            coroutine = new MethodDefinition ("Resume", Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.Public |
                                                  Mono.Cecil.MethodAttributes.Virtual, module.TypeSystem.Void);

            var il = coroutine.Body.GetILProcessor ();

            // process the method we want to transform and...
            //  1) Replace all Ldarg, Starg opcodes with Ldfld, Stfld (argsFields)
            //  2) Replace all Ldloc, Stloc opcodes with Ldfld, Stfld (localsFields)
            //  3) Before Ret, add Future<T>.Value = ...; or Future.Status = FutureStatus.Fulfilled;
            //  4) Replace calls to Future.Wait or Thread.Yield with continuation
            //  5) Remove calls to Future<T>.op_Implicit preceeding Ret
            Visit (method);

            // remap the jumps- pass 1 (required because exception handling extracts some of these)
            MapAllInstructions (method.Body);

            // the whole body of the method must be an exception handler
            var exceptionType = module.Import (getException.ReturnType);
            var exception = new VariableDefinition (exceptionType);
            coroutine.Body.Variables.Add (exception);

            VariableDefinition skipFinallyBlocks = null;

            // add exception handlers
            int i = 0;
            var catchBlocks = new List<IList<Instruction>> ();
            var finallyBlocks = new List<IList<Instruction>> ();
            MethodDefinition finallyMethod = null;
            foreach (var eh in method.Body.ExceptionHandlers.OrderBy (e => e.TryStart.Offset).OrderBy (e => e.TryEnd.Offset)) {

                // set the next ePC to this handler block
                // we can get away with just setting an exception block selector (epc)
                //  at the beginning of the block because jumps into the middle of a try block are not allowed
                //  (see ECMA-335 12.4.2.8.2.7)
                InsertBefore (eh.TryStart, new Instruction [] {
                    il.Create (OpCodes.Ldarg_0),
                    il.Create (OpCodes.Ldarg_0),
                    il.Create (OpCodes.Ldfld, epcFld),
                    il.Create (OpCodes.Ldc_I8, 1L << i),
                    il.Create (OpCodes.Or),
                    il.Create (OpCodes.Stfld, epcFld)
                });

                // clear the bit for this handler at end of try block
                // This awkward bit of code below is necessary because one handler's end can be another's start
                var clearEpc = new List<Instruction> () {
                    il.Create (OpCodes.Ldarg_0),
                    il.Create (OpCodes.Ldarg_0),
                    il.Create (OpCodes.Ldfld, epcFld),
                    il.Create (OpCodes.Ldc_I8, ~(1L << i)),
                    il.Create (OpCodes.And),
                    il.Create (OpCodes.Stfld, epcFld)
                };

                if (eh.HandlerType == ExceptionHandlerType.Finally) {
                    finallyMethod = new MethodDefinition ("$finally" + i, Mono.Cecil.MethodAttributes.Private, module.TypeSystem.Void);
                    coroutineType.Methods.Add (finallyMethod);
                    clearEpc.Add (il.Create (OpCodes.Ldarg_0));
                    clearEpc.Add (il.Create (OpCodes.Call, finallyMethod));
                }
                InstructionMap.Insert (InstructionMap.IndexOfKey (eh.HandlerEnd), clearEpc [0], clearEpc);

                // have to fixup leaves from catch blocks to unset our epcs for handlers that are all in the same spot
                var lastHandler = method.Body.ExceptionHandlers.OrderBy (h => h.HandlerStart.Offset).LastOrDefault ((l, c) => l.HandlerEnd == c.HandlerStart, eh);
                var subsequent = lastHandler.HandlerEnd;//InstructionMap [lastHandler.HandlerEnd].FirstOrDefault ();
                //if (subsequent != null)
                MapInstructions (subsequent, clearEpc [0]);

                // extract the handler block
                var handlerBody = ExtractInstructionRange (eh.HandlerStart, clearEpc [0]);
                var block = new List<Instruction> ();

                //fixup common issue
                // FIXME: this solution is a kludge
                if (handlerBody [0].OpCode == OpCodes.Stfld) {
                    handlerBody.Insert (0, il.Create (OpCodes.Stloc, exception));
                    handlerBody.Insert (1, il.Create (OpCodes.Ldarg_0));
                    handlerBody.Insert (2, il.Create (OpCodes.Ldloc, exception));
                    if (eh.CatchType.FullName != "System.Exception")
                        handlerBody.Insert (3, il.Create (OpCodes.Isinst, eh.CatchType));
                }

                var skip = il.Create (OpCodes.Nop);

                // check if our epc bit is set
                block.Add (il.Create (OpCodes.Ldarg_0));
                block.Add (il.Create (OpCodes.Ldfld, epcFld));
                block.Add (il.Create (OpCodes.Ldc_I8, 1L << i));
                block.Add (il.Create (OpCodes.And));
                block.Add (il.Create (OpCodes.Brfalse, skip));

                // clear epc bits as we go
                block.Add (il.Create (OpCodes.Ldarg_0));
                block.Add (il.Create (OpCodes.Ldarg_0));
                block.Add (il.Create (OpCodes.Ldfld, epcFld));
                block.Add (il.Create (OpCodes.Ldc_I8, ~(1L << i)));
//.........这里部分代码省略.........
开发者ID:chkn,项目名称:cirrus,代码行数:101,代码来源:AsyncMethodTransform.cs


示例12: WriteExceptionHandlerSpecific

		void WriteExceptionHandlerSpecific (ExceptionHandler handler)
		{
			switch (handler.HandlerType) {
			case ExceptionHandlerType.Catch:
				WriteMetadataToken (metadata.LookupToken (handler.CatchType));
				break;
			case ExceptionHandlerType.Filter:
				WriteInt32 (handler.FilterStart.Offset);
				break;
			default:
				WriteInt32 (0);
				break;
			}
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:14,代码来源:CodeWriter.cs


示例13: CreateExceptionHandler

		protected ExceptionHandler CreateExceptionHandler()
		{
			try
			{
				var eh = new ExceptionHandler((ExceptionHandlerType) Types.SelectedItem);
				if (eh.HandlerType == ExceptionHandlerType.Filter)
					eh.FilterStart = FilterStart.SelectedOperand;

				eh.TryStart = TryStart.SelectedOperand;
				eh.TryEnd = TryEnd.SelectedOperand;
				eh.HandlerStart = HandlerStart.SelectedOperand;
				eh.HandlerEnd = HandlerEnd.SelectedOperand;

				if (CatchType.SelectedOperand != null)
					eh.CatchType = MethodDefinition.DeclaringType.Module.Import(CatchType.SelectedOperand);

				return eh;
			}
			catch (Exception)
			{
				MessageBox.Show(@"Reflexil is unable to create this exception handler");
				return null;
			}
		}
开发者ID:KitoHo,项目名称:Reflexil,代码行数:24,代码来源:ExceptionHandlerForm.cs


示例14: addExceptionHandler

 void addExceptionHandler(ExceptionHandler handler)
 {
     if (handler == null)
         return;
     pushMember(handler.CatchType);
 }
开发者ID:ldh0227,项目名称:de4dot,代码行数:6,代码来源:MemberRefFinder.cs


示例15: ReadExceptionHandlers

        // inline ?
        void ReadExceptionHandlers(int count, Func<int> read_entry, Func<int> read_length)
        {
            for (int i = 0; i < count; i++) {
                var handler = new ExceptionHandler (
                    (ExceptionHandlerType) (read_entry () & 0x7));

                handler.TryStart = GetInstruction (read_entry ());
                handler.TryEnd = GetInstruction (GetInstructionOffset (handler.TryStart) + read_length ());

                handler.HandlerStart = GetInstruction (read_entry ());
                handler.HandlerEnd = GetInstruction (GetInstructionOffset (handler.HandlerStart) + read_length ());

                ReadExceptionHandlerSpecific (handler);

                if (handler.TryStart != null && handler.HandlerStart != null)
                    this.body.ExceptionHandlers.Add (handler);
            }
        }
开发者ID:bladecoding,项目名称:cecil,代码行数:19,代码来源:CodeReader.cs


示例16: ReadExceptionHandlerSpecific

 void ReadExceptionHandlerSpecific(ExceptionHandler handler)
 {
     switch (handler.HandlerType) {
     case ExceptionHandlerType.Catch:
         handler.CatchType = reader.LookupToken (ReadToken ()) as TypeReference;
         break;
     case ExceptionHandlerType.Filter:
         handler.FilterStart = GetInstruction (ReadInt32 ());
         break;
     default:
         Advance (4);
         break;
     }
 }
开发者ID:bladecoding,项目名称:cecil,代码行数:14,代码来源:CodeReader.cs


示例17: Copy

        private ExceptionHandler Copy(DeepCopier copier, ExceptionHandler def)
        {
            var ret= new ExceptionHandler(def.HandlerType);
            if(def.CatchType != null)
                ret.CatchType = CopyReference(copier,def.CatchType);

            copier.Log("< ExceptionHandler ");
            copier.CopyAll(def,ret,ret,"CatchType");

            return ret;
        }
开发者ID:tritao,项目名称:flood,代码行数:11,代码来源:TypeWeaver.cs


示例18: ShowDialog

		public virtual DialogResult ShowDialog(MethodDefinition mdef, ExceptionHandler selected)
		{
			MethodDefinition = mdef;
			SelectedExceptionHandler = selected;
			return ShowDialog();
		}
开发者ID:KitoHo,项目名称:Reflexil,代码行数:6,代码来源:ExceptionHandlerForm.cs


示例19: Inject


//.........这里部分代码省略.........
                ILProcessor psr = bdy.GetILProcessor();

                foreach (VariableDefinition var in old.Variables)
                    bdy.Variables.Add(new VariableDefinition(var.Name, ImportType(var.VariableType, mod, ret, null)));

                foreach (Instruction inst in old.Instructions)
                {
                    switch (inst.OpCode.OperandType)
                    {
                        case OperandType.InlineArg:
                        case OperandType.ShortInlineArg:
                            if (inst.Operand == old.ThisParameter)
                                psr.Emit(inst.OpCode, bdy.ThisParameter);
                            else
                            {
                                int param = mtd.Parameters.IndexOf(inst.Operand as ParameterDefinition);
                                psr.Emit(inst.OpCode, ret.Parameters[param]);
                            }
                            break;
                        case OperandType.InlineVar:
                        case OperandType.ShortInlineVar:
                            int var = old.Variables.IndexOf(inst.Operand as VariableDefinition);
                            psr.Emit(inst.OpCode, bdy.Variables[var]);
                            break;
                        case OperandType.InlineField:
                            psr.Emit(inst.OpCode, ImportField(inst.Operand as FieldReference, mod, null));
                            break;
                        case OperandType.InlineMethod:
                            if (inst.Operand == mtd)
                                psr.Emit(inst.OpCode, ret);
                            else
                                psr.Emit(inst.OpCode, ImportMethod(inst.Operand as MethodReference, mod, ret, null));
                            break;
                        case OperandType.InlineType:
                            psr.Emit(inst.OpCode, ImportType(inst.Operand as TypeReference, mod, ret, null));
                            break;
                        case OperandType.InlineTok:
                            if (inst.Operand is TypeReference)
                                psr.Emit(inst.OpCode, ImportType(inst.Operand as TypeReference, mod, ret, null));
                            else if (inst.Operand is FieldReference)
                                psr.Emit(inst.OpCode, ImportField(inst.Operand as FieldReference, mod, null));
                            else if (inst.Operand is MethodReference)
                                psr.Emit(inst.OpCode, ImportMethod(inst.Operand as MethodReference, mod, ret, null));
                            break;
                        default:
                            psr.Append(inst.Clone());
                            break;
                    }
                }

                for (int i = 0; i < bdy.Instructions.Count; i++)
                {
                    Instruction inst = bdy.Instructions[i];
                    Instruction o = old.Instructions[i];

                    if (inst.OpCode.OperandType == OperandType.InlineSwitch)
                    {
                        Instruction[] olds = (Instruction[])o.Operand;
                        Instruction[] news = new Instruction[olds.Length];

                        for (int ii = 0; ii < news.Length; ii++)
                            news[ii] = bdy.Instructions[old.Instructions.IndexOf(olds[ii])];

                        inst.Operand = news;
                    }
                    else if (inst.OpCode.OperandType == OperandType.ShortInlineBrTarget || inst.OpCode.OperandType == OperandType.InlineBrTarget)
                        inst.Operand = bdy.Instructions[old.Instructions.IndexOf(inst.Operand as Instruction)];
                }

                foreach (ExceptionHandler eh in old.ExceptionHandlers)
                {
                    ExceptionHandler neh = new ExceptionHandler(eh.HandlerType);
                    if (old.Instructions.IndexOf(eh.TryStart) != -1)
                        neh.TryStart = bdy.Instructions[old.Instructions.IndexOf(eh.TryStart)];
                    if (old.Instructions.IndexOf(eh.TryEnd) != -1)
                        neh.TryEnd = bdy.Instructions[old.Instructions.IndexOf(eh.TryEnd)];
                    if (old.Instructions.IndexOf(eh.HandlerStart) != -1)
                        neh.HandlerStart = bdy.Instructions[old.Instructions.IndexOf(eh.HandlerStart)];
                    if (old.Instructions.IndexOf(eh.HandlerEnd) != -1)
                        neh.HandlerEnd = bdy.Instructions[old.Instructions.IndexOf(eh.HandlerEnd)];

                    switch (eh.HandlerType)
                    {
                        case ExceptionHandlerType.Catch:
                            neh.CatchType = ImportType(eh.CatchType, mod, ret, null);
                            break;
                        case ExceptionHandlerType.Filter:
                            neh.FilterStart = bdy.Instructions[old.Instructions.IndexOf(eh.FilterStart)];
                            //neh.FilterEnd = bdy.Instructions[old.Instructions.IndexOf(eh.FilterEnd)];
                            break;
                    }

                    bdy.ExceptionHandlers.Add(neh);
                }

                ret.Body = bdy;
            }

            return ret;
        }
开发者ID:n017,项目名称:Confuser,代码行数:101,代码来源:CecilHelper.cs


示例20: Clone

		internal static MethodBody Clone (MethodBody body, MethodDefinition parent, ImportContext context)
		{
			MethodBody nb = new MethodBody (parent);
			nb.MaxStack = body.MaxStack;
			nb.InitLocals = body.InitLocals;
			nb.CodeSize = body.CodeSize;

			foreach (VariableDefinition var in body.Variables)
				nb.Variables.Add (new VariableDefinition (
					context.Import (var.VariableType)));

			foreach (Instruction instr in body.Instructions) {
				Instruction ni = new Instruction (instr.OpCode);

				switch (instr.OpCode.OperandType) {
				case OperandType.InlineParam :
				case OperandType.ShortInlineParam :
					int param = body.Method.Parameters.IndexOf ((ParameterDefinition) instr.Operand);
					ni.Operand = parent.Parameters [param];
					break;
				case OperandType.InlineVar :
				case OperandType.ShortInlineVar :
					int var = body.Variables.IndexOf ((VariableDefinition) instr.Operand);
					ni.Operand = nb.Variables [var];
					break;
				case OperandType.InlineField :
					ni.Operand = context.Import ((FieldReference) instr.Operand);
					break;
				case OperandType.InlineMethod :
					ni.Operand = context.Import ((MethodReference) instr.Operand);
					break;
				case OperandType.InlineType :
					ni.Operand = context.Import ((TypeReference) instr.Operand);
					break;
				case OperandType.InlineTok :
					if (instr.Operand is TypeReference)
						ni.Operand = context.Import ((TypeReference) instr.Operand);
					else if (instr.Operand is FieldReference)
						ni.Operand = context.Import ((FieldReference) instr.Operand);
					else if (instr.Operand is MethodReference)
						ni.Operand = context.Import ((MethodReference) instr.Operand);
					break;
				case OperandType.ShortInlineBrTarget :
				case OperandType.InlineBrTarget :
					break;
				default :
					ni.Operand = instr.Operand;
					break;
				}

				nb.Instructions.Add (ni);
			}

			for (int i = 0; i < body.Instructions.Count; i++) {
				Instruction instr = nb.Instructions [i];
				if (instr.OpCode.OperandType != OperandType.ShortInlineBrTarget &&
					instr.OpCode.OperandType != OperandType.InlineBrTarget)
					continue;

				instr.Operand = GetInstruction (body, nb, (Instruction) body.Instructions [i].Operand);
			}

			foreach (ExceptionHandler eh in body.ExceptionHandlers) {
				ExceptionHandler neh = new ExceptionHandler (eh.Type);
				neh.TryStart = GetInstruction (body, nb, eh.TryStart);
				neh.TryEnd = GetInstruction (body, nb, eh.TryEnd);
				neh.HandlerStart = GetInstruction (body, nb, eh.HandlerStart);
				neh.HandlerEnd = GetInstruction (body, nb, eh.HandlerEnd);

				switch (eh.Type) {
				case ExceptionHandlerType.Catch :
					neh.CatchType = context.Import (eh.CatchType);
					break;
				case ExceptionHandlerType.Filter :
					neh.FilterStart = GetInstruction (body, nb, eh.FilterStart);
					neh.FilterEnd = GetInstruction (body, nb, eh.FilterEnd);
					break;
				}

				nb.ExceptionHandlers.Add (neh);
			}

			return nb;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:84,代码来源:MethodBody.cs



注:本文中的Mono.Cecil.Cil.ExceptionHandler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cil.ILProcessor类代码示例发布时间:2022-05-26
下一篇:
C# Cil.CilWorker类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap