Skip to content

Commit

Permalink
Merge branch 'NationalSecurityAgency:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cooljeanius authored Sep 30, 2024
2 parents 85b8fbf + 59f7b60 commit d16fa12
Show file tree
Hide file tree
Showing 57 changed files with 1,577 additions and 761 deletions.

Large diffs are not rendered by default.

215 changes: 74 additions & 141 deletions Ghidra/Configurations/Public_Release/src/global/docs/WhatsNew.html

Large diffs are not rendered by default.

292 changes: 212 additions & 80 deletions Ghidra/Debug/Debugger/src/main/resources/defaultTools/Emulator.tool

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,32 @@ <H4>Steps:</H4>
in it.</LI>
</UL>
</BLOCKQUOTE>

<H3><A name="Load_Libraries"></A>Load Libraries</H3>

<BLOCKQUOTE>
<P>This action is used to load libraries into the project and link them to an existing
program. The program must be open in the tool to perform this action.</P>

<P><B>NOTE: </B>If you know at the time of import that you want to load/link libraries, it
is preferred to set the library loading options directly from the <A href="#Importer_Dialog">
Importer Dialog's</A> <A href="#Common_Options">Options...</A> button.

<H4>Steps:</H4>

<UL>
<LI>Invoke the action from the <B>File<IMG src="help/shared/arrow.gif" alt="">Load
Libraries...</B> menu item.</LI>

<LI>Use the options dialog that appears to control the library import settings.</LI>

<LI>Press OK on the dialog to initiate importing any discovered libraries.</LI>

<LI>When complete, the currently open program should have additional
<A href="help/topics/ReferencesPlugin/external_program_names.htm#ExternalNamesDialog">
External Programs</A> linked if matching libraries were found.</LI>
</UL>
</BLOCKQUOTE>
</BLOCKQUOTE>

<H2>Other Import Actions</H2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ public boolean canDemangle(Program program) {
return RustUtilities.isRustProgram(program);
}

@Override
@Deprecated(since = "11.3", forRemoval = true)
public DemangledObject demangle(String mangled, DemanglerOptions options) {
MangledContext mangledContext = createMangledContext(mangled, options, null, null);
return demangle(mangledContext);
}

@Override
public DemangledObject demangle(MangledContext context) {
DemanglerOptions options = context.getOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.*;

import javax.help.UnsupportedOperationException;

import docking.widgets.OptionDialog;
import docking.widgets.fieldpanel.support.*;
import ghidra.program.database.DatabaseObject;
Expand Down Expand Up @@ -586,7 +588,7 @@ public DataTypeComponent add(DataType dataType) throws UsrException {
@Override
public DataTypeComponent add(int rowIndex, DataType dt) throws UsrException {
String descr = rowIndex < getNumComponents() ? "Replace Component" : "Add Component";
return viewDTM.withTransaction(descr, () -> {
DataTypeComponent dtc = viewDTM.withTransaction(descr, () -> {
DataType resolvedDt = viewDTM.resolve(dt, DataTypeConflictHandler.DEFAULT_HANDLER);
try {
DataTypeInstance dti = getDropDataType(rowIndex, resolvedDt);
Expand All @@ -596,7 +598,11 @@ public DataTypeComponent add(int rowIndex, DataType dt) throws UsrException {
return null;
}
});


fixSelection();
componentEdited();
selectionChanged();
return dtc;
}

/**
Expand Down Expand Up @@ -628,6 +634,10 @@ public DataTypeComponent add(int rowIndex, DataType dt, int dtLength) throws Usr
else {
dtc = viewDTM.withTransaction("Add Component", () -> insert(rowIndex, dt, dtLength));
}

fixSelection();
componentEdited();
selectionChanged();
return dtc;
}

Expand Down Expand Up @@ -733,10 +743,8 @@ public DataTypeComponent replace(int rowIndex, DataType datatype, int length)
int sizeDiff = newCompSize - oldCompSize;

// New one is larger so check to make sure it will fit.
if (sizeDiff > 0) {
if (!checkForReplace(rowIndex, datatype)) {
throw new InvalidDataTypeException(datatype.getDisplayName() + " doesn't fit.");
}
if (!isAtEnd(rowIndex) && sizeDiff > 0) {
checkForReplace(rowIndex, datatype, newCompSize);
}

// Replace the component at index.
Expand Down Expand Up @@ -811,35 +819,76 @@ protected DataTypeComponent replaceComponentRange(int startRowIndex, int endRowI
*
* @param rowIndex index of the row (component).
* @param datatype the type
* @return true if the replace is allowed
* @param length component length
* @throws InvalidDataTypeException if check fails
*/
boolean checkForReplace(int rowIndex, DataType datatype) {
private void checkForReplace(int rowIndex, DataType datatype, int length) throws InvalidDataTypeException {
DataTypeComponent dtc = getComponent(rowIndex);
if (dtc == null) {
return false;
throw new InvalidDataTypeException("Invalid component selection");
}
if (!isShowingUndefinedBytes()) {
return true;
if (!(viewComposite instanceof Structure struct)) {
return;
}
if (struct.isPackingEnabled()) {
return;
}
if (isAtEnd(rowIndex)) {
return;
}

// Does the new data type fit by replacing the component at index.

// Get the current data type at the index.
DataTypeComponent comp = getComponent(rowIndex);
int currentCompSize = comp.getLength();
int newCompSize = datatype.getLength();
int currentCompSize = dtc.getLength();
int newCompSize = length;
int sizeDiff = newCompSize - currentCompSize;
int numUndefs = 0;

// New one is larger.
if (sizeDiff > 0) {
if (isAtEnd(rowIndex) || onlyUndefinedsUntilEnd(rowIndex + 1)) {
return true;

if (sizeDiff <= 0) {
return;
}

int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);
if (sizeDiff > undefinedSpaceAvail) {
int spaceNeeded = sizeDiff - undefinedSpaceAvail;
String msg = newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());
if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {
// suggest growing structure
int suggestedSize = getLength() + spaceNeeded;
throw new InvalidDataTypeException(msg + " requires structure length of " + suggestedSize + "-bytes.");
}
// structure needs to have enough undefined bytes or replace fails.
numUndefs = getNumUndefinedBytesAt(rowIndex + 1);
// suggest insert bytes (NOTE: in the future a conflict removal/grow could be offered)
throw new InvalidDataTypeException(msg + " requires " + spaceNeeded + " additional undefined bytes.");
}

return (sizeDiff <= numUndefs);
}

/**
* Get the number of undefined bytes after the specified component.
* The viewComposite must be a non-packed structure.
* @param dtc datatype component
* @return number of undefined bytes after non-packed structure component or -1 if no additional
* defined components exist which will impead component growth or placement.
*/
protected final int getNumUndefinedBytesAfter(DataTypeComponent dtc) {
if (!isShowingUndefinedBytes()) {
throw new UnsupportedOperationException();
}
if (!(viewComposite instanceof Structure struct)) {
throw new UnsupportedOperationException();
}
if (struct.isPackingEnabled()) {
throw new UnsupportedOperationException();
}

// TODO: May need special logic if dtc is zero-length component
int length = getLength();
int nextCompOffset = dtc.getEndOffset() + 1;
if (nextCompOffset >= length) {
return 0;
}
DataTypeComponent nextDefinedDtc = struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);
int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset();
return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value
}

/**
Expand Down Expand Up @@ -1013,34 +1062,6 @@ protected void createArray(int numElements) throws InvalidDataTypeException, Usr
});
}

/**
* Returns the number of undefined bytes that are available in the structure
* beginning at the specified row index.
*
* @param rowIndex the index of the row
* @return the number of bytes
*/
protected int getNumUndefinedBytesAt(int rowIndex) {
int numRowComponents = getNumComponents();
if (rowIndex < 0 || rowIndex >= numRowComponents) {
return 0;
}
DataTypeComponent startComponent = getComponent(rowIndex);
int previousOffset = (startComponent != null) ? startComponent.getOffset() : 0;
for (int currentRowIndex =
rowIndex; currentRowIndex < numRowComponents; currentRowIndex++) {
// Get the current data type at the index.
DataTypeComponent comp = getComponent(currentRowIndex);
DataType dt = comp.getDataType();
int currentOffset = comp.getOffset();
if (!dt.equals(DataType.DEFAULT)) {
return currentOffset - previousOffset; // Ran into data type other than undefined byte.
}
}

return viewComposite.getLength() - previousOffset;
}

/**
* Determine if the indicated row index is at or beyond the last component in this composite.
*
Expand All @@ -1062,36 +1083,6 @@ protected boolean isAtEnd(int rowIndex) {
return false;
}

/**
* Determine whether or not there are only undefined data types from the indicated rowIndex
* until the end of the composite. There must be at least one undefined data type to return true.
*
* @param rowIndex the index of the row to begin checking for undefined data types.
* @return true if an undefined data type is at the indicated row index and all components
* from there to the end of the composite are undefined data types.
*/
protected boolean onlyUndefinedsUntilEnd(int rowIndex) {
if (!isShowingUndefinedBytes()) {
return false;
}
int numRowComponents = getNumComponents();
if (rowIndex < 0) {
return false;
}
if (rowIndex >= numRowComponents) {
return false; // Beyond last component.
}
for (int i = rowIndex; i < numRowComponents; i++) {
// Get the current data type at the index.
DataTypeComponent comp = getComponent(i);
DataType dt = comp.getDataType();
if (!dt.equals(DataType.DEFAULT)) {
return false; // Ran into data type other than undefined byte.
}
}
return true;
}

/**
* Cause the component at the specified index to consume undefined bytes
* that follow it.
Expand Down Expand Up @@ -1670,16 +1661,17 @@ public int getMaxDuplicates(int rowIndex) {
if ((rowIndex < 0) || (rowIndex >= numRowComponents)) {
return 0;
}
if (rowIndex + 1 == numRowComponents) {
return Integer.MAX_VALUE; // On last component.
DataTypeComponent dtc = getComponent(rowIndex);
DataType dt = dtc.getDataType();
int dtcLen = dt.getLength();
if (dtcLen < 0) {
dtcLen = dtc.getLength();
}
DataType dt = getComponent(rowIndex).getDataType();
int maxDups = Integer.MAX_VALUE;
// If editModel is showing undefined bytes (non-packed)
// then constrain by number of undefined bytes that follow.
if (isShowingUndefinedBytes() && (dt != DataType.DEFAULT)) {
int numBytes = getNumUndefinedBytesAt(rowIndex + 1);
maxDups = (numBytes / dt.getLength());
int maxDups = (Integer.MAX_VALUE - getLength()) / dtcLen;
if (dt != DataType.DEFAULT && isShowingUndefinedBytes() && !isAtEnd(rowIndex)) {
// If editModel is showing undefined bytes (non-packed)
// then constrain by number of undefined bytes that follow.
maxDups = getNumUndefinedBytesAfter(dtc) / dtcLen;
}
return maxDups;
}
Expand Down Expand Up @@ -1715,15 +1707,7 @@ public int getMaxElements() {
return numBytesInRange / len;
}
// single line selected.

// If editModel is locked then constrain by number of undefined bytes that follow.
if (!isShowingUndefinedBytes() || isAtEnd(rowIndex) ||
onlyUndefinedsUntilEnd(rowIndex + 1)) {
return Integer.MAX_VALUE;
}

int numBytes = getNumUndefinedBytesAt(rowIndex + 1);
return 1 + (numBytes / len);
return getMaxDuplicates(rowIndex) + 1;
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
* <p>
* Note: Any new actions must be registered in the editor manager via the actions's name.
*/
abstract public class CompositeEditorTableAction extends DockingAction
implements CompositeEditorModelListener {
abstract public class CompositeEditorTableAction extends DockingAction {

static final String MAIN_ACTION_GROUP = "0_MAIN_EDITOR_ACTION";
static final String UNDOREDO_ACTION_GROUP = "1_UNDOREDO_EDITOR_ACTION";
Expand Down Expand Up @@ -79,14 +78,12 @@ private void init(CompositeEditorProvider editorProvider) {
this.model = provider.getModel();
this.plugin = provider.plugin;
this.tool = plugin.getTool();
model.addCompositeEditorModelListener(this);
String helpAnchor = provider.getHelpName() + "_" + getHelpName();
setHelpLocation(new HelpLocation(provider.getHelpTopic(), helpAnchor));
}

@Override
public void dispose() {
model.removeCompositeEditorModelListener(this);
super.dispose();
provider = null;
model = null;
Expand All @@ -108,43 +105,4 @@ public String getHelpName() {
return getName();
}

@Override
public void selectionChanged() {
provider.contextChanged();
}

public void editStateChanged(int i) {
provider.contextChanged();
}

@Override
public void compositeEditStateChanged(int type) {
provider.contextChanged();
}

@Override
public void endFieldEditing() {
provider.contextChanged();
}

@Override
public void componentDataChanged() {
provider.contextChanged();
}

@Override
public void compositeInfoChanged() {
provider.contextChanged();
}

@Override
public void statusChanged(String message, boolean beep) {
// we are an action; don't care about status messages
}

@Override
public void showUndefinedStateChanged(boolean showUndefinedBytes) {
provider.contextChanged();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ protected void selectionChanged() {
for (CompositeViewerModelListener listener : modelListeners) {
listener.selectionChanged();
}
provider.contextChanged();
});
}

Expand Down
Loading

0 comments on commit d16fa12

Please sign in to comment.