Beispiel #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));
        }
Beispiel #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);
 }
Beispiel #3
0
        static bool CanExecuteCommand()
        {
            var context = CreateContext();

            return(ShowAddressReferenceInHexEditorCommand.IsVisibleInternal(context) ||
                   ShowILRangeInHexEditorCommand.IsVisibleInternal(context) ||
                   ShowHexNodeInHexEditorCommand.IsVisibleInternal(context) ||
                   IsVisibleInternal(context));
        }
Beispiel #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);
        }
Beispiel #5
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);
            }
        }