Skip to content

Commit 2ce8463

Browse files
committed
Merge remote-tracking branch 'origin/GP-4347_ryanmkurtz_blocks'
(Closes NationalSecurityAgency#6238)
2 parents 5690528 + f9ce96f commit 2ce8463

File tree

9 files changed

+35
-21
lines changed

9 files changed

+35
-21
lines changed

Ghidra/Features/Base/src/main/help/help/topics/MemoryMapPlugin/Memory_Map.htm

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ <H1><A name="View_Memory_Map"></A>Memory Map</H1>
134134
this property applies to Default and Overlay blocks.</P>
135135

136136
<P><I><B>Byte Source -</B></I> Provides information about the source of the bytes in this
137-
block. If the bytes were originally imported from a file, then this will indicate which file
138-
and the offset into that file. If the bytes are mapped to another region of memory, it will
139-
provide the address for the mapping. Blocks may consist of regions that have different
140-
sources. In that case, source information about the first several regions will be
137+
block. A block is made up of one or more sub-blocks. Each sub-block is listed by its type,
138+
size, and other type-specific information. For example, if the bytes were originally imported
139+
from a file, then the file name and the offset into that file is displayed. If the bytes are
140+
mapped to another region of memory, then the start address for the mapping will be
141141
displayed.</P>
142142

143143
<P><I><B>Source -</B></I> Description of block origination.</P>

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapModel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private String getByteSourceDescription(List<MemoryBlockSourceInfo> sourceInfos)
467467
String description = limited
468468
.stream()
469469
.map(info -> info.getDescription())
470-
.collect(Collectors.joining(", "));
470+
.collect(Collectors.joining(" | "));
471471
//@formatter:on
472472
if (limited != sourceInfos) {
473473
description += "...";

Ghidra/Features/Base/src/main/java/ghidra/app/util/MemoryBlockUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public static MemoryBlock createByteMappedBlock(Program program, String name, Ad
209209
* @param w the write permission for the new block.
210210
* @param x the execute permission for the new block.
211211
* @param log a {@link MessageLog} for appending error messages
212-
* @return the new created block
212+
* @return the newly created block or null if the operation failed
213213
* @throws AddressOverflowException if the address
214214
*/
215215
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay,
@@ -262,7 +262,7 @@ public static MemoryBlock createInitializedBlock(Program program, boolean isOver
262262
* @param x the execute permission for the new block.
263263
* @param log a {@link MessageLog} for appending error messages
264264
* @param monitor the monitor for canceling this potentially long running operation.
265-
* @return the new created block
265+
* @return the newly created block or null if the operation failed
266266
* @throws AddressOverflowException if the address
267267
*/
268268
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay,

Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/PeLoader.java

+22-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import ghidra.program.model.data.*;
4747
import ghidra.program.model.listing.*;
4848
import ghidra.program.model.mem.MemoryAccessException;
49+
import ghidra.program.model.mem.MemoryBlock;
4950
import ghidra.program.model.reloc.Relocation.Status;
5051
import ghidra.program.model.reloc.RelocationTable;
5152
import ghidra.program.model.symbol.*;
@@ -671,6 +672,7 @@ protected Map<SectionHeader, Address> processMemoryBlocks(PortableExecutable pe,
671672
int rawDataSize = sections[i].getSizeOfRawData();
672673
int rawDataPtr = sections[i].getPointerToRawData();
673674
virtualSize = sections[i].getVirtualSize();
675+
MemoryBlock block = null;
674676
if (rawDataSize != 0 && rawDataPtr != 0) {
675677
int dataSize =
676678
((rawDataSize > virtualSize && virtualSize > 0) || rawDataSize < 0)
@@ -682,8 +684,8 @@ protected Map<SectionHeader, Address> processMemoryBlocks(PortableExecutable pe,
682684
Msg.warn(this, "OptionalHeader.SizeOfImage < size of " +
683685
sections[i].getName() + " section");
684686
}
685-
MemoryBlockUtils.createInitializedBlock(prog, false, sectionName, address,
686-
fileBytes, rawDataPtr, dataSize, "", "", r, w, x, log);
687+
block = MemoryBlockUtils.createInitializedBlock(prog, false, sectionName,
688+
address, fileBytes, rawDataPtr, dataSize, "", "", r, w, x, log);
687689
sectionToAddress.put(sections[i], address);
688690
}
689691
if (rawDataSize == virtualSize) {
@@ -711,9 +713,24 @@ else if (rawDataSize > virtualSize) {
711713
else {
712714
int dataSize = (virtualSize > 0 || rawDataSize < 0) ? virtualSize : 0;
713715
if (dataSize > 0) {
714-
MemoryBlockUtils.createUninitializedBlock(prog, false, sectionName, address,
715-
dataSize, "", "", r, w, x, log);
716-
sectionToAddress.putIfAbsent(sections[i], address);
716+
if (block != null) {
717+
MemoryBlock paddingBlock =
718+
MemoryBlockUtils.createInitializedBlock(prog, false, sectionName,
719+
address, dataSize, "", "", r, w, x, log);
720+
if (paddingBlock != null) {
721+
try {
722+
prog.getMemory().join(block, paddingBlock);
723+
}
724+
catch (Exception e) {
725+
log.appendMsg(e.getMessage());
726+
}
727+
}
728+
}
729+
else {
730+
MemoryBlockUtils.createUninitializedBlock(prog, false, sectionName,
731+
address, dataSize, "", "", r, w, x, log);
732+
sectionToAddress.putIfAbsent(sections[i], address);
733+
}
717734
}
718735
}
719736

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/BitMappedSubMemoryBlock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected SubMemoryBlock split(long offset) {
179179

180180
@Override
181181
protected String getDescription() {
182-
return "Bit Mapped: " + mappedAddress;
182+
return "bitmap[0x%x, 0x%x, %s]".formatted(subBlockOffset, subBlockLength, mappedAddress);
183183
}
184184

185185
}

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/BufferSubMemoryBlock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ protected SubMemoryBlock split(long memBlockOffset)
117117

118118
@Override
119119
protected String getDescription() {
120-
return "";
120+
return "init[0x%x]".formatted(subBlockLength);
121121
}
122122
}

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/ByteMappedSubMemoryBlock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected SubMemoryBlock split(long memBlockOffset) throws IOException {
199199

200200
@Override
201201
protected String getDescription() {
202-
return "Byte Mapped: " + mappedAddress + ", " + byteMappingScheme;
202+
return "bytemap[0x%x, 0x%x, %s]".formatted(subBlockOffset, subBlockLength, mappedAddress);
203203
}
204204

205205
}

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/FileBytesSubMemoryBlock.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ protected SubMemoryBlock split(long memBlockOffset) throws IOException {
112112

113113
@Override
114114
protected String getDescription() {
115-
String fileName = fileBytes.getFilename();
116-
117-
String hexString = Long.toHexString(fileBytesOffset + fileBytes.getFileOffset());
118-
return "File: " + fileName + ": 0x" + hexString;
115+
return "%s[0x%x, 0x%x]".formatted(fileBytes.getFilename(),
116+
fileBytesOffset + fileBytes.getFileOffset(), subBlockLength);
119117
}
120118

121119
@Override

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/mem/UninitializedSubMemoryBlock.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ protected SubMemoryBlock split(long memBlockOffset) throws IOException {
8686

8787
@Override
8888
protected String getDescription() {
89-
return "";
89+
return "uninit[0x%x]".formatted(subBlockLength);
9090
}
91-
9291
}

0 commit comments

Comments
 (0)