Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-990 - Scripting - fixed incorrect parsing of certification header for python scripts

dragonmachere3b787a5243b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptProvider.java
index 6bef0f076a..8791fbf2bb 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptProvider.java
@@ -81,6 +81,9 @@ public abstract class GhidraScriptProvider
* @param sourceFile the source file
* @param writer the print writer to write warning/error messages
* @return a GhidraScript instance for the specified source file
+ * @throws ClassNotFoundException if the script class cannot be found
+ * @throws InstantiationException if the construction of the script fails for some reason
+ * @throws IllegalAccessException if the class constructor is not accessible
*/
public abstract GhidraScript getScriptInstance(ResourceFile sourceFile, PrintWriter writer)
throws ClassNotFoundException, InstantiationException, IllegalAccessException;
@@ -168,8 +171,7 @@ public abstract class GhidraScriptProvider
}
/**
- * Return the start of certification header line if this file type is
- * subject to certification.
+ * Return the start of certification header line if this file type is subject to certification.
* @return start of certification header or null if not supported
*/
protected String getCertifyHeaderStart() {
@@ -177,21 +179,19 @@ public abstract class GhidraScriptProvider
}
/**
- * Return the prefix for each certification header bofy line if
- * this file is subject to certification
- * @return certification heaber body prefix or null if not supported
+ * Return the prefix for each certification header body line if this file is subject to
+ * certification.
+ * @return certification header body prefix or null if not supported
*/
protected String getCertificationBodyPrefix() {
return null;
}
/**
- * Return the end of certification header line if this file type is
- * subject to certification.
+ * Return the end of certification header line if this file type is subject to certification.
* @return end of certification header or null if not supported
*/
protected String getCertifyHeaderEnd() {
return null;
}
-
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/JavaScriptProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/JavaScriptProvider.java
index 1a433dd2cc..5c1e34d5c2 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/JavaScriptProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/JavaScriptProvider.java
@@ -198,6 +198,11 @@ public class JavaScriptProvider extends GhidraScriptProvider {
return "*/";
}
+ @Override
+ protected String getCertificationBodyPrefix() {
+ return "*";
+ }
+
/**
*
* Fix script name for search in script directories, such as Java package parts in the name and inner class names.
diff --git a/Ghidra/Features/Python/src/main/java/ghidra/python/PythonScriptProvider.java b/Ghidra/Features/Python/src/main/java/ghidra/python/PythonScriptProvider.java
index fe49b67279..090e63b8f3 100644
--- a/Ghidra/Features/Python/src/main/java/ghidra/python/PythonScriptProvider.java
+++ b/Ghidra/Features/Python/src/main/java/ghidra/python/PythonScriptProvider.java
@@ -61,6 +61,21 @@ public class PythonScriptProvider extends GhidraScriptProvider {
return "#";
}
+ @Override
+ protected String getCertifyHeaderStart() {
+ return "## ###";
+ }
+
+ @Override
+ protected String getCertificationBodyPrefix() {
+ return "#";
+ }
+
+ @Override
+ protected String getCertifyHeaderEnd() {
+ return "##";
+ }
+
@Override
public String getDescription() {
return "Python";
diff --git a/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonScriptInfoTest.java b/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonScriptInfoTest.java
index f960a16b67..ca16891de0 100644
--- a/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonScriptInfoTest.java
+++ b/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonScriptInfoTest.java
@@ -137,15 +137,15 @@ public class PythonScriptInfoTest extends AbstractGhidraHeadedIntegrationTest {
try {
//@formatter:off
scriptFile = createTempPyScriptFileWithLines(
- "## ###" +
- "# IP: GHIDRA" +
- "# " +
- "# Some license text..." +
- "# you may not use this file except in compliance with the License." +
- "# " +
- "# blah blah blah" +
- "##" +
- "" +
+ "## ###",
+ "# IP: GHIDRA",
+ "# ",
+ "# Some license text...",
+ "# you may not use this file except in compliance with the License.",
+ "# ",
+ "# blah blah blah",
+ "##",
+ "",
"'''",
"This is a test block comment. It will be ignored.",
"@category NotTheRealCategory",