GP-4297 Fixed screen reader decompiler api to prevent duplicate reading of the line when cursoring up or down a line

This commit is contained in:
ghidragon 2024-02-06 17:09:31 -05:00
parent dffb5fd859
commit 97fdfddecf
3 changed files with 19 additions and 11 deletions

View file

@ -18,6 +18,7 @@ package ghidra.app.util.viewer.field;
import docking.widgets.fieldpanel.FieldDescriptionProvider; import docking.widgets.fieldpanel.FieldDescriptionProvider;
import docking.widgets.fieldpanel.field.Field; import docking.widgets.fieldpanel.field.Field;
import docking.widgets.fieldpanel.support.FieldLocation; import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.program.model.address.Address;
import ghidra.program.util.ProgramLocation; import ghidra.program.util.ProgramLocation;
public class ListingFieldDescriptionProvider implements FieldDescriptionProvider { public class ListingFieldDescriptionProvider implements FieldDescriptionProvider {
@ -27,8 +28,9 @@ public class ListingFieldDescriptionProvider implements FieldDescriptionProvider
if (field instanceof ListingField listingField) { if (field instanceof ListingField listingField) {
FieldFactory fieldFactory = listingField.getFieldFactory(); FieldFactory fieldFactory = listingField.getFieldFactory();
ProgramLocation location = fieldFactory.getProgramLocation(0, 0, listingField); ProgramLocation location = fieldFactory.getProgramLocation(0, 0, listingField);
return fieldFactory.getFieldName() + " Field at Address " + location.getAddress() + Address address = location.getAddress();
" text = " + field.getText(); String addressString = address.toString(address.getAddressSpace().showSpaceName(), 1);
return fieldFactory.getFieldName() + " Field at Address " + addressString;
} }
return "Unknown Field"; return "Unknown Field";
} }

View file

@ -102,13 +102,22 @@ public class ByteViewerComponent extends FieldPanel implements FieldMouseListene
ByteBlockInfo info = indexMap.getBlockInfo(fieldLoc.getIndex(), fieldLoc.getFieldNum()); ByteBlockInfo info = indexMap.getBlockInfo(fieldLoc.getIndex(), fieldLoc.getFieldNum());
if (info != null) { if (info != null) {
String modelName = model.getName(); String modelName = model.getName();
return modelName + " format at " + String location = getAccessibleLocationInfo(info.getBlock(), info.getOffset());
info.getBlock().getLocationRepresentation(info.getOffset()) + ", value = " + return modelName + " format at " + location;
field.getText();
} }
return null; return null;
} }
private String getAccessibleLocationInfo(ByteBlock block, BigInteger offset) {
if (block instanceof MemoryByteBlock memBlock) {
// location represents an address, remove leading zeros to make screen reading concise
Address address = memBlock.getAddress(offset);
return address.toString(address.getAddressSpace().showSpaceName(), 1);
}
// otherwise use generic location representation
return block.getLocationRepresentation(offset);
}
@Override @Override
public void buttonPressed(FieldLocation fieldLocation, Field field, MouseEvent mouseEvent) { public void buttonPressed(FieldLocation fieldLocation, Field field, MouseEvent mouseEvent) {
if (fieldLocation == null || field == null) { if (fieldLocation == null || field == null) {

View file

@ -16,9 +16,7 @@
package ghidra.app.decompiler.component; package ghidra.app.decompiler.component;
import java.awt.*; import java.awt.*;
import java.awt.event.ComponentAdapter; import java.awt.event.*;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
@ -45,7 +43,6 @@ import ghidra.app.decompiler.component.hover.DecompilerHoverService;
import ghidra.app.decompiler.component.margin.*; import ghidra.app.decompiler.component.margin.*;
import ghidra.app.plugin.core.decompile.DecompilerClipboardProvider; import ghidra.app.plugin.core.decompile.DecompilerClipboardProvider;
import ghidra.app.plugin.core.decompile.actions.FieldBasedSearchLocation; import ghidra.app.plugin.core.decompile.actions.FieldBasedSearchLocation;
import ghidra.app.util.viewer.listingpanel.MarginProvider;
import ghidra.app.util.viewer.util.ScrollpaneAlignedHorizontalLayout; import ghidra.app.util.viewer.util.ScrollpaneAlignedHorizontalLayout;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
@ -1317,7 +1314,7 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
if (f == null) { if (f == null) {
return null; return null;
} }
return "line " + (l.getIndex().intValue() + 1) + ", " + f.getText(); return "line " + (l.getIndex().intValue() + 1);
}); });
} }