Skip to content

Commit

Permalink
Make module name matching more user friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 15, 2022
1 parent 19c09a4 commit 364a043
Show file tree
Hide file tree
Showing 23 changed files with 400 additions and 348 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/build_on_tag_push.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Ghidra Extension Build
name: Ghidra Extension Publish

env:
ghidra-url: https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.1.5_build/ghidra_10.1.5_PUBLIC_20220726.zip
ghidra-zip-filename: ghidra_10.1.5_PUBLIC_20220726.zip
ghidra-directory: ghidra_10.1.5_PUBLIC
ghidra-url: https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_10.2.1_build/ghidra_10.2.1_PUBLIC_20221110.zip
ghidra-zip-filename: ghidra_10.2.1_PUBLIC_20221110.zip
ghidra-directory: ghidra_10.2.1_PUBLIC

on:
push:
Expand Down Expand Up @@ -33,11 +33,14 @@ jobs:
- name: Build
shell: bash
run: |
pwd
sudo apt-get update
sudo apt-get install -y openjdk-17-jdk-headless
sudo update-java-alternatives -s java-1.17.0-openjdk-amd64
unzip -qq ${{ steps.download-ghidra.outputs.file-path }} -d /opt
rm -v ${{ env.ghidra-zip-filename }}
cd lightkeeper
gradle -PGHIDRA_INSTALL_DIR=/opt/${{ env.ghidra-directory }}
java --version
gradle -Dorg.gradle.java.home=/usr/lib/jvm/java-1.17.0-openjdk-amd64 -PGHIDRA_INSTALL_DIR=/opt/${{ env.ghidra-directory }}
mv -v dist/*.zip ${{ github.workspace }}/lightkeeper-${{ steps.get_version.outputs.VERSION }}.zip
- name: Create Release
Expand Down
504 changes: 272 additions & 232 deletions lightkeeper/.classpath

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lightkeeper/.project
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<link>
<name>Ghidra</name>
<type>2</type>
<location>/opt/ghidra_10.1.5_PUBLIC</location>
<location>/opt/ghidra_10.2.1_PUBLIC</location>
</link>
</linkedResources>
</projectDescription>
2 changes: 2 additions & 0 deletions lightkeeper/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
6 changes: 3 additions & 3 deletions lightkeeper/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
Expand Down Expand Up @@ -44,4 +44,4 @@ org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=17
65 changes: 30 additions & 35 deletions lightkeeper/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Builds a Ghidra Extension for a given Ghidra installation.
//
// An absolute path to the Ghidra installation directory must be supplied either by setting the
Expand All @@ -14,41 +29,6 @@
// application.gradle.version property in <GHIDRA_INSTALL_DIR>/Ghidra/application.properties
// for the correction version of Gradle to use for the Ghidra installation you specify.


plugins {
id 'java'

// Where this plugin (or it's many dependencies) are not available then use git-info.gradle
id 'net.nemerosa.versioning' version '2.13.2'
}

versioning {
gitRepoRootDir = '../'
}

def builtBy = ""
if (System.env.GITHUB_ACTION) {
builtBy = "GitHub Action"
}

jar {
manifest {
attributes(
'Built-By' : "$builtBy",
'Implementation-Version' : "$versioning.info.lastTag-$versioning.info.build",
'Git-Branch' : "$versioning.info.branch",
'Git-Tag' : "$versioning.info.tag",
'Git-Last-Tag' : "$versioning.info.lastTag",
'Git-Dirty' : "$versioning.info.dirty",
'Git-Tag-Major' : "$versioning.info.versionNumber.major",
'Git-Tag-Minor' : "$versioning.info.versionNumber.minor",
'Git-Tag-Patch' : "$versioning.info.versionNumber.patch",
'Git-Commit-Hash' : "$versioning.info.commit",
'Git-Commit-Hash-Short' : "$versioning.info.build",
)
}
}

//----------------------START "DO NOT MODIFY" SECTION------------------------------
def ghidraInstallDir

Expand All @@ -66,3 +46,18 @@ else {
throw new GradleException("GHIDRA_INSTALL_DIR is not defined!")
}
//----------------------END "DO NOT MODIFY" SECTION-------------------------------

repositories {
// Declare dependency repositories here. This is not needed if dependencies are manually
// dropped into the lib/ directory.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html for more info.
// Ex: mavenCentral()
}

dependencies {
// Any external dependencies added here will automatically be copied to the lib/ directory when
// this extension is built.
}

// Exclude additional files from the built extension
// Ex: buildExtension.exclude '.idea/**'
2 changes: 1 addition & 1 deletion lightkeeper/extension.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=@extname@
description=Plugin for visualization of DynamoRio coverage data.
description=The extension description can be customized by editing the extension.properties file.
author=
createdOn=
version=@extversion@
14 changes: 0 additions & 14 deletions lightkeeper/git-info.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class LightKeeperPlugin extends ProgramPlugin {
protected FlatProgramAPI api;

public LightKeeperPlugin(PluginTool tool) {
super(tool, true, true);
super(tool);
coverageModel = new CoverageModel(this);
tableModel = new CoverageTableModel(this, coverageModel);
instructionModel = new CoverageInstructionModel(this, coverageModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void importCoverage(TaskMonitor monitor, List<File> files) throws Cancell
monitor.setProgress(0);

var dataFile = new DynamoRioFile(file);

dataFile.addListener(this);
dataFile.read(monitor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import lightkeeper.model.ICoverageModelListener;
import lightkeeper.model.instruction.CoverageInstructionModel;

public class DisassemblyController implements ICoverageModelListener{
public class DisassemblyController implements ICoverageModelListener {
protected LightKeeperPlugin plugin;
protected CoverageInstructionModel model;

Expand All @@ -30,29 +30,29 @@ public DisassemblyController(LightKeeperPlugin plugin, CoverageInstructionModel
}

@Override
public void modelChanged(TaskMonitor monitor) throws CancelledException {
public void modelChanged(TaskMonitor monitor) throws CancelledException {

DecompilerProvider dprov = (DecompilerProvider) plugin.getTool().getComponentProvider("Decompiler");
if (dprov != null) {
DecompilerActionContext context = (DecompilerActionContext) dprov.getActionContext(null);
if (context != null) {
DecompilerPanel dpanel = context.getDecompilerPanel();
var controller = dpanel.getLayoutModel();
controller.addLayoutModelListener(new LayoutModelListener() {
@Override
public void modelSizeChanged(IndexMapper indexMapper) {
updateCoverageTask(dpanel);
}
@Override
public void dataChanged(BigInteger start, BigInteger end) {
updateCoverageTask(dpanel);
}
});
updateCoverage(monitor, dpanel);
}
}
DecompilerProvider dprov = (DecompilerProvider) plugin.getTool().getComponentProvider("Decompiler");
if (dprov != null) {
DecompilerActionContext context = (DecompilerActionContext) dprov.getActionContext(null);
if (context != null) {
DecompilerPanel dpanel = context.getDecompilerPanel();
var controller = dpanel.getLayoutModel();
controller.addLayoutModelListener(new LayoutModelListener() {

@Override
public void modelSizeChanged(IndexMapper indexMapper) {
updateCoverageTask(dpanel);
}

@Override
public void dataChanged(BigInteger start, BigInteger end) {
updateCoverageTask(dpanel);
}
});
updateCoverage(monitor, dpanel);
}
}
}

public void updateCoverage(TaskMonitor monitor, DecompilerPanel dpanel) throws CancelledException {
Expand All @@ -63,17 +63,14 @@ public void updateCoverage(TaskMonitor monitor, DecompilerPanel dpanel) throws C

var program = api.getCurrentProgram();

for (ClangLine line: dpanel.getLines())
{
for (ClangToken token: line.getAllTokens())
{
for (ClangLine line : dpanel.getLines()) {
for (ClangToken token : line.getAllTokens()) {
monitor.checkCanceled();
var address = DecompilerUtils.getClosestAddress(program, token);
if (address == null) {
continue;
}
for (AddressRange range: model.getModelData())
{
for (AddressRange range : model.getModelData()) {
monitor.checkCanceled();
if (!range.contains(address)) {
continue;
Expand All @@ -86,7 +83,7 @@ public void updateCoverage(TaskMonitor monitor, DecompilerPanel dpanel) throws C
}

public void updateCoverageTask(DecompilerPanel dpanel) {
Task task = new Task("Clear Coverage Data", true, true, true){
Task task = new Task("Clear Coverage Data", true, true, true) {
@Override
public void run(TaskMonitor monitor) throws CancelledException {
updateCoverage(monitor, dpanel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public interface IEventListener {
void addMessage(String message);

void addErrorMessage(String message);

void addException(Exception exc);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public BinaryLineReader(CountedByteProvider provider) {
public String readLine() throws IOException {
var buffer = new StringBuilder();
while (true) {
var c = (char)readNextByte();
var c = (char) readNextByte();
if (isLineEnd(c)) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public InputStream getInputStream(long index) throws IOException {

@Override
public String getName() {
return "InputStreamByteProvider Index=0x" + Long.toHexString(currentIndex) + " Length=0x" +
Long.toHexString(length);
return "InputStreamByteProvider Index=0x" + Long.toHexString(currentIndex) + " Length=0x"
+ Long.toHexString(length);
}

@Override
Expand All @@ -69,8 +69,7 @@ public boolean isValidIndex(long index) {
public byte readByte(long index) throws IOException {
if (index < currentIndex) {
throw new IOException("Attempted to read byte that was already read.");
}
else if (index > currentIndex) {
} else if (index > currentIndex) {
currentIndex += inputStream.skip(index - currentIndex);
if (currentIndex != index) {
throw new IOException("Not enough bytes were skipped.");
Expand All @@ -89,8 +88,7 @@ else if (index > currentIndex) {
public byte[] readBytes(long index, long len) throws IOException {
if (index < currentIndex) {
throw new IOException("Attempted to read bytes that were already read.");
}
else if (index > currentIndex) {
} else if (index > currentIndex) {
currentIndex += inputStream.skip(index - currentIndex);
if (currentIndex != index) {
throw new IOException("Not enough bytes were skipped.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void addException(Exception exc) {
listeners.forEach(l -> l.addException(exc));
}


public BlockEntry read() throws CancelledException, IOException {
monitor.checkCanceled();
var start = reader.readNextUnsignedInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class ModuleEntry {
protected long timeStamp;
protected String path;

public ModuleEntry(int id, int containingId, long start, long end, long entry, String checksum, long timeStamp, String path){
public ModuleEntry(int id, int containingId, long start, long end, long entry, String checksum, long timeStamp,
String path) {
this.id = id;
this.containingId = containingId;
this.start = start;
Expand All @@ -23,7 +24,8 @@ public ModuleEntry(int id, int containingId, long start, long end, long entry, S

@Override
public String toString() {
var str = String.format("id: %d, start: %x, end: %x, entry: %x, checksum: %s, timestamp: %x, path: %s", id, start, end, entry, checksum, timeStamp, path);
var str = String.format("id: %d, start: %x, end: %x, entry: %x, checksum: %s, timestamp: %x, path: %s", id,
start, end, entry, checksum, timeStamp, path);
return str;
}

Expand All @@ -42,7 +44,7 @@ public long getStart() {
public long getEnd() {
return end;
}

public String getChecksum() {
return this.checksum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void notifyUpdate(TaskMonitor monitor) throws CancelledException {
}
}

public abstract void load(T ranges);
public abstract void load(T ranges) throws IOException;

public abstract void update(TaskMonitor monitor) throws CancelledException, IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;

public interface ICoverageModelListener extends EventListener{
void modelChanged(TaskMonitor monitor) throws CancelledException;
public interface ICoverageModelListener extends EventListener {
void modelChanged(TaskMonitor monitor) throws CancelledException;
}
Loading

0 comments on commit 364a043

Please sign in to comment.