Exemple #1
0
 public DialogResult ShowDialog(EInjectType type)
 {
     TargetType         = type;
     OwnerType.Enabled  = false;
     OwnerPanel.Enabled = false;
     ItemType.Enabled   = false;
     return(ShowDialog());
 }
Exemple #2
0
        /// <summary>
        /// Inject an item definition into an owner
        /// </summary>
        /// <param name="owner">Owner item</param>
        /// <param name="targettype">Target type definition</param>
        /// <param name="name">name for the newly created item</param>
        /// <param name="extratype">Extra type</param>
        /// <returns>Object definition</returns>
        public static object Inject(object owner, EInjectType targettype, string name, object extratype)
        {
            if (owner == null || name == null)
                throw new ArgumentException();

            if (owner is AssemblyDefinition)
            {
                var adef = owner as AssemblyDefinition;
                switch (targettype)
                {
                    case EInjectType.AssemblyReference:
                        return InjectAssemblyNameReference(adef, name);
                    case EInjectType.Type:
                        return InjectTypeDefinition(adef.MainModule, name, adef.MainModule.Import(extratype as TypeReference));
                    case EInjectType.Class:
                        return InjectClassDefinition(adef.MainModule, name, adef.MainModule.Import(extratype as TypeReference));
                    case EInjectType.Interface:
                        return InjectInterfaceDefinition(adef.MainModule, name);
                    case EInjectType.Struct:
                        return InjectStructDefinition(adef.MainModule, name);
                    case EInjectType.Enum:
                        return InjectEnumDefinition(adef.MainModule, name);
                    case EInjectType.Resource:
                        return InjectResource(adef.MainModule, name, (ResourceType) extratype);
                }
            }
            else if (owner is TypeDefinition)
            {
                var tdef = owner as TypeDefinition;

                switch (targettype)
                {
                    case EInjectType.Type:
                        return InjectInnerTypeDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference));
                    case EInjectType.Class:
                        return InjectInnerClassDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference));
                    case EInjectType.Interface:
                        return InjectInnerInterfaceDefinition(tdef, name);
                    case EInjectType.Struct:
                        return InjectInnerStructDefinition(tdef, name);
                    case EInjectType.Enum:
                        return InjectInnerEnumDefinition(tdef, name);
                    case EInjectType.Constructor:
                        return InjectConstructorDefinition(tdef);
                    case EInjectType.Method:
                        return InjectMethodDefinition(tdef, name);
                    case EInjectType.Property:
                        return InjectPropertyDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference));
                    case EInjectType.Field:
                        return InjectFieldDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference));
                    case EInjectType.Event:
                        return InjectEventDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference));
                }
            }

            throw new NotImplementedException();
        }
Exemple #3
0
        private void InjectContextChanged(object sender, EventArgs e)
        {
            IOperandEditor editor = (IOperandEditor)OwnerType.SelectedItem;

            if (ItemType.SelectedIndex >= 0)
            {
                EInjectType targettype = (EInjectType)ItemType.SelectedItem;

                ExtraTypePanel.Visible = extratypesupported.Contains(targettype);
                LabExtraType.Visible   = extratypesupported.Contains(targettype);
                LabExtraType.Text      = targettype.ToString().Replace("Interface", "Base").Replace("Class", "Base") + " type";
                ItemName.Enabled       = targettype != EInjectType.Constructor;

                object owner = editor.SelectedOperand;

                String nameprefix = (editor is AssemblyDefinitionEditor) ? "Namespace.Injected" : "InjectedInner";
                ItemName.Text = "Injected" + targettype.ToString();
                Type extratype = null;

                switch (targettype)
                {
                case EInjectType.Class:
                case EInjectType.Interface:
                    ItemName.Text = string.Concat(nameprefix, targettype.ToString());
                    extratype     = typeof(object);
                    break;

                case EInjectType.Enum:
                case EInjectType.Struct:
                    ItemName.Text = string.Concat(nameprefix, targettype.ToString());
                    break;

                case EInjectType.Property:
                case EInjectType.Field:
                    extratype = typeof(int);
                    break;

                case EInjectType.Event:
                    extratype = typeof(EventHandler);
                    break;

                case EInjectType.AssemblyReference:
                    ItemName.Text = "System.Windows.Forms";
                    break;

                case EInjectType.Constructor:
                    ItemName.Text = ".ctor";
                    break;

                case EInjectType.Resource:
                    extratype = typeof(ResourceType);
                    break;
                }

                InitializeExtraType(editor, extratype);
            }
        }
 /// <summary>
 /// Inject a specific item
 /// </summary>
 /// <param name="type">item type to inject</param>
 protected virtual void Inject(EInjectType type)
 {
     using (InjectForm frm = new InjectForm())
     {
         if (frm.ShowDialog(type) == DialogResult.OK)
         {
             OnItemInjected();
         }
     }
 }
Exemple #5
0
        public InjectForm()
        {
            InitializeComponent();
            mappings           = new Dictionary <object, EInjectType[]>();
            extratypesupported = new List <EInjectType>();
            extratypesupported.AddRange(new EInjectType[] { EInjectType.Class,
                                                            EInjectType.Property,
                                                            EInjectType.Field,
                                                            EInjectType.Event,
                                                            EInjectType.Resource });

            var ade      = new AssemblyDefinitionEditor();
            var adetypes = new EInjectType[] { EInjectType.Class,
                                               EInjectType.Interface,
                                               EInjectType.Struct,
                                               EInjectType.Enum,
                                               EInjectType.AssemblyReference,
                                               EInjectType.Resource };

            mappings.Add(ade, adetypes);
            OwnerType.Items.Add(ade);

            var tde      = new TypeDefinitionEditor();
            var tdetypes = new EInjectType[] { EInjectType.Class,
                                               EInjectType.Interface,
                                               EInjectType.Struct,
                                               EInjectType.Enum,
                                               EInjectType.Constructor,
                                               EInjectType.Method,
                                               EInjectType.Property,
                                               EInjectType.Field,
                                               EInjectType.Event };

            mappings.Add(tde, tdetypes);
            OwnerType.Items.Add(tde);

            InitializeOwnerType(ade, tde);
        }
        public InjectForm()
		{
			InitializeComponent();
            mappings = new Dictionary<object, EInjectType[]>();
            extratypesupported = new List<EInjectType>();
            extratypesupported.AddRange(new EInjectType[] { EInjectType.Class,
                                                            EInjectType.Property,
                                                            EInjectType.Field,
                                                            EInjectType.Event,
                                                            EInjectType.Resource});

            var ade = new AssemblyDefinitionEditor();
            var adetypes = new EInjectType[] {  EInjectType.Class,
                                                EInjectType.Interface,
                                                EInjectType.Struct, 
                                                EInjectType.Enum,
                                                EInjectType.AssemblyReference,
                                                EInjectType.Resource };
            mappings.Add(ade, adetypes);
            OwnerType.Items.Add(ade);

            var tde = new TypeDefinitionEditor();
            var tdetypes = new EInjectType[] {  EInjectType.Class,
                                                EInjectType.Interface,
                                                EInjectType.Struct,
                                                EInjectType.Enum,
                                                EInjectType.Constructor,
                                                EInjectType.Method,
                                                EInjectType.Property,
                                                EInjectType.Field,
                                                EInjectType.Event };
            mappings.Add(tde, tdetypes);
            OwnerType.Items.Add(tde);

            InitializeOwnerType(ade, tde);
		}
        internal void Inject(EInjectType injectType)
        {
            HandleItemRequest(this, EventArgs.Empty);

            base.Inject(injectType);
        }
 internal new void Inject(EInjectType injectType)
 {
     JustDecompileCecilStudioPackage.HandleItemRequest(this, EventArgs.Empty);
     base.Inject(injectType);
 }
        /// <summary>
        /// Inject an item definition into an owner
        /// </summary>
        /// <param name="owner">Owner item</param>
        /// <param name="targettype">Target type definition</param>
        /// <param name="name">name for the newly created item</param>
        /// <returns>Object definition</returns>
        public static object Inject(object owner, EInjectType targettype, string name, object extratype)
        {
            if (owner != null && name != null)
            {
                if (owner is AssemblyDefinition)
                {
                    AssemblyDefinition adef = owner as AssemblyDefinition;
                    switch (targettype)
                    {
                    case EInjectType.AssemblyReference:
                        return(InjectHelper.InjectAssemblyNameReference(adef, name));

                    case EInjectType.Type:
                        return(InjectHelper.InjectTypeDefinition(adef.MainModule, name, adef.MainModule.Import(extratype as TypeReference)));

                    case EInjectType.Class:
                        return(InjectHelper.InjectClassDefinition(adef.MainModule, name, adef.MainModule.Import(extratype as TypeReference)));

                    case EInjectType.Interface:
                        return(InjectHelper.InjectInterfaceDefinition(adef.MainModule, name));

                    case EInjectType.Struct:
                        return(InjectHelper.InjectStructDefinition(adef.MainModule, name));

                    case EInjectType.Enum:
                        return(InjectHelper.InjectEnumDefinition(adef.MainModule, name));

                    case EInjectType.Resource:
                        return(InjectHelper.InjectResource(adef.MainModule, name, (ResourceType)extratype));
                    }
                }
                else if (owner is TypeDefinition)
                {
                    TypeDefinition tdef = owner as TypeDefinition;

                    switch (targettype)
                    {
                    case EInjectType.Type:
                        return(InjectHelper.InjectInnerTypeDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference)));

                    case EInjectType.Class:
                        return(InjectHelper.InjectInnerClassDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference)));

                    case EInjectType.Interface:
                        return(InjectHelper.InjectInnerInterfaceDefinition(tdef, name));

                    case EInjectType.Struct:
                        return(InjectHelper.InjectInnerStructDefinition(tdef, name));

                    case EInjectType.Enum:
                        return(InjectHelper.InjectInnerEnumDefinition(tdef, name));

                    case EInjectType.Constructor:
                        return(InjectHelper.InjectConstructorDefinition(tdef));

                    case EInjectType.Method:
                        return(InjectHelper.InjectMethodDefinition(tdef, name));

                    case EInjectType.Property:
                        return(InjectHelper.InjectPropertyDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference)));

                    case EInjectType.Field:
                        return(InjectHelper.InjectFieldDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference)));

                    case EInjectType.Event:
                        return(InjectHelper.InjectEventDefinition(tdef, name, tdef.Module.Import(extratype as TypeReference)));
                    }
                }

                throw new NotImplementedException();
            }
            else
            {
                throw new ArgumentException();
            }
        }
 /// <summary>
 /// Inject a specific item
 /// </summary>
 /// <param name="type">item type to inject</param>
 protected virtual void Inject(EInjectType type)
 {
     using (InjectForm frm = new InjectForm())
     {
         if (frm.ShowDialog(type) == DialogResult.OK)
         {
             OnItemInjected();
         }
     }
 }
        internal void Inject(EInjectType injectType)
        {
            HandleItemRequest(this, EventArgs.Empty);

            base.Inject(injectType);
        }
 public DialogResult ShowDialog(EInjectType type)
 {
     TargetType = type;
     OwnerType.Enabled = false;
     OwnerPanel.Enabled = false;
     ItemType.Enabled = false;
     return ShowDialog();
 }