Skip to content

Ghidra is a software reverse engineering (SRE) framework

speed up bundle status load, fix empty source dir handling

Jason P. Leasure89e0e617b246
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java
index 4f8b98d4fa..a0fd5581d5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusModel.java
@@ -199,7 +199,7 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {
}
});
- fireTableDataChanged();
+ // fireTableDataChanged(); // this is done by the addNewPaths during restoreState
}
@Override
@@ -226,21 +226,17 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {
if (loc != null) {
loc2status.put(loc, path);
}
-
- int index = statuses.size();
statuses.add(path);
- fireTableRowsInserted(index, index);
}
+ /**
+ * add new status and fire a table udpate
+ */
private BundleStatus addNewStatus(ResourceFile path, boolean enabled, boolean readonly) {
BundleStatus p = new BundleStatus(path, enabled, readonly);
+ int index = statuses.size();
addStatus(p);
- return p;
- }
-
- private BundleStatus addNewStatus(String path, boolean enabled, boolean readonly) {
- BundleStatus p = new BundleStatus(path, enabled, readonly);
- addStatus(p);
+ fireTableRowsInserted(index, index);
return p;
}
@@ -391,7 +387,7 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {
* @param path the path to insert
*/
public void insertPathForTesting(String path) {
- addNewStatus(path, true, false);
+ addNewStatus(new ResourceFile(path), true, false);
}
private ArrayList<BundleStatusListener> listeners = new ArrayList<>();
@@ -455,14 +451,15 @@ public class BundleStatusModel extends AbstractSortedTableModel<BundleStatus> {
BundleStatus currentStatus = getStatus(pathArr[i], currentPaths);
if (currentStatus != null) {
currentPaths.remove(currentStatus);
- addNewStatus(pathArr[i], enableArr[i], readonlyArr[i]);
+ addStatus(new BundleStatus(pathArr[i], enableArr[i], readonlyArr[i]));
}
else if (!readonlyArr[i]) {
// skip read-only statuses which are not present in the current config
// This is needed to thin-out old default entries
- addNewStatus(pathArr[i], enableArr[i], readonlyArr[i]);
+ addStatus(new BundleStatus(pathArr[i], enableArr[i], readonlyArr[i]));
}
}
+ fireTableDataChanged();
fireBundlesChanged();
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
index a7a70d8688..5e797ce92a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
@@ -89,26 +89,21 @@ public class GhidraSourceBundle implements GhidraBundle {
}
}
- public ResourceFile getSourceDir() {
+ ResourceFile getSourceDir() {
return sourceDir;
}
- public Path getBinDir() {
+ Path getBinDir() {
return binDir;
}
- @Override
- public Bundle install() throws GhidraBundleException {
- return bundleHost.installFromLoc(getBundleLoc());
- }
-
- public void buildError(ResourceFile rf, String err) {
+ void buildError(ResourceFile rf, String err) {
BuildFailure f = buildErrors.computeIfAbsent(rf, x -> new BundleHost.BuildFailure());
f.when = rf.lastModified();
f.message.append(err);
}
- public String getPreviousBuildErrors() {
+ private String getPreviousBuildErrors() {
return buildErrors.values().stream().map(e -> e.message.toString()).collect(
Collectors.joining());
}
@@ -144,7 +139,7 @@ public class GhidraSourceBundle implements GhidraBundle {
}
}
- public List<BundleRequirement> getAllReqs() {
+ List<BundleRequirement> getAllReqs() {
Map<String, BundleRequirement> dedupedReqs = new HashMap<>();
buildReqs.values().stream().flatMap(List::stream).forEach(
r -> dedupedReqs.putIfAbsent(r.toString(), r));
@@ -161,7 +156,7 @@ public class GhidraSourceBundle implements GhidraBundle {
* @throws IOException while accessing manifest file
* @throws OSGiException while parsing imports
*/
- public void updateFromFilesystem(PrintWriter writer) throws IOException, OSGiException {
+ void updateFromFilesystem(PrintWriter writer) throws IOException, OSGiException {
// look for new source files
newSources.clear();
oldBin.clear();
@@ -202,18 +197,18 @@ public class GhidraSourceBundle implements GhidraBundle {
}
}
- public void deleteOldBinaries() throws IOException {
+ private void deleteOldBinaries() throws IOException {
for (Path bf : oldBin) {
Files.delete(bf);
}
// oldBin.clear();
}
- public int getFailingSourcesCount() {
+ int getFailingSourcesCount() {
return buildErrors.size();
}
- public int getNewSourcesCount() {
+ int getNewSourcesCount() {
return newSources.size();
}
@@ -221,27 +216,27 @@ public class GhidraSourceBundle implements GhidraBundle {
return newSources;
}
- public boolean newManifestFile() {
+ boolean newManifestFile() {
return foundNewManifest;
}
long lastCompileAttempt;
- public void compileAttempted() {
+ void compileAttempted() {
lastCompileAttempt = System.currentTimeMillis();
}
- public long getLastCompileAttempt() {
+ long getLastCompileAttempt() {
return lastCompileAttempt;
}
String summary = "";
- public void setSummary(String summary) {
+ void setSummary(String summary) {
this.summary = summary;
}
- public void appendSummary(String s) {
+ void appendSummary(String s) {
if (!summary.isEmpty()) {
summary += ", " + s;
}
@@ -255,11 +250,6 @@ public class GhidraSourceBundle implements GhidraBundle {
return summary;
}
- @Override
- public Bundle getBundle() throws GhidraBundleException {
- return bundleHost.getBundle(getBundleLoc());
- }
-
@Override
public String getBundleLoc() {
return bundleLoc;
@@ -297,6 +287,11 @@ public class GhidraSourceBundle implements GhidraBundle {
needsCompile = true;
}
+ // finally, we should be able to handle empty directories
+ if (!binDir.toFile().exists()) {
+ needsCompile = true;
+ }
+
if (needsCompile) {
writer.printf("%d new files, %d skipped, %s\n", newSourcecount, failing,
newManifestFile() ? ", new manifest" : "");
@@ -321,4 +316,15 @@ public class GhidraSourceBundle implements GhidraBundle {
}
return false;
}
+
+ @Override
+ public Bundle install() throws GhidraBundleException {
+ return bundleHost.installFromLoc(getBundleLoc());
+ }
+
+ @Override
+ public Bundle getBundle() throws GhidraBundleException {
+ return bundleHost.getBundle(getBundleLoc());
+ }
+
}