Skip to content

Commit

Permalink
Bugs fixed, category changed, better DRCOV support
Browse files Browse the repository at this point in the history
closes #7, closes #8, closes #9, closes #10, closes #11, closes #12;

Fixes a parsing issue when handling large base address values.

Fixes a coverage accuracy issue that stemmed from using a BasicBlockModel instead of a SimpleBlockModel.

Changed the category from DECOMPILER to ANALYSIS.

The code should now build for Ghidra 11.1.x.

Made the loadCoverageFile() function public and created a public function called processCoverageFile() to be used by other plugins, as suggested by @N-I-N-0.

Added support for DRCOV module versions 1, 2, 3, and 4.

Thanks to @datalocaltmp, @krisi0903, and @antoniovazquezblanco for valuable feedback.
  • Loading branch information
aus10pv committed Jul 11, 2024
1 parent 551f4c0 commit c8160d5
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 154 deletions.
80 changes: 46 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,66 @@ name: build

on:
push:
branches: [ "main" ]
branches: [ "*" ]
pull_request:
branches: [ "main" ]
branches: [ "*" ]
release:
types: [ published ]


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# Root directory for doing Ghidra work (building, etc.)
root: ["/tmp/ghidra"]
# Ghidra build version(s)
version: ["10.4", "11.0.2"]
include:
- 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"
version:
- "11.1.2"

steps:
- uses: actions/checkout@v3
- name: Clone Repository
uses: actions/checkout@v4

- name: Install Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"

- name: Download Ghidra
run: |
wget -P ${{matrix.root}} -q ${{matrix.release_url}}/${{matrix.filename}}
unzip -d ${{matrix.root}} -q ${{matrix.root}}/${{matrix.filename}}
- name: Install Gradle
uses: gradle/actions/setup-gradle@v3

- name: Setup Java
uses: actions/setup-java@v3
- name: Install Ghidra ${{matrix.version}}
uses: antoniovazquezblanco/setup-[email protected]
with:
java-version: 17
distribution: temurin
version: ${{matrix.version}}

- name: Build plugin via gradle
run: gradle -PGHIDRA_INSTALL_DIR=${{matrix.root}}/${{matrix.directory}} -PZIP_NAME_PREFIX=ghidra_${{matrix.version}}
run: gradle -PZIP_NAME_PREFIX=ghidra_${{matrix.version}}

# Uploading a ZIP file as an artifact creates a double-ZIP
- name: Fix artifact ZIP
run: unzip -d dist/${{matrix.version}} dist/*_${{matrix.version}}_*.zip
- name: Rename artifact ZIP
run: mv dist/*_${{matrix.version}}_*.zip dist/ghidra_${{matrix.version}}_${{github.event.repository.name}}.zip

# Upload the unzipped contents as the artifact to create a Ghidra-loadable ZIP file
- name: Upload artifact
uses: actions/upload-artifact@v3
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ghidra_${{matrix.version}}_Cartographer
path: dist/${{matrix.version}}/*
if-no-files-found: error
name: ghidra_${{matrix.version}}_${{github.event.repository.name}}
path: dist/*${{github.event.repository.name}}.zip

release:
permissions:
contents: write
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release' && github.event.action == 'published'

steps:
- name: Clone Repository
uses: actions/checkout@v4

- name: Download binaries
uses: actions/download-artifact@v4

- name: Upload release ZIP
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: gh release upload ${{github.event.release.tag_name}} *${{github.event.repository.name}}/*.zip
55 changes: 0 additions & 55 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/cartographer/CartographerModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public String getColumnName() {
@Override
public String getValue(TableRowObject rowObject, Settings settings, Object data,
ServiceProvider services) throws IllegalArgumentException {
return String.format("0x%08X", rowObject.getFunctionAddress().getUnsignedOffset());
return String.format("0x%08X", rowObject.getFunctionAddress().getUnsignedOffset());
}
}

Expand Down
88 changes: 53 additions & 35 deletions src/main/java/cartographer/CartographerPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
@PluginInfo(
status = PluginStatus.RELEASED,
packageName = MiscellaneousPluginPackage.NAME,
category = PluginCategoryNames.DECOMPILER,
category = PluginCategoryNames.ANALYSIS,
shortDescription = "Code coverage parser",
description = "Plugin for loading and processing code coverage data."
)
Expand Down Expand Up @@ -299,39 +299,10 @@ public void actionPerformed(ActionContext context) {
throw new AssertionError(e.getMessage());
}

// Only process if no errors were encountered
if (file.getStatusCode() != CoverageFile.STATUS.OK) {
Utils.showError(
file.getStatusCode().toString(),
file.getStatusMessage()
);
return;
// Attempt to process the code coverage file
if (!processCoverageFile(file)) {
return;
}

// Load the coverage file data
if (!loadCoverageFile(file)) {
return;
}

// Set the selected file for the provider
provider.setSelectedFile(file);

// Set to loaded
loaded = true;

// Reload the model
provider.setFileLoadedFlag();
provider.getModel().reload();

// Associate the model with the file
file.setModel(provider.getModel());

// Give the loaded file a unique ID
file.setId(loadedFiles.size());
file.setAlphaId(Utils.idToAlpha(loadedFiles.size()));

// Add the file data to the list of loaded files
loadedFiles.put(file.getId(), file);
});
}
};
Expand Down Expand Up @@ -502,7 +473,7 @@ public void colorizeListing(CoverageFile file) {
*
* @return True if successfully loaded coverage file, false if not
*/
private boolean loadCoverageFile(CoverageFile file) {
public boolean loadCoverageFile(CoverageFile file) {

// Clear out function map
file.clearCoverageFunctions();
Expand Down Expand Up @@ -553,7 +524,7 @@ private boolean loadCoverageFile(CoverageFile file) {
);

// Bail if no option was chosen
if (response == null) {
if (response == null) {
return false;
}

Expand Down Expand Up @@ -593,6 +564,53 @@ else if (file.getType().equals("ezcov")) {

return true;
}

/**
* Processes the given code coverage file.
*
* @param file Coverage file to process
*
* @return Whether or not the coverage file was successfully processed
*/
public boolean processCoverageFile(CoverageFile file) {

// Only process if no errors were encountered
if (file.getStatusCode() != CoverageFile.STATUS.OK) {
Utils.showError(
file.getStatusCode().toString(),
file.getStatusMessage()
);
return false;
}

// Load the coverage file data
if (!loadCoverageFile(file)) {
return false;
}

// Set the selected file for the provider
provider.setSelectedFile(file);

// Set to loaded
loaded = true;

// Reload the model
provider.setFileLoadedFlag();
provider.getModel().reload();

// Associate the model with the file
file.setModel(provider.getModel());

// Give the loaded file a unique ID
file.setId(loadedFiles.size());
file.setAlphaId(Utils.idToAlpha(loadedFiles.size()));

// Add the file data to the list of loaded files
loadedFiles.put(file.getId(), file);

// Successfully processed
return true;
}

/**
* Gets the provider for the plugin.
Expand Down
Loading

0 comments on commit c8160d5

Please sign in to comment.