Example #1
0
        protected CustomAttributeArgument FixCustomAttributeArgument(ModuleDefinition module, CustomAttributeArgument argument)
        {
            var value = argument.Value;

            if (value is TypeReference)
            {
                value = CecilImporter.Import(module, value as TypeReference);
            }

            if (value is CustomAttributeArgument[])
            {
                var arguments = value as CustomAttributeArgument[];
                for (var i = 0; i < arguments.Length; i++)
                {
                    arguments[i] = FixCustomAttributeArgument(module, arguments[i]);
                }
            }

            // Used for wrapped CustomAttributeArgument[]
            if (argument.Type.Module == null)
            {
                argument.Type = module.TypeSystem.LookupType(argument.Type.Namespace, argument.Type.Name);
            }

            return(new CustomAttributeArgument(CecilImporter.Import(module, argument.Type), value));
        }
        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 = CecilImporter.Import(MethodDefinition.DeclaringType.Module, CatchType.SelectedOperand, MethodDefinition);
                }

                return(eh);
            }
            catch (Exception)
            {
                MessageBox.Show(@"Reflexil is unable to create this exception handler");
                return(null);
            }
        }
Example #3
0
        protected VariableDefinition CreateVariable()
        {
            var result = new VariableDefinition(CecilImporter.Import(MethodDefinition.DeclaringType.Module,
                                                                     TypeSpecificationEditor.SelectedTypeReference, MethodDefinition));

            return(result);
        }
Example #4
0
        private void FieldType_Validating(object sender, CancelEventArgs e)
        {
            bool validated;
            var  typeSpecification = FieldType.SelectedTypeReference as Mono.Cecil.TypeSpecification;

            if (typeSpecification != null)
            {
                var tspec = typeSpecification;
                validated = tspec.ElementType != null;
            }
            else
            {
                validated = FieldType.SelectedTypeReference != null;
            }

            if (!validated)
            {
                ErrorProvider.SetError(FieldType, "Type is mandatory");
                e.Cancel = true;
            }
            else
            {
                ErrorProvider.SetError(FieldType, string.Empty);
                if (Item != null && Item.Module != null)
                {
                    Item.FieldType = CecilImporter.Import(Item.Module, FieldType.SelectedTypeReference, FieldType.Context);
                }
            }
        }
Example #5
0
        private void ButUpdate_Click(object sender, EventArgs e)
        {
            if (IsFormComplete)
            {
                SelectedParameter.Attributes = ParameterAttributes.None;

                var parameterDefinition = Attributes.Item as ParameterDefinition;
                if (parameterDefinition != null)
                {
                    SelectedParameter.Attributes = parameterDefinition.Attributes;
                }

                ConstantEditor.CopyStateTo(SelectedParameter);

                SelectedParameter.Name          = ItemName.Text;
                SelectedParameter.ParameterType = CecilImporter.Import(MethodDefinition.DeclaringType.Module, TypeSpecificationEditor.SelectedTypeReference,
                                                                       MethodDefinition);

                DialogResult = DialogResult.OK;
            }
            else
            {
                DialogResult = DialogResult.None;
            }
        }
Example #6
0
        protected void FixAndUpdateWorkingAttribute()
        {
            var module = CecilHelper.GetModuleFromCustomAttributeProvider(SelectedProvider);

            WorkingAttribute.Constructor = CecilImporter.Import(module, Constructor.SelectedOperand);

            FixCustomAttributeArguments(module, WorkingAttribute.ConstructorArguments);
            FixCustomAttributeNamedArguments(module, WorkingAttribute.Fields);
            FixCustomAttributeNamedArguments(module, WorkingAttribute.Properties);
        }
Example #7
0
        private void BaseType_Validated(object sender, System.EventArgs e)
        {
            if (Item == null)
            {
                return;
            }

            var tref = BaseType.SelectedOperand;

            Item.BaseType = tref != null && Item.Module != null?CecilImporter.Import(Item.Module, tref, Item) : null;
        }
 private void ButInsertAfter_Click(Object sender, EventArgs e)
 {
     if (IsFormComplete)
     {
         var interfaces = TypeDefinition.Interfaces;
         interfaces.Insert(interfaces.IndexOf(SelectedTypeReference) + 1, CecilImporter.Import(TypeDefinition.Module, TypeReferenceEditor.SelectedOperand));
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.None;
     }
 }
Example #9
0
		private void ButUpdate_Click(object sender, EventArgs e)
		{
			if (IsFormComplete)
			{
				SelectedVariable.VariableType = CecilImporter.Import(MethodDefinition.DeclaringType.Module, TypeSpecificationEditor.SelectedTypeReference, MethodDefinition);

				DialogResult = DialogResult.OK;
			}
			else
			{
				DialogResult = DialogResult.None;
			}
		}
Example #10
0
 private void ButAppend_Click(object sender, EventArgs e)
 {
     if (IsFormComplete)
     {
         var overrides = MethodDefinition.Overrides;
         overrides.Add(CecilImporter.Import(MethodDefinition.DeclaringType.Module, MethodReferenceEditor.SelectedOperand, MethodDefinition));
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.None;
     }
 }
 private void ButAppend_Click(object sender, EventArgs e)
 {
     if (IsFormComplete)
     {
         var newInterface = new InterfaceImplementation(CecilImporter.Import(TypeDefinition.Module, TypeReferenceEditor.SelectedOperand, TypeDefinition));
         TypeDefinition.Interfaces.Add(newInterface);
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.None;
     }
 }
Example #12
0
 private void ButInsertAfter_Click(Object sender, EventArgs e)
 {
     if (IsFormComplete)
     {
         var overrides = MethodDefinition.Overrides;
         overrides.Insert(overrides.IndexOf(SelectedMethodReference) + 1, CecilImporter.Import(MethodDefinition.DeclaringType.Module, MethodReferenceEditor.SelectedOperand));
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.None;
     }
 }
Example #13
0
 private void ButUpdate_Click(object sender, EventArgs e)
 {
     if (IsFormComplete)
     {
         var index = TypeDefinition.Interfaces.IndexOf(SelectedTypeReference);
         TypeDefinition.Interfaces.RemoveAt(index);
         TypeDefinition.Interfaces.Insert(index, CecilImporter.Import(TypeDefinition.Module, TypeReferenceEditor.SelectedOperand));
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.None;
     }
 }
Example #14
0
 private void ButUpdate_Click(object sender, EventArgs e)
 {
     if (IsFormComplete)
     {
         var index = MethodDefinition.Overrides.IndexOf(SelectedMethodReference);
         MethodDefinition.Overrides.RemoveAt(index);
         MethodDefinition.Overrides.Insert(index, CecilImporter.Import(MethodDefinition.DeclaringType.Module, MethodReferenceEditor.SelectedOperand, MethodDefinition));
         DialogResult = DialogResult.OK;
     }
     else
     {
         DialogResult = DialogResult.None;
     }
 }
Example #15
0
        private void ButUpdate_Click(object sender, EventArgs e)
        {
            if (IsFormComplete)
            {
                var index = TypeDefinition.LegacyInterfaces.IndexOf(SelectedTypeReference);
                var iface = TypeDefinition.Interfaces[index];

                iface.InterfaceType = CecilImporter.Import(TypeDefinition.Module, TypeReferenceEditor.SelectedOperand, TypeDefinition);
                DialogResult        = DialogResult.OK;
            }
            else
            {
                DialogResult = DialogResult.None;
            }
        }
        private void ButInsertAfter_Click(object sender, EventArgs e)
        {
            if (IsFormComplete)
            {
                var newInterface = new InterfaceImplementation(CecilImporter.Import(TypeDefinition.Module, TypeReferenceEditor.SelectedOperand, TypeDefinition));
                var index        = TypeDefinition.LegacyInterfaces.IndexOf(SelectedTypeReference) + 1;

                TypeDefinition.Interfaces.Insert(index, newInterface);

                DialogResult = DialogResult.OK;
            }
            else
            {
                DialogResult = DialogResult.None;
            }
        }
Example #17
0
        protected override GenericInstanceType CreateGenericInstance(IEnumerable <TypeReference> arguments)
        {
            var instance = new GenericInstanceType(Provider as TypeReference);

            foreach (var argument in arguments)
            {
                instance.GenericArguments.Add(argument);
            }

            // Now we need to import type given the current module AND the given generic context
            var handler = PluginFactory.GetInstance().Package.ActiveHandler;
            var module  = handler.TargetObjectModule;

            instance = (GenericInstanceType)CecilImporter.Import(module, instance, Context);

            return(instance);
        }
Example #18
0
        protected ParameterDefinition CreateParameter()
        {
            var prm =
                new ParameterDefinition(CecilImporter.Import(MethodDefinition.DeclaringType.Module, TypeSpecificationEditor.SelectedTypeReference, MethodDefinition))
            {
                Name = ItemName.Text,
            };

            var attributeProvider = Attributes.Item as ParameterDefinition;

            if (attributeProvider != null)
            {
                prm.Attributes = attributeProvider.Attributes;
            }

            ConstantEditor.CopyStateTo(prm);

            return(prm);
        }
        protected override GenericInstanceMethod CreateGenericInstance(IEnumerable <TypeReference> arguments)
        {
            var mref = (MethodReference)Provider;

            var reference = new MethodReference
            {
                Name              = mref.Name,
                DeclaringType     = HandleGenericType(mref.DeclaringType),
                HasThis           = mref.HasThis,
                ExplicitThis      = mref.ExplicitThis,
                ReturnType        = mref.ReturnType,
                CallingConvention = mref.CallingConvention,
            };

            foreach (var param in mref.Parameters)
            {
                reference.Parameters.Add(new ParameterDefinition(param.ParameterType));
            }

            foreach (var genParam in mref.GenericParameters)
            {
                reference.GenericParameters.Add(new GenericParameter(genParam.Name, reference));
            }

            var instance = new GenericInstanceMethod(reference);

            foreach (var argument in arguments)
            {
                instance.GenericArguments.Add(argument);
            }

            // Now we need to import method given the current module AND the given generic context
            var handler = PluginFactory.GetInstance().Package.ActiveHandler;
            var module  = handler.TargetObjectModule;

            instance = (GenericInstanceMethod)CecilImporter.Import(module, instance, Context);

            return(instance);
        }
Example #20
0
        public override Instruction CreateInstruction(ILProcessor worker, OpCode opcode)
        {
            var mdef = Context as MethodDefinition;

            return(mdef != null?worker.Create(opcode, CecilImporter.Import(mdef.DeclaringType.Module, SelectedOperand, mdef)) : null);
        }