Skip to content

Commit

Permalink
Fix missing "Show Data in Hex Editor" option for section headers in PEs
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Jun 15, 2024
1 parent 147c7d6 commit e30cc6e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Extensions/dnSpy.AsmEditor/Hex/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,22 +551,27 @@ internal static void ExecuteInternal(IDocumentTabService documentTabService, Laz

if (context.Nodes is null || context.Nodes.Length != 1)
return null;
if (!(context.Nodes[0] is HexNode))
if (!(context.Nodes[0] is HexNode hexNode))
return null;

var mod = context.Nodes[0].GetModule() as ModuleDefMD;
if (mod is null)
var name = ShowAddressReferenceInHexEditorCommand.GetFilename(hexNode);
if (string.IsNullOrEmpty(name))
return null;

var doc = hexNode.GetDocumentNode();
if (doc is null)
return null;
var pe = mod.Metadata.PEImage;

if (context.Nodes[0] is ImageSectionHeaderNode sectNode) {
var pe = doc.Document.PEImage;
if (pe is not null && hexNode is ImageSectionHeaderNode sectNode) {
if (sectNode.SectionNumber >= pe.ImageSectionHeaders.Count)
return null;
var sect = pe.ImageSectionHeaders[sectNode.SectionNumber];
return new AddressReference(mod.Location, false, sect.PointerToRawData, sect.SizeOfRawData);
return new AddressReference(name, false, sect.PointerToRawData, sect.SizeOfRawData);
}

if (context.Nodes[0] is StorageStreamNode stgNode) {
var mod = doc.Document.ModuleDef as ModuleDefMD;
if (mod is not null && hexNode is StorageStreamNode stgNode) {
if (stgNode.StreamNumber >= mod.Metadata.MetadataHeader.StreamHeaders.Count)
return null;
var sh = mod.Metadata.MetadataHeader.StreamHeaders[stgNode.StreamNumber];
Expand Down

0 comments on commit e30cc6e

Please sign in to comment.