当前位置: 首页>>代码示例>>C#>>正文


C# Cil.ExceptionHandler类代码示例

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


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


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