Merge remote-tracking branch 'origin/GP-4347_ryanmkurtz_blocks'

(Closes #6238)
This commit is contained in:
Ryan Kurtz
2024-02-23 07:11:22 -05:00
9 changed files with 35 additions and 21 deletions
@@ -134,10 +134,10 @@
this property applies to Default and Overlay blocks.</P>
<P><I><B>Byte Source -</B></I> Provides information about the source of the bytes in this
block. If the bytes were originally imported from a file, then this will indicate which file
and the offset into that file. If the bytes are mapped to another region of memory, it will
provide the address for the mapping. Blocks may consist of regions that have different
sources. In that case, source information about the first several regions will be
block. A block is made up of one or more sub-blocks. Each sub-block is listed by its type,
size, and other type-specific information. For example, if the bytes were originally imported
from a file, then the file name and the offset into that file is displayed. If the bytes are
mapped to another region of memory, then the start address for the mapping will be
displayed.</P>
<P><I><B>Source -</B></I> Description of block origination.</P>
@@ -467,7 +467,7 @@ class MemoryMapModel extends AbstractSortedTableModel<MemoryBlock> implements Pr
String description = limited
.stream()
.map(info -> info.getDescription())
.collect(Collectors.joining(", "));
.collect(Collectors.joining(" | "));
//@formatter:on
if (limited != sourceInfos) {
description += "...";
@@ -209,7 +209,7 @@ public class MemoryBlockUtils {
* @param w the write permission for the new block.
* @param x the execute permission for the new block.
* @param log a {@link MessageLog} for appending error messages
* @return the new created block
* @return the newly created block or null if the operation failed
* @throws AddressOverflowException if the address
*/
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay,
@@ -262,7 +262,7 @@ public class MemoryBlockUtils {
* @param x the execute permission for the new block.
* @param log a {@link MessageLog} for appending error messages
* @param monitor the monitor for canceling this potentially long running operation.
* @return the new created block
* @return the newly created block or null if the operation failed
* @throws AddressOverflowException if the address
*/
public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay,
@@ -46,6 +46,7 @@ import ghidra.program.model.address.*;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.program.model.reloc.Relocation.Status;
import ghidra.program.model.reloc.RelocationTable;
import ghidra.program.model.symbol.*;
@@ -671,6 +672,7 @@ public class PeLoader extends AbstractPeDebugLoader {
int rawDataSize = sections[i].getSizeOfRawData();
int rawDataPtr = sections[i].getPointerToRawData();
virtualSize = sections[i].getVirtualSize();
MemoryBlock block = null;
if (rawDataSize != 0 && rawDataPtr != 0) {
int dataSize =
((rawDataSize > virtualSize && virtualSize > 0) || rawDataSize < 0)
@@ -682,8 +684,8 @@ public class PeLoader extends AbstractPeDebugLoader {
Msg.warn(this, "OptionalHeader.SizeOfImage < size of " +
sections[i].getName() + " section");
}
MemoryBlockUtils.createInitializedBlock(prog, false, sectionName, address,
fileBytes, rawDataPtr, dataSize, "", "", r, w, x, log);
block = MemoryBlockUtils.createInitializedBlock(prog, false, sectionName,
address, fileBytes, rawDataPtr, dataSize, "", "", r, w, x, log);
sectionToAddress.put(sections[i], address);
}
if (rawDataSize == virtualSize) {
@@ -711,9 +713,24 @@ public class PeLoader extends AbstractPeDebugLoader {
else {
int dataSize = (virtualSize > 0 || rawDataSize < 0) ? virtualSize : 0;
if (dataSize > 0) {
MemoryBlockUtils.createUninitializedBlock(prog, false, sectionName, address,
dataSize, "", "", r, w, x, log);
sectionToAddress.putIfAbsent(sections[i], address);
if (block != null) {
MemoryBlock paddingBlock =
MemoryBlockUtils.createInitializedBlock(prog, false, sectionName,
address, dataSize, "", "", r, w, x, log);
if (paddingBlock != null) {
try {
prog.getMemory().join(block, paddingBlock);
}
catch (Exception e) {
log.appendMsg(e.getMessage());
}
}
}
else {
MemoryBlockUtils.createUninitializedBlock(prog, false, sectionName,
address, dataSize, "", "", r, w, x, log);
sectionToAddress.putIfAbsent(sections[i], address);
}
}
}
@@ -179,7 +179,7 @@ class BitMappedSubMemoryBlock extends SubMemoryBlock {
@Override
protected String getDescription() {
return "Bit Mapped: " + mappedAddress;
return "bitmap[0x%x, 0x%x, %s]".formatted(subBlockOffset, subBlockLength, mappedAddress);
}
}
@@ -117,6 +117,6 @@ class BufferSubMemoryBlock extends SubMemoryBlock {
@Override
protected String getDescription() {
return "";
return "init[0x%x]".formatted(subBlockLength);
}
}
@@ -199,7 +199,7 @@ class ByteMappedSubMemoryBlock extends SubMemoryBlock {
@Override
protected String getDescription() {
return "Byte Mapped: " + mappedAddress + ", " + byteMappingScheme;
return "bytemap[0x%x, 0x%x, %s]".formatted(subBlockOffset, subBlockLength, mappedAddress);
}
}
@@ -112,10 +112,8 @@ class FileBytesSubMemoryBlock extends SubMemoryBlock {
@Override
protected String getDescription() {
String fileName = fileBytes.getFilename();
String hexString = Long.toHexString(fileBytesOffset + fileBytes.getFileOffset());
return "File: " + fileName + ": 0x" + hexString;
return "%s[0x%x, 0x%x]".formatted(fileBytes.getFilename(),
fileBytesOffset + fileBytes.getFileOffset(), subBlockLength);
}
@Override
@@ -86,7 +86,6 @@ class UninitializedSubMemoryBlock extends SubMemoryBlock {
@Override
protected String getDescription() {
return "";
return "uninit[0x%x]".formatted(subBlockLength);
}
}