Skip to content

Commit

Permalink
Bug fixes, update for Ghidra 10.4/11.x
Browse files Browse the repository at this point in the history
closes #2, closes #3, closes #4, closes #5, closes #6;

Fixes an out-of-bounds error when attempting to load a DRCOV file with an unknown module ID.

The code should now build for Ghidra versions 10.4 and 11.x.
  • Loading branch information
aus10pv committed Mar 27, 2024
1 parent 30e4efa commit 551f4c0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# Root directory for doing Ghidra work (building, etc.)
# Root directory for doing Ghidra work (building, etc.)
root: ["/tmp/ghidra"]
# Ghidra build version(s)
version: [10.3]
version: ["10.4", "11.0.2"]
include:
- version: 10.3
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.3_build"
filename: "ghidra_10.3_PUBLIC_20230510.zip"
directory: "ghidra_10.3_PUBLIC"
- version: "10.4"
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.4_build"
filename: "ghidra_10.4_PUBLIC_20230928.zip"
directory: "ghidra_10.4_PUBLIC"
- version: "11.0.2"
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.0.2_build"
filename: "ghidra_11.0.2_PUBLIC_20240326.zip"
directory: "ghidra_11.0.2_PUBLIC"

steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ jobs:
# Repository name ("Cartographer")
name: ["${{github.event.repository.name}}"]
# Ghidra build version(s)
version: [10.3]
version: ["10.4", "11.0.2"]
include:
- version: 10.3
release_url: https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.3_build
filename: ghidra_10.3_PUBLIC_20230510.zip
directory: ghidra_10.3_PUBLIC
- version: "10.4"
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.4_build"
filename: "ghidra_10.4_PUBLIC_20230928.zip"
directory: "ghidra_10.4_PUBLIC"
- version: "11.0.2"
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.0.2_build"
filename: "ghidra_11.0.2_PUBLIC_20240326.zip"
directory: "ghidra_11.0.2_PUBLIC"

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cartographer/CartographerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import ghidra.framework.options.OptionsChangeListener;
import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ComponentProviderAdapter;
import ghidra.framework.plugintool.util.OptionsService;
import docking.options.OptionsService;
import ghidra.util.*;
import ghidra.util.table.column.AbstractGColumnRenderer;
import ghidra.util.task.TaskMonitor;
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/cartographer/CoverageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ else if (headerLine.toLowerCase().startsWith("ezcov")) {

// Whoops!
catch (Exception e) {
throw new AssertionError(e.getMessage());
throw new AssertionError(e);
}
}

Expand Down Expand Up @@ -237,23 +237,29 @@ private void parseDrCovFile(RandomAccessFile reader) throws IOException {
if (isBinary) {
int offset = readInt(reader);
short size = readShort(reader);
short moduleId = readShort(reader);
int moduleId = readShort(reader) & 0xFFFF;

// Add the block to the module
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
// Make sure the module ID is valid
if(moduleId < numModules){
// Add the block to the module
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
}
}

// Read a text block
else {
line = reader.readLine();
match = Pattern.compile("module\\[\\s*(\\d+)\\]: 0x([0-9a-fA-F]+?),\\s*(\\d+)").matcher(line);
if (match.find()) {
short moduleId = Short.parseShort(match.group(1));
int moduleId = Integer.parseInt(match.group(1)) & 0xFFFF;
int offset = Integer.parseInt(match.group(2), 16);
short size = Short.parseShort(match.group(3));

// Add the block to the module
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
// Make sure the module ID is valid
if(moduleId < numModules){
// Add the block to the module
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
}
}
}
}
Expand Down Expand Up @@ -407,7 +413,7 @@ public DrCovModule(int moduleId, int parentId, int base, String name) {
* @param size Size of the block in bytes
* @param module Module ID
*/
private void addBlock(int offset, short size, short module) {
private void addBlock(int offset, short size, int module) {
BasicBlock basicBlock = new BasicBlock(offset, size, module);
this.getBasicBlocks().add(basicBlock);
}
Expand Down Expand Up @@ -444,7 +450,7 @@ private void addBlock(int offset, short size, String addressSpace) {
public class BasicBlock {
private int offset;
private short size;
private short moduleId;
private int moduleId;
private AddressSpace addressSpace;

/**
Expand All @@ -454,7 +460,7 @@ public class BasicBlock {
* @param size Size of the block in bytes
* @param moduleId Module ID
*/
public BasicBlock(int offset, short size, short moduleId) {
public BasicBlock(int offset, short size, int moduleId) {
this.offset = offset;
this.size = size;
this.moduleId = moduleId;
Expand Down

0 comments on commit 551f4c0

Please sign in to comment.