Skip to content

Commit

Permalink
Improve the handling of data and function imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Mar 10, 2019
1 parent 1fca6eb commit b37a5e6
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/main/java/ghidra/app/util/opinion/RPXLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import ghidra.app.util.importer.MemoryConflictHandler;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.importer.MessageLogContinuesFactory;
import ghidra.program.database.external.ExternalManagerDB;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.RefType;
import ghidra.program.model.symbol.Reference;
import ghidra.program.model.symbol.SourceType;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.DuplicateNameException;
Expand Down Expand Up @@ -103,9 +104,26 @@ public void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
}

Address addr = aspace.getAddress(offset);
Reference r = program.getReferenceManager().addExternalReference(addr, rplName,
symbol.getNameAsString(), aspace.getAddress(0), SourceType.IMPORTED, 1, RefType.DATA);
program.getReferenceManager().setPrimary(r, true);
boolean isData = section.getNameAsString().startsWith(".d");

ExternalManagerDB em = (ExternalManagerDB) program.getExternalManager();
ExternalLocation location;
if (!isData) {
location = em.addExtFunction(rplName, symbol.getNameAsString(), null, SourceType.IMPORTED);
} else {
location = em.addExtLocation(rplName, symbol.getNameAsString(), null, SourceType.IMPORTED);
}

// We need this to have working references. (=> clicking on Imports, Show
// Referenences to.. is working)
// Setting the RefType.INVALID works for some reason!
// If the set it to DATA, everything is treated like DATA, and if we use
// something like "UNCONDITIONAL_CALL" for functions
// then decompiler doesn't get the right function names anymore.
program.getReferenceManager().addExternalReference(addr, 1, location, SourceType.USER_DEFINED,
RefType.INVALID);

// Add a comment to easily see from which rpl the function is coming.
program.getListing().setComment(addr, 0, rplName + "::" + symbol.getNameAsString());
}
}
Expand Down

0 comments on commit b37a5e6

Please sign in to comment.