mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 19:11:28 +08:00
Merge remote-tracking branch 'origin/GT-3330_dev747368_DWARF_relocated_addresses_mode'
This commit is contained in:
@@ -51,6 +51,20 @@ public class MemoryByteProvider implements ByteProvider {
|
|||||||
this.baseAddress = baseAddress;
|
this.baseAddress = baseAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an index into this ByteProvider into an {@link Address}.
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* @param index absolute index in this ByteProvider to convert into an Address
|
||||||
|
* @return {@link Address}
|
||||||
|
* @throws AddressOutOfBoundsException if wrapping is not supported by the
|
||||||
|
* corresponding address space and the addition causes an out-of-bounds
|
||||||
|
* error
|
||||||
|
*/
|
||||||
|
public Address getAddress(long index) {
|
||||||
|
return baseAddress.add(index);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStream(long index) throws IOException {
|
public InputStream getInputStream(long index) throws IOException {
|
||||||
return new MemoryByteProviderInputStream(memory, baseAddress.add(index));
|
return new MemoryByteProviderInputStream(memory, baseAddress.add(index));
|
||||||
|
|||||||
+1
-5
@@ -21,7 +21,6 @@ import java.util.*;
|
|||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import ghidra.app.util.bin.BinaryReader;
|
import ghidra.app.util.bin.BinaryReader;
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
|
||||||
import ghidra.app.util.bin.format.dwarf4.attribs.*;
|
import ghidra.app.util.bin.format.dwarf4.attribs.*;
|
||||||
import ghidra.app.util.bin.format.dwarf4.encoding.*;
|
import ghidra.app.util.bin.format.dwarf4.encoding.*;
|
||||||
import ghidra.app.util.bin.format.dwarf4.expression.*;
|
import ghidra.app.util.bin.format.dwarf4.expression.*;
|
||||||
@@ -800,10 +799,7 @@ public class DIEAggregate {
|
|||||||
*/
|
*/
|
||||||
public List<DWARFRange> parseDebugRange(int attribute) throws IOException {
|
public List<DWARFRange> parseDebugRange(int attribute) throws IOException {
|
||||||
byte pointerSize = getCompilationUnit().getPointerSize();
|
byte pointerSize = getCompilationUnit().getPointerSize();
|
||||||
boolean isLittleEndian = getCompilationUnit().getProgram().isLittleEndian();
|
BinaryReader reader = getCompilationUnit().getProgram().getDebugRanges();
|
||||||
|
|
||||||
ByteProvider debug_ranges = getCompilationUnit().getProgram().getDebugRanges();
|
|
||||||
BinaryReader reader = new BinaryReader(debug_ranges, isLittleEndian);
|
|
||||||
|
|
||||||
long offset = getUnsignedLong(attribute, -1);
|
long offset = getUnsignedLong(attribute, -1);
|
||||||
if (offset == -1) {
|
if (offset == -1) {
|
||||||
|
|||||||
+35
-13
@@ -22,8 +22,7 @@ import java.util.*;
|
|||||||
import org.apache.commons.collections4.ListValuedMap;
|
import org.apache.commons.collections4.ListValuedMap;
|
||||||
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
|
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
|
||||||
|
|
||||||
import ghidra.app.util.bin.BinaryReader;
|
import ghidra.app.util.bin.*;
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
|
||||||
import ghidra.app.util.bin.format.dwarf4.*;
|
import ghidra.app.util.bin.format.dwarf4.*;
|
||||||
import ghidra.app.util.bin.format.dwarf4.attribs.DWARFAttributeFactory;
|
import ghidra.app.util.bin.format.dwarf4.attribs.DWARFAttributeFactory;
|
||||||
import ghidra.app.util.bin.format.dwarf4.encoding.*;
|
import ghidra.app.util.bin.format.dwarf4.encoding.*;
|
||||||
@@ -31,6 +30,8 @@ import ghidra.app.util.bin.format.dwarf4.expression.DWARFExpressionException;
|
|||||||
import ghidra.app.util.bin.format.dwarf4.next.sectionprovider.*;
|
import ghidra.app.util.bin.format.dwarf4.next.sectionprovider.*;
|
||||||
import ghidra.app.util.opinion.ElfLoader;
|
import ghidra.app.util.opinion.ElfLoader;
|
||||||
import ghidra.app.util.opinion.MachoLoader;
|
import ghidra.app.util.opinion.MachoLoader;
|
||||||
|
import ghidra.program.model.address.Address;
|
||||||
|
import ghidra.program.model.address.AddressSet;
|
||||||
import ghidra.program.model.data.CategoryPath;
|
import ghidra.program.model.data.CategoryPath;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.model.symbol.SymbolUtilities;
|
import ghidra.program.model.symbol.SymbolUtilities;
|
||||||
@@ -108,7 +109,7 @@ public class DWARFProgram implements Closeable {
|
|||||||
new HashMap<>();
|
new HashMap<>();
|
||||||
|
|
||||||
private BinaryReader debugLocation;
|
private BinaryReader debugLocation;
|
||||||
private ByteProvider debugRanges;
|
private BinaryReader debugRanges;
|
||||||
private BinaryReader debugInfoBR;
|
private BinaryReader debugInfoBR;
|
||||||
private BinaryReader debugLineBR;
|
private BinaryReader debugLineBR;
|
||||||
private BinaryReader debugAbbrBR;
|
private BinaryReader debugAbbrBR;
|
||||||
@@ -185,10 +186,7 @@ public class DWARFProgram implements Closeable {
|
|||||||
this.importOptions = importOptions;
|
this.importOptions = importOptions;
|
||||||
this.nameLengthCutoffSize = Math.max(MIN_NAME_LENGTH_CUTOFF,
|
this.nameLengthCutoffSize = Math.max(MIN_NAME_LENGTH_CUTOFF,
|
||||||
Math.min(importOptions.getNameLengthCutoff(), MAX_NAME_LENGTH_CUTOFF));
|
Math.min(importOptions.getNameLengthCutoff(), MAX_NAME_LENGTH_CUTOFF));
|
||||||
Long oib = ElfLoader.getElfOriginalImageBase(program);
|
|
||||||
if (oib != null && oib.longValue() != program.getImageBase().getOffset()) {
|
|
||||||
this.programBaseAddressFixup = program.getImageBase().getOffset() - oib.longValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor.setMessage("Reading DWARF debug string table");
|
monitor.setMessage("Reading DWARF debug string table");
|
||||||
this.debugStrings = StringTable.readStringTable(
|
this.debugStrings = StringTable.readStringTable(
|
||||||
@@ -201,7 +199,17 @@ public class DWARFProgram implements Closeable {
|
|||||||
this.debugInfoBR = getBinaryReaderFor(DWARFSectionNames.DEBUG_INFO);
|
this.debugInfoBR = getBinaryReaderFor(DWARFSectionNames.DEBUG_INFO);
|
||||||
this.debugLineBR = getBinaryReaderFor(DWARFSectionNames.DEBUG_LINE);
|
this.debugLineBR = getBinaryReaderFor(DWARFSectionNames.DEBUG_LINE);
|
||||||
this.debugAbbrBR = getBinaryReaderFor(DWARFSectionNames.DEBUG_ABBREV);
|
this.debugAbbrBR = getBinaryReaderFor(DWARFSectionNames.DEBUG_ABBREV);
|
||||||
this.debugRanges = sectionProvider.getSectionAsByteProvider(DWARFSectionNames.DEBUG_RANGES);
|
this.debugRanges = getBinaryReaderFor(DWARFSectionNames.DEBUG_RANGES);// sectionProvider.getSectionAsByteProvider(DWARFSectionNames.DEBUG_RANGES);
|
||||||
|
|
||||||
|
// if there are relocations (already handled by the ghidra loader) anywhere in the debuginfo or debugrange sections, then
|
||||||
|
// we don't need to manually fix up addresses extracted from DWARF data.
|
||||||
|
boolean hasRelocations = hasRelocations(debugInfoBR) || hasRelocations(debugRanges);
|
||||||
|
if (!hasRelocations) {
|
||||||
|
Long oib = ElfLoader.getElfOriginalImageBase(program);
|
||||||
|
if (oib != null && oib.longValue() != program.getImageBase().getOffset()) {
|
||||||
|
this.programBaseAddressFixup = program.getImageBase().getOffset() - oib.longValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dwarfRegisterMappings =
|
dwarfRegisterMappings =
|
||||||
DWARFRegisterMappingsManager.hasDWARFRegisterMapping(program.getLanguage())
|
DWARFRegisterMappingsManager.hasDWARFRegisterMapping(program.getLanguage())
|
||||||
@@ -219,10 +227,7 @@ public class DWARFProgram implements Closeable {
|
|||||||
debugInfoBR = null;
|
debugInfoBR = null;
|
||||||
debugLineBR = null;
|
debugLineBR = null;
|
||||||
debugLocation = null;
|
debugLocation = null;
|
||||||
if (debugRanges != null) {
|
debugRanges = null;
|
||||||
debugRanges.close();
|
|
||||||
debugRanges = null;
|
|
||||||
}
|
|
||||||
debugStrings.clear();
|
debugStrings.clear();
|
||||||
dniCache.clear();
|
dniCache.clear();
|
||||||
clearDIEIndexes();
|
clearDIEIndexes();
|
||||||
@@ -249,6 +254,23 @@ public class DWARFProgram implements Closeable {
|
|||||||
return (bp != null) ? new BinaryReader(bp, !isBigEndian()) : null;
|
return (bp != null) ? new BinaryReader(bp, !isBigEndian()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasRelocations(BinaryReader br) throws IOException {
|
||||||
|
if (br == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ByteProvider bp = br.getByteProvider();
|
||||||
|
if (bp instanceof MemoryByteProvider && bp.length() > 0) {
|
||||||
|
MemoryByteProvider mbp = (MemoryByteProvider) bp;
|
||||||
|
Address startAddr = mbp.getAddress(0);
|
||||||
|
Address endAddr = mbp.getAddress(mbp.length() - 1);
|
||||||
|
if (program.getRelocationTable().getRelocations(
|
||||||
|
new AddressSet(startAddr, endAddr)).hasNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
private static boolean isAnonDWARFName(String name) {
|
private static boolean isAnonDWARFName(String name) {
|
||||||
return (name == null) || name.startsWith("._") || name.startsWith("<anonymous");
|
return (name == null) || name.startsWith("._") || name.startsWith("<anonymous");
|
||||||
@@ -594,7 +616,7 @@ public class DWARFProgram implements Closeable {
|
|||||||
return debugLocation;
|
return debugLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteProvider getDebugRanges() {
|
public BinaryReader getDebugRanges() {
|
||||||
return debugRanges;
|
return debugRanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user