Exemplo n.º 1
0
 private void InitializeExtraType(IOperandEditor editor, Type extratype)
 {
     if (extratype != null)
     {
         if (extratype.IsEnum)
         {
             ExtraType.Visible           = false;
             ExtraTypeList.Visible       = true;
             ExtraTypeList.DataSource    = Enum.GetValues(extratype);
             ExtraTypeList.SelectedIndex = 0;
         }
         else
         {
             ExtraType.Visible     = true;
             ExtraTypeList.Visible = false;
             if (editor is AssemblyDefinitionEditor)
             {
                 var aeditor = (editor as AssemblyDefinitionEditor);
                 if (aeditor.SelectedOperand != null)
                 {
                     ExtraType.SelectedOperand = aeditor.SelectedOperand.MainModule.Import(extratype);
                 }
             }
             else
             {
                 var teditor = (editor as TypeDefinitionEditor);
                 if (teditor.SelectedOperand != null)
                 {
                     ExtraType.SelectedOperand = teditor.SelectedOperand.Module.Import(extratype);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 private void InitializeExtraType(IOperandEditor editor, Type extratype)
 {
     if (extratype != null)
     {
         if (extratype.IsEnum)
         {
             ExtraType.Visible           = false;
             ExtraTypeList.Visible       = true;
             ExtraTypeList.DataSource    = Enum.GetValues(extratype);
             ExtraTypeList.SelectedIndex = 0;
         }
         else
         {
             ExtraType.Visible     = true;
             ExtraTypeList.Visible = false;
             var assemblyDefinitionEditor = editor as AssemblyDefinitionEditor;
             if (assemblyDefinitionEditor != null)
             {
                 if (assemblyDefinitionEditor.SelectedOperand != null)
                 {
                     ExtraType.SelectedOperand = LookupTypeReference(assemblyDefinitionEditor.SelectedOperand.MainModule, extratype);
                 }
             }
             else
             {
                 var teditor = editor as TypeDefinitionEditor;
                 if (teditor != null && teditor.SelectedOperand != null)
                 {
                     ExtraType.SelectedOperand = LookupTypeReference(teditor.SelectedOperand.Module, extratype);
                 }
             }
         }
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
 public void CopyStateTo(IConstantProvider item)
 {
     if (ConstantTypes.SelectedItem != null)
     {
         IOperandEditor editor = (IOperandEditor)ConstantTypes.SelectedItem;
         item.Constant    = editor.SelectedOperand;
         item.HasConstant = !(editor is NoneOperandEditor);
     }
     else
     {
         item.Constant    = null;
         item.HasConstant = false;
     }
 }
Exemplo n.º 5
0
        private void Ok_Click(object sender, EventArgs e)
        {
            IOperandEditor editor = (IOperandEditor)OwnerType.SelectedItem;

            if (editor != null)
            {
                object owner = editor.SelectedOperand;
                if (owner != null && ItemType.SelectedIndex >= 0)
                {
                    if (ExtraTypeList.Visible)
                    {
                        InjectHelper.Inject(owner, TargetType, ItemName.Text, ExtraTypeList.SelectedItem);
                    }
                    else
                    {
                        InjectHelper.Inject(owner, TargetType, ItemName.Text, ExtraType.SelectedOperand);
                    }
                }
            }
        }
 protected Instruction CreateInstruction()
 {
     try
     {
         if (OpCodes.SelectedItem != null)
         {
             IOperandEditor editor = (IOperandEditor)Operands.SelectedItem;
             Instruction    ins    = editor.CreateInstruction(MethodDefinition.Body.GetILProcessor(), ((OpCode)OpCodes.SelectedItem));
             return(ins);
         }
         else
         {
             MessageBox.Show("Unknown opcode");
             return(null);
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Reflexil is unable to create this instruction, check coherence between the opcode and the operand");
         return(null);
     }
 }
Exemplo n.º 7
0
		private void InitializeExtraType(IOperandEditor editor, Type extratype)
		{
			if (extratype != null)
			{
				if (extratype.IsEnum)
				{
					ExtraType.Visible = false;
					ExtraTypeList.Visible = true;
					ExtraTypeList.DataSource = Enum.GetValues(extratype);
					ExtraTypeList.SelectedIndex = 0;
				}
				else
				{
					ExtraType.Visible = true;
					ExtraTypeList.Visible = false;
					if (editor is AssemblyDefinitionEditor)
					{
						var aeditor = (editor as AssemblyDefinitionEditor);
						if (aeditor.SelectedOperand != null)
						{
							ExtraType.SelectedOperand = LookupTypeReference(aeditor.SelectedOperand.MainModule, extratype);
						}
					}
					else
					{
						var teditor = (editor as TypeDefinitionEditor);
						if (teditor != null && teditor.SelectedOperand != null)
						{
							ExtraType.SelectedOperand = LookupTypeReference(teditor.SelectedOperand.Module, extratype);
						}
					}
				}
			}
		}