Ejemplo n.º 1
0
        static AddressReference GetAddressReference(ContextMenuEntryContext context)
        {
            if (ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context))
            {
                return(null);
            }
            if (ShowILRangeInHexEditorCommand.IsVisibleInternal(context))
            {
                return(null);
            }

            if (context.SelectedTreeNodes == null || context.SelectedTreeNodes.Length != 1)
            {
                return(null);
            }
            var hexNode = context.SelectedTreeNodes[0] as HexTreeNode;

            if (hexNode == null)
            {
                return(null);
            }

            var name = ShowAddressReferenceInHexEditorCommand.GetFilename(hexNode);

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            return(new AddressReference(name, false, hexNode.StartOffset, hexNode.StartOffset == 0 && hexNode.EndOffset == ulong.MaxValue ? ulong.MaxValue : hexNode.EndOffset - hexNode.StartOffset + 1));
        }
Ejemplo n.º 2
0
 static AssemblyTreeNode GetAssemblyTreeNode(ContextMenuEntryContext context)
 {
     if (ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context))
     {
         return(null);
     }
     if (ShowILRangeInHexEditorCommand.IsVisibleInternal(context))
     {
         return(null);
     }
     if (ShowHexNodeInHexEditorCommand.IsVisibleInternal(context))
     {
         return(null);
     }
     if (context.Element is DecompilerTextView)
     {
         return(GetActiveAssemblyTreeNode());
     }
     if (context.Element == MainWindow.Instance.treeView)
     {
         return(context.SelectedTreeNodes != null &&
                context.SelectedTreeNodes.Length == 1 ?
                context.SelectedTreeNodes[0] as AssemblyTreeNode : null);
     }
     return(null);
 }
Ejemplo n.º 3
0
        static bool CanExecuteCommand()
        {
            var context = CreateContext();

            return(ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context) ||
                   ShowILRangeInHexEditorCommand.IsVisibleInternal(context) ||
                   ShowHexNodeInHexEditorCommand.IsVisibleInternal(context) ||
                   IsVisibleInternal(context));
        }
Ejemplo n.º 4
0
        static AddressReference GetAddressReference(ContextMenuEntryContext context)
        {
            if (ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context))
            {
                return(null);
            }
            if (ShowILRangeInHexEditorCommand.IsVisibleInternal(context))
            {
                return(null);
            }

            if (context.SelectedTreeNodes == null || context.SelectedTreeNodes.Length != 1)
            {
                return(null);
            }
            if (!(context.SelectedTreeNodes[0] is HexTreeNode))
            {
                return(null);
            }

            var mod = ILSpyTreeNode.GetModule(context.SelectedTreeNodes[0]) as ModuleDefMD;

            if (mod == null)
            {
                return(null);
            }
            var pe = mod.MetaData.PEImage;

            var sectNode = context.SelectedTreeNodes[0] as ImageSectionHeaderTreeNode;

            if (sectNode != null)
            {
                if (sectNode.SectionNumber >= pe.ImageSectionHeaders.Count)
                {
                    return(null);
                }
                var sect = pe.ImageSectionHeaders[sectNode.SectionNumber];
                return(new AddressReference(mod.Location, false, sect.PointerToRawData, sect.SizeOfRawData));
            }

            var stgNode = context.SelectedTreeNodes[0] as StorageStreamTreeNode;

            if (stgNode != null)
            {
                if (stgNode.StreamNumber >= mod.MetaData.MetaDataHeader.StreamHeaders.Count)
                {
                    return(null);
                }
                var sh = mod.MetaData.MetaDataHeader.StreamHeaders[stgNode.StreamNumber];

                return(new AddressReference(mod.Location, false, (ulong)mod.MetaData.MetaDataHeader.StartOffset + sh.Offset, sh.StreamSize));
            }

            return(null);
        }
Ejemplo n.º 5
0
        static AddressReference GetAddressReference(ContextMenuEntryContext context)
        {
            if (ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context))
            {
                return(null);
            }
            if (TVShowMethodInstructionsInHexEditorCommand.IsVisibleInternal(context))
            {
                return(null);
            }

            var mappings = GetMappings(context);

            if (mappings == null || mappings.Count == 0)
            {
                return(null);
            }

            var method = mappings[0].MemberMapping.MethodDef;
            var mod    = mappings[0].MemberMapping.MethodDef.Module as ModuleDefMD;

            if (mod == null || string.IsNullOrEmpty(mod.Location))
            {
                return(null);
            }

            ulong addr = (ulong)method.RVA;
            ulong len;

            if (MethodAnnotations.Instance.IsBodyModified(method))
            {
                len = 0;
            }
            else if (mappings.Count == 1)
            {
                addr += (ulong)method.Body.HeaderSize + mappings[0].ILInstructionOffset.From;
                len   = mappings[0].ILInstructionOffset.To - mappings[0].ILInstructionOffset.From;
            }
            else
            {
                addr += (ulong)method.Body.HeaderSize + mappings[0].ILInstructionOffset.From;
                len   = 0;
            }

            return(new AddressReference(mod.Location, true, addr, len));
        }
Ejemplo n.º 6
0
        static void ExecuteCommand()
        {
            var context = CreateContext();

            if (ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context))
            {
                ShowAddressReferenceInHexEditorCommand.ExecuteInternal(context);
            }
            else if (ShowILRangeInHexEditorCommand.IsVisibleInternal(context))
            {
                ShowILRangeInHexEditorCommand.ExecuteInternal(context);
            }
            else if (ShowHexNodeInHexEditorCommand.IsVisibleInternal(context))
            {
                ShowHexNodeInHexEditorCommand.ExecuteInternal(context);
            }
            else if (IsVisibleInternal(context))
            {
                ExecuteInternal(context);
            }
        }