mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-3405: Emit events and sync for dynamic loc/sel/hl.
This commit is contained in:
parent
b5e404f499
commit
da89fe5fe9
19 changed files with 549 additions and 322 deletions
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -19,8 +19,8 @@ import java.util.*;
|
|||
|
||||
import org.jdom.Element;
|
||||
|
||||
import ghidra.app.events.ProgramLocationPluginEvent;
|
||||
import ghidra.app.events.ProgramSelectionPluginEvent;
|
||||
import ghidra.app.events.AbstractLocationPluginEvent;
|
||||
import ghidra.app.events.AbstractSelectionPluginEvent;
|
||||
import ghidra.app.services.*;
|
||||
import ghidra.framework.model.DomainFile;
|
||||
import ghidra.framework.model.DomainObject;
|
||||
|
@ -30,6 +30,7 @@ import ghidra.framework.plugintool.PluginTool;
|
|||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.util.ProgramLocation;
|
||||
import ghidra.program.util.ProgramSelection;
|
||||
import ghidra.util.SystemUtilities;
|
||||
import utility.function.Callback;
|
||||
|
||||
public abstract class AbstractByteViewerPlugin<P extends ProgramByteViewerComponentProvider>
|
||||
|
@ -270,8 +271,12 @@ public abstract class AbstractByteViewerPlugin<P extends ProgramByteViewerCompon
|
|||
return connectedProvider;
|
||||
}
|
||||
|
||||
public abstract void updateSelection(ByteViewerComponentProvider provider,
|
||||
ProgramSelectionPluginEvent event, Program program);
|
||||
public void updateSelection(ByteViewerComponentProvider provider,
|
||||
AbstractSelectionPluginEvent event, Program program) {
|
||||
if (provider == connectedProvider) {
|
||||
firePluginEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void highlightChanged(ByteViewerComponentProvider provider,
|
||||
ProgramSelection highlight);
|
||||
|
@ -298,11 +303,31 @@ public abstract class AbstractByteViewerPlugin<P extends ProgramByteViewerCompon
|
|||
provider.dispose();
|
||||
}
|
||||
|
||||
protected abstract void updateLocation(
|
||||
ProgramByteViewerComponentProvider programByteViewerComponentProvider,
|
||||
ProgramLocationPluginEvent event, boolean export);
|
||||
public void updateLocation(ProgramByteViewerComponentProvider provider,
|
||||
AbstractLocationPluginEvent event, boolean export) {
|
||||
|
||||
protected abstract void fireProgramLocationPluginEvent(
|
||||
ProgramByteViewerComponentProvider programByteViewerComponentProvider,
|
||||
ProgramLocationPluginEvent pluginEvent);
|
||||
if (eventsDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (provider == connectedProvider) {
|
||||
fireProgramLocationPluginEvent(provider, event);
|
||||
}
|
||||
else if (export) {
|
||||
exportLocation(provider.getProgram(), event.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
public void fireProgramLocationPluginEvent(ProgramByteViewerComponentProvider provider,
|
||||
AbstractLocationPluginEvent event) {
|
||||
|
||||
if (SystemUtilities.isEqual(event.getLocation(), currentLocation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentLocation = event.getLocation();
|
||||
if (provider == connectedProvider) {
|
||||
firePluginEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -24,7 +24,6 @@ import ghidra.framework.plugintool.*;
|
|||
import ghidra.framework.plugintool.util.PluginStatus;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.util.ProgramSelection;
|
||||
import ghidra.util.SystemUtilities;
|
||||
|
||||
//@formatter:off
|
||||
@PluginInfo(
|
||||
|
@ -69,10 +68,8 @@ public class ByteViewerPlugin extends AbstractByteViewerPlugin<ProgramByteViewer
|
|||
if (event instanceof ProgramClosedPluginEvent) {
|
||||
Program program = ((ProgramClosedPluginEvent) event).getProgram();
|
||||
programClosed(program);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event instanceof ProgramActivatedPluginEvent) {
|
||||
else if (event instanceof ProgramActivatedPluginEvent) {
|
||||
currentProgram = ((ProgramActivatedPluginEvent) event).getActiveProgram();
|
||||
currentLocation = null;
|
||||
}
|
||||
|
@ -94,44 +91,6 @@ public class ByteViewerPlugin extends AbstractByteViewerPlugin<ProgramByteViewer
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(ProgramByteViewerComponentProvider provider,
|
||||
ProgramLocationPluginEvent event, boolean export) {
|
||||
|
||||
if (eventsDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (provider == connectedProvider) {
|
||||
fireProgramLocationPluginEvent(provider, event);
|
||||
}
|
||||
else if (export) {
|
||||
exportLocation(provider.getProgram(), event.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireProgramLocationPluginEvent(ProgramByteViewerComponentProvider provider,
|
||||
ProgramLocationPluginEvent event) {
|
||||
|
||||
if (SystemUtilities.isEqual(event.getLocation(), currentLocation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentLocation = event.getLocation();
|
||||
if (provider == connectedProvider) {
|
||||
firePluginEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSelection(ByteViewerComponentProvider provider,
|
||||
ProgramSelectionPluginEvent event, Program program) {
|
||||
if (provider == connectedProvider) {
|
||||
firePluginEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void highlightChanged(ByteViewerComponentProvider provider, ProgramSelection highlight) {
|
||||
if (provider == connectedProvider) {
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -19,8 +19,7 @@ import java.math.BigInteger;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ghidra.app.events.ProgramLocationPluginEvent;
|
||||
import ghidra.app.events.ProgramSelectionPluginEvent;
|
||||
import ghidra.app.events.*;
|
||||
import ghidra.app.plugin.core.format.*;
|
||||
import ghidra.framework.options.SaveState;
|
||||
import ghidra.program.model.address.*;
|
||||
|
@ -59,17 +58,8 @@ public class ProgramByteBlockSet implements ByteBlockSet {
|
|||
return blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the appropriate plugin event for the given block selection.
|
||||
*
|
||||
* @param source source to use in the event
|
||||
* @param selection selection to use to generate the event
|
||||
*/
|
||||
@Override
|
||||
public ProgramSelectionPluginEvent getPluginEvent(String source, ByteBlockSelection selection) {
|
||||
|
||||
protected ProgramSelection convertSelection(ByteBlockSelection selection) {
|
||||
AddressSet addrSet = new AddressSet();
|
||||
|
||||
for (int i = 0; i < selection.getNumberOfRanges(); i++) {
|
||||
ByteBlockRange br = selection.getRange(i);
|
||||
ByteBlock block = br.getByteBlock();
|
||||
|
@ -77,7 +67,20 @@ public class ProgramByteBlockSet implements ByteBlockSet {
|
|||
Address end = getAddress(block, br.getEndIndex());
|
||||
addrSet.add(new AddressRangeImpl(start, end));
|
||||
}
|
||||
return new ProgramSelectionPluginEvent(source, new ProgramSelection(addrSet), program);
|
||||
return new ProgramSelection(addrSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the appropriate plugin event for the given block selection.
|
||||
*
|
||||
* @param source source to use in the event
|
||||
* @param selection selection to use to generate the event
|
||||
*/
|
||||
@Override
|
||||
public AbstractSelectionPluginEvent getPluginEvent(String source,
|
||||
ByteBlockSelection selection) {
|
||||
ProgramSelection pSel = convertSelection(selection);
|
||||
return new ProgramSelectionPluginEvent(source, pSel, program);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +92,7 @@ public class ProgramByteBlockSet implements ByteBlockSet {
|
|||
* @param column the column within the UI byte field
|
||||
*/
|
||||
@Override
|
||||
public ProgramLocationPluginEvent getPluginEvent(String source, ByteBlock block,
|
||||
public AbstractLocationPluginEvent getPluginEvent(String source, ByteBlock block,
|
||||
BigInteger offset, int column) {
|
||||
|
||||
ProgramLocation loc = provider.getLocation(block, offset, column);
|
||||
|
|
|
@ -197,7 +197,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
|
|||
panel.setViewerSelection(blockSelection);
|
||||
|
||||
if (notify) {
|
||||
ProgramSelectionPluginEvent selectionEvent =
|
||||
AbstractSelectionPluginEvent selectionEvent =
|
||||
blockSet.getPluginEvent(getName(), blockSelection);
|
||||
plugin.updateSelection(this, selectionEvent, program);
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
|
|||
}
|
||||
}
|
||||
|
||||
ProgramLocation getLocation(ByteBlock block, BigInteger offset, int column) {
|
||||
protected ProgramLocation getLocation(ByteBlock block, BigInteger offset, int column) {
|
||||
Address address = blockSet.getAddress(block, offset);
|
||||
int characterOffset = column;
|
||||
ProgramLocation loc = new ByteViewerProgramLocation(program, address, characterOffset);
|
||||
|
@ -515,17 +515,17 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
|
|||
}
|
||||
}
|
||||
|
||||
private void processHighlightEvent(ProgramHighlightPluginEvent event) {
|
||||
protected void processHighlightEvent(AbstractHighlightPluginEvent event) {
|
||||
ProgramSelection programSelection = event.getHighlight();
|
||||
setHighlight(programSelection);
|
||||
}
|
||||
|
||||
private void processSelectionEvent(ProgramSelectionPluginEvent event) {
|
||||
protected void processSelectionEvent(AbstractSelectionPluginEvent event) {
|
||||
ProgramSelection programSelection = event.getSelection();
|
||||
setSelection(programSelection);
|
||||
}
|
||||
|
||||
private void processLocationEvent(ProgramLocationPluginEvent event) {
|
||||
protected void processLocationEvent(AbstractLocationPluginEvent event) {
|
||||
ProgramLocation loc = event.getLocation();
|
||||
setLocation(loc);
|
||||
}
|
||||
|
@ -603,7 +603,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
|
|||
|
||||
@Override
|
||||
protected void updateSelection(ByteBlockSelection selection) {
|
||||
ProgramSelectionPluginEvent event = blockSet.getPluginEvent(plugin.getName(), selection);
|
||||
AbstractSelectionPluginEvent event = blockSet.getPluginEvent(plugin.getName(), selection);
|
||||
liveSelection = null;
|
||||
currentSelection = event.getSelection();
|
||||
plugin.updateSelection(this, event, program);
|
||||
|
@ -614,7 +614,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
|
|||
|
||||
@Override
|
||||
protected void updateLiveSelection(ByteBlockSelection selection) {
|
||||
ProgramSelectionPluginEvent event = blockSet.getPluginEvent(plugin.getName(), selection);
|
||||
AbstractSelectionPluginEvent event = blockSet.getPluginEvent(plugin.getName(), selection);
|
||||
liveSelection = event.getSelection();
|
||||
updateTitle();
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
|
|||
@Override
|
||||
protected void updateLocation(ByteBlock block, BigInteger blockOffset, int column,
|
||||
boolean export) {
|
||||
ProgramLocationPluginEvent event =
|
||||
AbstractLocationPluginEvent event =
|
||||
blockSet.getPluginEvent(plugin.getName(), block, blockOffset, column);
|
||||
currentLocation = event.getLocation();
|
||||
plugin.updateLocation(this, event, export);
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -17,8 +17,8 @@ package ghidra.app.plugin.core.format;
|
|||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import ghidra.app.events.ProgramLocationPluginEvent;
|
||||
import ghidra.app.events.ProgramSelectionPluginEvent;
|
||||
import ghidra.app.events.AbstractLocationPluginEvent;
|
||||
import ghidra.app.events.AbstractSelectionPluginEvent;
|
||||
import ghidra.program.model.address.AddressSet;
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ public interface ByteBlockSet {
|
|||
* @param column the column within the UI byte field
|
||||
* @return the event
|
||||
*/
|
||||
public ProgramLocationPluginEvent getPluginEvent(String source, ByteBlock block,
|
||||
public AbstractLocationPluginEvent getPluginEvent(String source, ByteBlock block,
|
||||
BigInteger offset, int column);
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public interface ByteBlockSet {
|
|||
* @param selection selection to use to generate the event
|
||||
* @return the event
|
||||
*/
|
||||
public ProgramSelectionPluginEvent getPluginEvent(String source, ByteBlockSelection selection);
|
||||
public AbstractSelectionPluginEvent getPluginEvent(String source, ByteBlockSelection selection);
|
||||
|
||||
/**
|
||||
* Return true if the block has been changed at the given index.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue