mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GP-0: Moving MachoProgramUtils.addExternalBlock() to
AbstractProgramLoader
This commit is contained in:
parent
d460bf9382
commit
162733b585
5 changed files with 38 additions and 41 deletions
|
@ -24,8 +24,8 @@ import ghidra.app.util.bin.format.macho.dyld.DyldChainedPtr;
|
||||||
import ghidra.app.util.bin.format.macho.dyld.DyldChainedPtr.DyldChainType;
|
import ghidra.app.util.bin.format.macho.dyld.DyldChainedPtr.DyldChainType;
|
||||||
import ghidra.app.util.bin.format.macho.dyld.DyldFixup;
|
import ghidra.app.util.bin.format.macho.dyld.DyldFixup;
|
||||||
import ghidra.app.util.importer.MessageLog;
|
import ghidra.app.util.importer.MessageLog;
|
||||||
|
import ghidra.app.util.opinion.AbstractProgramLoader;
|
||||||
import ghidra.app.util.opinion.MachoProgramBuilder;
|
import ghidra.app.util.opinion.MachoProgramBuilder;
|
||||||
import ghidra.app.util.opinion.MachoProgramUtils;
|
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.listing.*;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.mem.Memory;
|
import ghidra.program.model.mem.Memory;
|
||||||
|
@ -153,7 +153,7 @@ public class DyldChainedFixups {
|
||||||
.mapToLong(DyldFixup::size)
|
.mapToLong(DyldFixup::size)
|
||||||
.sum();
|
.sum();
|
||||||
if (externalSize > 0) {
|
if (externalSize > 0) {
|
||||||
extAddr = MachoProgramUtils.addExternalBlock(program, externalSize, log);
|
extAddr = AbstractProgramLoader.addExternalBlock(program, externalSize, log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
|
|
@ -35,8 +35,7 @@ import ghidra.program.database.function.OverlappingFunctionException;
|
||||||
import ghidra.program.model.address.*;
|
import ghidra.program.model.address.*;
|
||||||
import ghidra.program.model.lang.*;
|
import ghidra.program.model.lang.*;
|
||||||
import ghidra.program.model.listing.*;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.mem.InvalidAddressException;
|
import ghidra.program.model.mem.*;
|
||||||
import ghidra.program.model.mem.MemoryConflictException;
|
|
||||||
import ghidra.program.model.symbol.*;
|
import ghidra.program.model.symbol.*;
|
||||||
import ghidra.program.util.DefaultLanguageService;
|
import ghidra.program.util.DefaultLanguageService;
|
||||||
import ghidra.program.util.GhidraProgramUtilities;
|
import ghidra.program.util.GhidraProgramUtilities;
|
||||||
|
@ -456,6 +455,39 @@ public abstract class AbstractProgramLoader implements Loader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the {@link MemoryBlock#EXTERNAL_BLOCK_NAME EXERNAL block} to memory, or adds to an
|
||||||
|
* existing one
|
||||||
|
*
|
||||||
|
* @param program The {@link Program}
|
||||||
|
* @param size The desired size of the new EXTERNAL block
|
||||||
|
* @param log The {@link MessageLog}
|
||||||
|
* @return The {@link Address} of the new (or new piece) of EXTERNAL block
|
||||||
|
* @throws Exception if there was an issue creating or adding to the EXTERNAL block
|
||||||
|
*/
|
||||||
|
public static Address addExternalBlock(Program program, long size, MessageLog log)
|
||||||
|
throws Exception {
|
||||||
|
Memory mem = program.getMemory();
|
||||||
|
MemoryBlock externalBlock = mem.getBlock(MemoryBlock.EXTERNAL_BLOCK_NAME);
|
||||||
|
Address ret;
|
||||||
|
if (externalBlock != null) {
|
||||||
|
ret = externalBlock.getEnd().add(1);
|
||||||
|
MemoryBlock newBlock =
|
||||||
|
mem.createBlock(externalBlock, MemoryBlock.EXTERNAL_BLOCK_NAME, ret, size);
|
||||||
|
mem.join(externalBlock, newBlock);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = MachoProgramUtils.getNextAvailableAddress(program);
|
||||||
|
externalBlock =
|
||||||
|
mem.createUninitializedBlock(MemoryBlock.EXTERNAL_BLOCK_NAME, ret, size, false);
|
||||||
|
externalBlock.setWrite(true);
|
||||||
|
externalBlock.setArtificial(true);
|
||||||
|
externalBlock.setComment(
|
||||||
|
"NOTE: This block is artificial and is used to make relocations work correctly");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link Loader}'s language service.
|
* Gets the {@link Loader}'s language service.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -593,7 +593,7 @@ public class MachoLoader extends AbstractLibrarySupportLoader {
|
||||||
.map(lib.getSymbolTable()::getPrimarySymbol)
|
.map(lib.getSymbolTable()::getPrimarySymbol)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.toList();
|
.toList();
|
||||||
Address addr = MachoProgramUtils.addExternalBlock(program,
|
Address addr = AbstractProgramLoader.addExternalBlock(program,
|
||||||
reexportedSymbols.size() * 8, log);
|
reexportedSymbols.size() * 8, log);
|
||||||
monitor.initialize(reexportedSymbols.size(), "Reexporting symbols...");
|
monitor.initialize(reexportedSymbols.size(), "Reexporting symbols...");
|
||||||
for (Symbol symbol : reexportedSymbols) {
|
for (Symbol symbol : reexportedSymbols) {
|
||||||
|
|
|
@ -731,7 +731,7 @@ public class MachoProgramBuilder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Address addr = MachoProgramUtils.addExternalBlock(program,
|
Address addr = AbstractProgramLoader.addExternalBlock(program,
|
||||||
undefinedSymbols.size() * machoHeader.getAddressSize(), log);
|
undefinedSymbols.size() * machoHeader.getAddressSize(), log);
|
||||||
monitor.initialize(undefinedSymbols.size(), "Processing undefined symbols...");
|
monitor.initialize(undefinedSymbols.size(), "Processing undefined symbols...");
|
||||||
for (NList symbol : undefinedSymbols) {
|
for (NList symbol : undefinedSymbols) {
|
||||||
|
|
|
@ -15,10 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.util.opinion;
|
package ghidra.app.util.opinion;
|
||||||
|
|
||||||
import ghidra.app.util.importer.MessageLog;
|
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.model.mem.Memory;
|
|
||||||
import ghidra.program.model.mem.MemoryBlock;
|
import ghidra.program.model.mem.MemoryBlock;
|
||||||
|
|
||||||
public class MachoProgramUtils {
|
public class MachoProgramUtils {
|
||||||
|
@ -46,37 +44,4 @@ public class MachoProgramUtils {
|
||||||
long remainder = maxAddr % 0x1000;
|
long remainder = maxAddr % 0x1000;
|
||||||
return maxAddress.getNewAddress(maxAddr + 0x1000 - remainder);
|
return maxAddress.getNewAddress(maxAddr + 0x1000 - remainder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@link MemoryBlock#EXTERNAL_BLOCK_NAME EXERNAL block} to memory, or adds to an
|
|
||||||
* existing one
|
|
||||||
*
|
|
||||||
* @param program The {@link Program}
|
|
||||||
* @param size The desired size of the new EXTERNAL block
|
|
||||||
* @param log The {@link MessageLog}
|
|
||||||
* @return The {@link Address} of the new (or new piece) of EXTERNAL block
|
|
||||||
* @throws Exception if there was an issue creating or adding to the EXTERNAL block
|
|
||||||
*/
|
|
||||||
public static Address addExternalBlock(Program program, long size, MessageLog log)
|
|
||||||
throws Exception {
|
|
||||||
Memory mem = program.getMemory();
|
|
||||||
MemoryBlock externalBlock = mem.getBlock(MemoryBlock.EXTERNAL_BLOCK_NAME);
|
|
||||||
Address ret;
|
|
||||||
if (externalBlock != null) {
|
|
||||||
ret = externalBlock.getEnd().add(1);
|
|
||||||
MemoryBlock newBlock =
|
|
||||||
mem.createBlock(externalBlock, MemoryBlock.EXTERNAL_BLOCK_NAME, ret, size);
|
|
||||||
mem.join(externalBlock, newBlock);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret = MachoProgramUtils.getNextAvailableAddress(program);
|
|
||||||
externalBlock =
|
|
||||||
mem.createUninitializedBlock(MemoryBlock.EXTERNAL_BLOCK_NAME, ret, size, false);
|
|
||||||
externalBlock.setWrite(true);
|
|
||||||
externalBlock.setArtificial(true);
|
|
||||||
externalBlock.setComment(
|
|
||||||
"NOTE: This block is artificial and is used to make relocations work correctly");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue