fix: Update XrefsEndpoints.java for Ghidra 11 API compatibility
- Fix reference handling using ReferenceIterator - Use proper Ghidra 11 services for current address retrieval - Implement location tracking via LocationService and SelectionService
This commit is contained in:
parent
5dc59ced59
commit
2b1fe6c4e1
@ -104,8 +104,9 @@ public class XrefsEndpoints extends AbstractEndpoint {
|
||||
|
||||
// Get references to this address
|
||||
if (toAddr != null) {
|
||||
Reference[] refsToArray = refManager.getReferencesTo(toAddr);
|
||||
for (Reference ref : refsToArray) {
|
||||
ReferenceIterator refsTo = refManager.getReferencesTo(toAddr);
|
||||
while (refsTo.hasNext()) {
|
||||
Reference ref = refsTo.next();
|
||||
if (refTypeStr != null && !ref.getReferenceType().getName().equalsIgnoreCase(refTypeStr)) {
|
||||
continue; // Skip if type filter doesn't match
|
||||
}
|
||||
@ -117,8 +118,9 @@ public class XrefsEndpoints extends AbstractEndpoint {
|
||||
|
||||
// Get references from this address
|
||||
if (fromAddr != null) {
|
||||
Reference[] refsFromArray = refManager.getReferencesFrom(fromAddr);
|
||||
for (Reference ref : refsFromArray) {
|
||||
ReferenceIterator refsFrom = refManager.getReferencesFrom(fromAddr);
|
||||
while (refsFrom.hasNext()) {
|
||||
Reference ref = refsFrom.next();
|
||||
if (refTypeStr != null && !ref.getReferenceType().getName().equalsIgnoreCase(refTypeStr)) {
|
||||
continue; // Skip if type filter doesn't match
|
||||
}
|
||||
@ -286,19 +288,28 @@ public class XrefsEndpoints extends AbstractEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
// Try to get the address from the current listing
|
||||
// Try to get the address from the current listing using LocationService
|
||||
ghidra.app.services.ProgramManager programManager =
|
||||
tool.getService(ghidra.app.services.ProgramManager.class);
|
||||
if (programManager != null && programManager.getCurrentProgram() == program) {
|
||||
ghidra.program.util.ProgramSelection selection = programManager.getCurrentSelection();
|
||||
if (selection != null && !selection.isEmpty()) {
|
||||
return selection.getMinAddress();
|
||||
// In Ghidra 11+, use the current cursor location
|
||||
ghidra.app.services.LocationService locationService =
|
||||
tool.getService(ghidra.app.services.LocationService.class);
|
||||
if (locationService != null) {
|
||||
ghidra.program.util.ProgramLocation location = locationService.getLocation();
|
||||
if (location != null && location.getProgram() == program) {
|
||||
return location.getAddress();
|
||||
}
|
||||
}
|
||||
|
||||
// Try the current highlight selection
|
||||
selection = programManager.getCurrentHighlight();
|
||||
if (selection != null && !selection.isEmpty()) {
|
||||
return selection.getMinAddress();
|
||||
// Try selection service as a last resort
|
||||
ghidra.app.services.SelectionService selectionService =
|
||||
tool.getService(ghidra.app.services.SelectionService.class);
|
||||
if (selectionService != null) {
|
||||
ghidra.program.util.ProgramSelection selection = selectionService.getCurrentSelection();
|
||||
if (selection != null && !selection.isEmpty()) {
|
||||
return selection.getMinAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user