mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch 'origin/Ghidra_11.4'
This commit is contained in:
commit
5772ac2ab8
3 changed files with 38 additions and 20 deletions
|
@ -472,17 +472,21 @@ public class GoModuledata implements StructureMarkup<GoModuledata> {
|
||||||
int ptrSize = context.getPtrSize();
|
int ptrSize = context.getPtrSize();
|
||||||
byte[] searchBytes = new byte[ptrSize];
|
byte[] searchBytes = new byte[ptrSize];
|
||||||
context.getDataConverter().putValue(pcHeaderAddress.getOffset(), ptrSize, searchBytes, 0);
|
context.getDataConverter().putValue(pcHeaderAddress.getOffset(), ptrSize, searchBytes, 0);
|
||||||
Address moduleAddr = memory.findBytes(range.getMinAddress(), range.getMaxAddress(),
|
|
||||||
searchBytes, null, true, monitor);
|
Address moduleAddr;
|
||||||
if (moduleAddr == null) {
|
while ((moduleAddr = memory.findBytes(range.getMinAddress(), range.getMaxAddress(),
|
||||||
return null;
|
searchBytes, null, true, monitor)) != null) {
|
||||||
|
|
||||||
|
GoModuledata moduleData = context.readStructure(GoModuledata.class, moduleAddr);
|
||||||
|
|
||||||
|
// Verify that we read a good GoModuledata struct by comparing some of its values to
|
||||||
|
// the pclntab structure.
|
||||||
|
if (moduleData.matchesPcHeader(pcHeader)) {
|
||||||
|
return moduleData;
|
||||||
|
}
|
||||||
|
range = new AddressRangeImpl(moduleAddr.next(), range.getMaxAddress());
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
GoModuledata moduleData = context.readStructure(GoModuledata.class, moduleAddr);
|
|
||||||
|
|
||||||
// Verify that we read a good GoModuledata struct by comparing some of its values to
|
|
||||||
// the pclntab structure.
|
|
||||||
return moduleData.matchesPcHeader(pcHeader) ? moduleData : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ import java.io.IOException;
|
||||||
import ghidra.app.util.bin.*;
|
import ghidra.app.util.bin.*;
|
||||||
import ghidra.app.util.bin.format.golang.GoVer;
|
import ghidra.app.util.bin.format.golang.GoVer;
|
||||||
import ghidra.app.util.bin.format.golang.structmapping.*;
|
import ghidra.app.util.bin.format.golang.structmapping.*;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.*;
|
||||||
import ghidra.program.model.address.AddressRange;
|
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
import ghidra.program.model.lang.Endian;
|
import ghidra.program.model.lang.Endian;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
|
@ -47,6 +46,7 @@ public class GoPcHeader {
|
||||||
public static final int GO_1_2_MAGIC = 0xfffffffb;
|
public static final int GO_1_2_MAGIC = 0xfffffffb;
|
||||||
public static final int GO_1_16_MAGIC = 0xfffffffa;
|
public static final int GO_1_16_MAGIC = 0xfffffffa;
|
||||||
public static final int GO_1_18_MAGIC = 0xfffffff0;
|
public static final int GO_1_18_MAGIC = 0xfffffff0;
|
||||||
|
public static final int GO_1_20_MAGIC = 0xfffffff1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Address} (if present) of the go pclntab section or symbol.
|
* Returns the {@link Address} (if present) of the go pclntab section or symbol.
|
||||||
|
@ -112,15 +112,18 @@ public class GoPcHeader {
|
||||||
(byte) 0xff // ptrSize
|
(byte) 0xff // ptrSize
|
||||||
};
|
};
|
||||||
Memory memory = programContext.getProgram().getMemory();
|
Memory memory = programContext.getProgram().getMemory();
|
||||||
Address pcHeaderAddr = memory.findBytes(range.getMinAddress(), range.getMaxAddress(),
|
Address pcHeaderAddr;
|
||||||
searchBytes, searchMask, true, monitor);
|
while ((pcHeaderAddr = memory.findBytes(range.getMinAddress(), range.getMaxAddress(),
|
||||||
if (pcHeaderAddr == null) {
|
searchBytes, searchMask, true, monitor)) != null) {
|
||||||
return null;
|
try (MemoryByteProvider bp =
|
||||||
}
|
new MemoryByteProvider(memory, pcHeaderAddr, range.getMaxAddress())) {
|
||||||
try (MemoryByteProvider bp =
|
if (isPcHeader(bp)) {
|
||||||
new MemoryByteProvider(memory, pcHeaderAddr, range.getMaxAddress())) {
|
return pcHeaderAddr;
|
||||||
return isPcHeader(bp) ? pcHeaderAddr : null;
|
}
|
||||||
|
}
|
||||||
|
range = new AddressRangeImpl(pcHeaderAddr.next(), range.getMaxAddress());
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -286,6 +289,10 @@ public class GoPcHeader {
|
||||||
return ptrSize;
|
return ptrSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMagic() {
|
||||||
|
return magic;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------
|
||||||
record GoVerEndian(GoVer goVer, Endian endian) {
|
record GoVerEndian(GoVer goVer, Endian endian) {
|
||||||
GoVerEndian(GoVer goVer, boolean isLittleEndian) {
|
GoVerEndian(GoVer goVer, boolean isLittleEndian) {
|
||||||
|
@ -314,6 +321,7 @@ public class GoPcHeader {
|
||||||
case GO_1_2_MAGIC -> new GoVer(1, 2, 0);
|
case GO_1_2_MAGIC -> new GoVer(1, 2, 0);
|
||||||
case GO_1_16_MAGIC -> new GoVer(1, 16, 0);
|
case GO_1_16_MAGIC -> new GoVer(1, 16, 0);
|
||||||
case GO_1_18_MAGIC -> new GoVer(1, 18, 0);
|
case GO_1_18_MAGIC -> new GoVer(1, 18, 0);
|
||||||
|
case GO_1_20_MAGIC -> new GoVer(1, 20, 0);
|
||||||
default -> GoVer.INVALID;
|
default -> GoVer.INVALID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -507,6 +507,12 @@ public class GoRttiMapper extends DataTypeMapper implements DataTypeMapperContex
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Mismatched ptrSize: %d vs %d".formatted(pcHeader.getPtrSize(), ptrSize));
|
"Mismatched ptrSize: %d vs %d".formatted(pcHeader.getPtrSize(), ptrSize));
|
||||||
}
|
}
|
||||||
|
if (pcHeader.getGoVersion().isInvalid()) {
|
||||||
|
// we can get here if the firstmoduledata was located via symbolname instead of
|
||||||
|
// relying on bootstraping via the pcheader
|
||||||
|
Msg.warn(this,
|
||||||
|
"Unknown golang pcheader magic value: 0x%x".formatted(pcHeader.getMagic()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addModule(firstModule);
|
addModule(firstModule);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue