Skip to content

Commit 5fe28ee

Browse files
committed
Merge remote-tracking branch
'origin/GP-3675_ghidra1_CreateDatabackgroundCmd' into patch (Closes NationalSecurityAgency#5602)
2 parents 749d229 + 554f1c8 commit 5fe28ee

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateDataBackgroundCmd.java

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -126,58 +126,38 @@ public boolean doApplyTo(DomainObject obj, TaskMonitor monitor) {
126126
return true;
127127
}
128128

129-
private static Address alignAddress(Address addr, int alignment) {
130-
if (addr == null) {
131-
return null;
132-
}
133-
long mod = addr.getOffset() % alignment;
134-
if (mod == 0) {
135-
return addr;
136-
}
137-
try {
138-
return addr.addNoWrap(alignment - mod);
139-
}
140-
catch (AddressOverflowException e) {
141-
// ignore
142-
}
143-
return null;
144-
}
145-
146129
private void createData(Address start, Address end, DataType dataType, Program p,
147130
TaskMonitor monitor) throws CodeUnitInsertionException {
148131

149-
int alignment = 1;
150-
if (newDataType.getLength() != newDataType.getAlignedLength()) {
151-
// datatypes whose length does not match their aligned-length must
152-
// be properly aligned to account for padding (e.g., x86-32 80-bit floats)
153-
alignment = newDataType.getAlignment();
154-
}
132+
Address nextAddr = start;
133+
Listing listing = p.getListing();
134+
listing.clearCodeUnits(start, end, false);
155135

156136
int initialProgress = bytesApplied;
157137

158-
Listing listing = p.getListing();
159-
listing.clearCodeUnits(start, end, false);
160-
Address nextAddr = alignAddress(start, alignment);
161138
int length = (int) end.subtract(nextAddr) + 1;
162139
while (nextAddr != null && nextAddr.compareTo(end) <= 0) {
163140
if (monitor.isCancelled()) {
164141
return;
165142
}
166143

167144
Data d = listing.createData(nextAddr, dataType, length);
168-
Address maxDataAddr = d.getMaxAddress();
169-
bytesApplied = initialProgress + (int) maxDataAddr.subtract(start) + 1;
170-
nextAddr = alignAddress(maxDataAddr.next(), alignment);
171-
if (nextAddr != null) {
172-
length = (int) end.subtract(nextAddr) + 1;
145+
int dataLength = d.getLength();
146+
bytesApplied = initialProgress + dataLength;
147+
148+
try {
149+
nextAddr = nextAddr.addNoWrap(dataLength);
150+
length -= dataLength;
151+
}
152+
catch (AddressOverflowException e) {
153+
return;
173154
}
174155

175156
monitor.setProgress(bytesApplied);
176157
if (++numDataCreated % 10000 == 0) {
177158
monitor.setMessage("Created " + numDataCreated);
178159

179-
// Allow the Swing thread a chance to paint components that may require
180-
// a DB lock.
160+
// Allow the Swing thread a chance to paint components that may require lock
181161
Swing.allowSwingToProcessEvents();
182162
}
183163
}

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected DataTypeInstance getDropDataType(int rowIndex, DataType dt)
212212
}
213213

214214
DataType resultDt = DataUtilities.reconcileAppliedDataType(currentDt, dt, true);
215-
int resultLen = resultDt.getAlignedLength();
215+
int resultLen = resultDt.getLength();
216216

217217
if (resultDt instanceof Dynamic) {
218218
resultLen = DataTypeHelper.requestDtSize(getProvider(), resultDt.getDisplayName(),
@@ -222,7 +222,9 @@ else if (resultLen == 0) {
222222
throw new InvalidDataTypeException("Data types of size 0 are not allowed.");
223223
}
224224

225-
return DataTypeInstance.getDataTypeInstance(resultDt, resultLen, true);
225+
// TODO: Need to handle proper placement for big-endian within a larger component (i.e., right-justified)
226+
return DataTypeInstance.getDataTypeInstance(resultDt, resultLen,
227+
viewComposite.isPackingEnabled());
226228
}
227229

228230
/**

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataTypeInstance.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public String toString() {
7777
/**
7878
* Generate a data-type instance
7979
* Factory and Dynamic data-types are NOT handled.
80+
* <br>
81+
* This container does not dictate the placement of a fixed-length type within this
82+
* container. It is suggested that big-endian use should evaulate the datatype
83+
* at the far end of the container.
84+
*
8085
* @param dataType data type
8186
* @param buf memory buffer
8287
* @param useAlignedLength if true a fixed-length primitive data type will use its
@@ -95,6 +100,11 @@ public static DataTypeInstance getDataTypeInstance(DataType dataType, MemBuffer
95100
/**
96101
* Attempt to create a fixed-length data-type instance.
97102
* Factory and non-sizable Dynamic data-types are NOT handled.
103+
* <br>
104+
* This container does not dictate the placement of a fixed-length type within this
105+
* container. It is suggested that big-endian use should evaulate the datatype
106+
* at the far end of the container.
107+
*
98108
* @param dataType data type
99109
* @param length length for sizable Dynamic data-types, otherwise ignored
100110
* @param useAlignedLength if true a fixed-length primitive data type will use its
@@ -128,6 +138,7 @@ else if (dataType instanceof Dynamic) {
128138
}
129139
}
130140
else if (useAlignedLength) {
141+
// TODO: big-endian should place type at end of this container
131142
length = dataType.getAlignedLength();
132143
}
133144
else {
@@ -145,10 +156,11 @@ else if (useAlignedLength) {
145156
* Attempt to create a data-type instance associated with a specific memory location.
146157
* Factory and Dynamic data-types are handled.
147158
* <br>
148-
* NOTE: fixed-length primitive datatypes assume {@link DataType#getLength() raw datatype length}
149-
* intended for {@link Data} use.
159+
* This container does not dictate the placement of a fixed-length type within this
160+
* container. It is suggested that big-endian use should evaulate the datatype
161+
* at the far end of the container.
150162
*
151-
* @param dataType
163+
* @param dataType the data type
152164
* @param buf memory location
153165
* @param length length for sizable Dynamic data-types, otherwise ignored
154166
* @param useAlignedLength if true a fixed-length primitive data type will use its

0 commit comments

Comments
 (0)