Skip to content

Commit 551f4c0

Browse files
committed
Bug fixes, update for Ghidra 10.4/11.x
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.
1 parent 30e4efa commit 551f4c0

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

.github/workflows/build.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
# Root directory for doing Ghidra work (building, etc.)
14+
# Root directory for doing Ghidra work (building, etc.)
1515
root: ["/tmp/ghidra"]
1616
# Ghidra build version(s)
17-
version: [10.3]
17+
version: ["10.4", "11.0.2"]
1818
include:
19-
- version: 10.3
20-
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.3_build"
21-
filename: "ghidra_10.3_PUBLIC_20230510.zip"
22-
directory: "ghidra_10.3_PUBLIC"
19+
- version: "10.4"
20+
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.4_build"
21+
filename: "ghidra_10.4_PUBLIC_20230928.zip"
22+
directory: "ghidra_10.4_PUBLIC"
23+
- version: "11.0.2"
24+
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.0.2_build"
25+
filename: "ghidra_11.0.2_PUBLIC_20240326.zip"
26+
directory: "ghidra_11.0.2_PUBLIC"
2327

2428
steps:
2529
- uses: actions/checkout@v3

.github/workflows/release.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ jobs:
1818
# Repository name ("Cartographer")
1919
name: ["${{github.event.repository.name}}"]
2020
# Ghidra build version(s)
21-
version: [10.3]
21+
version: ["10.4", "11.0.2"]
2222
include:
23-
- version: 10.3
24-
release_url: https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.3_build
25-
filename: ghidra_10.3_PUBLIC_20230510.zip
26-
directory: ghidra_10.3_PUBLIC
23+
- version: "10.4"
24+
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.4_build"
25+
filename: "ghidra_10.4_PUBLIC_20230928.zip"
26+
directory: "ghidra_10.4_PUBLIC"
27+
- version: "11.0.2"
28+
release_url: "https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_11.0.2_build"
29+
filename: "ghidra_11.0.2_PUBLIC_20240326.zip"
30+
directory: "ghidra_11.0.2_PUBLIC"
2731

2832
steps:
2933
- uses: actions/checkout@v3

src/main/java/cartographer/CartographerProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import ghidra.framework.options.OptionsChangeListener;
3434
import ghidra.framework.options.ToolOptions;
3535
import ghidra.framework.plugintool.ComponentProviderAdapter;
36-
import ghidra.framework.plugintool.util.OptionsService;
36+
import docking.options.OptionsService;
3737
import ghidra.util.*;
3838
import ghidra.util.table.column.AbstractGColumnRenderer;
3939
import ghidra.util.task.TaskMonitor;

src/main/java/cartographer/CoverageFile.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ else if (headerLine.toLowerCase().startsWith("ezcov")) {
134134

135135
// Whoops!
136136
catch (Exception e) {
137-
throw new AssertionError(e.getMessage());
137+
throw new AssertionError(e);
138138
}
139139
}
140140

@@ -237,23 +237,29 @@ private void parseDrCovFile(RandomAccessFile reader) throws IOException {
237237
if (isBinary) {
238238
int offset = readInt(reader);
239239
short size = readShort(reader);
240-
short moduleId = readShort(reader);
240+
int moduleId = readShort(reader) & 0xFFFF;
241241

242-
// Add the block to the module
243-
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
242+
// Make sure the module ID is valid
243+
if(moduleId < numModules){
244+
// Add the block to the module
245+
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
246+
}
244247
}
245248

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

255-
// Add the block to the module
256-
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
258+
// Make sure the module ID is valid
259+
if(moduleId < numModules){
260+
// Add the block to the module
261+
drcovModules.get(moduleId).addBlock(offset, size, moduleId);
262+
}
257263
}
258264
}
259265
}
@@ -407,7 +413,7 @@ public DrCovModule(int moduleId, int parentId, int base, String name) {
407413
* @param size Size of the block in bytes
408414
* @param module Module ID
409415
*/
410-
private void addBlock(int offset, short size, short module) {
416+
private void addBlock(int offset, short size, int module) {
411417
BasicBlock basicBlock = new BasicBlock(offset, size, module);
412418
this.getBasicBlocks().add(basicBlock);
413419
}
@@ -444,7 +450,7 @@ private void addBlock(int offset, short size, String addressSpace) {
444450
public class BasicBlock {
445451
private int offset;
446452
private short size;
447-
private short moduleId;
453+
private int moduleId;
448454
private AddressSpace addressSpace;
449455

450456
/**
@@ -454,7 +460,7 @@ public class BasicBlock {
454460
* @param size Size of the block in bytes
455461
* @param moduleId Module ID
456462
*/
457-
public BasicBlock(int offset, short size, short moduleId) {
463+
public BasicBlock(int offset, short size, int moduleId) {
458464
this.offset = offset;
459465
this.size = size;
460466
this.moduleId = moduleId;

0 commit comments

Comments
 (0)