Skip to content

Commit

Permalink
Extend Ghidra exporter to include data references
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-hunhoff committed Mar 20, 2024
1 parent c55f264 commit 8a96cdc
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public BinExport2Builder setPrependNamespace(boolean isPrepended) {
return this;
}

private Address getAddressFromLong(long offset) {
return program.getAddressFactory().getDefaultAddressSpace().getAddress(offset);
}

private long getMappedAddress(Address address) {
return address.getOffset() - addressOffset;
}
Expand Down Expand Up @@ -407,6 +411,23 @@ private void buildCallGraph() throws CancelledException {
}
}

private void buildDataReferences(Map<Long, Integer> instructionIndices) {
monitor.setMessage("Exporting data references");
monitor.setIndeterminate(true);

for (Map.Entry<Long, Integer> insnIndex : instructionIndices.entrySet()) {
Address addr = getAddressFromLong(insnIndex.getKey());
for (Reference ref : program.getReferenceManager().getReferencesFrom(addr)) {
if (ref.isMemoryReference() && ref.getReferenceType().isData()) {
builder
.addDataReferenceBuilder()
.setInstructionIndex(insnIndex.getValue())
.setAddress(ref.getToAddress().getOffset());
}
}
}
}

private void buildSections() {
monitor.setMessage("Exporting sections");
monitor.setIndeterminate(false);
Expand Down Expand Up @@ -532,7 +553,7 @@ public BinExport2 build(TaskMonitor taskMonitor) throws CancelledException {
// TODO(cblichmann): Implement these:
// buildComments()
// buildStrings();
// buildDataReferences()
buildDataReferences(instructionIndices);
monitor.setMessage("Exporting flow graphs");
buildFlowGraphs(basicBlockIndices);
monitor.setMessage("Exporting call graph");
Expand Down

0 comments on commit 8a96cdc

Please sign in to comment.