Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6890 deprecate Recognizer module / service.

dev74736839f2bae2332b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/Recognizer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/Recognizer.java
index 6bdd6d03d2..f9e155427c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/Recognizer.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/Recognizer.java
@@ -4,9 +4,9 @@
* 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.
@@ -22,6 +22,7 @@ import ghidra.util.classfinder.ExtensionPoint;
* the ClassSearcher will not find them.
*
*/
+@Deprecated(forRemoval = true, since = "12.3")
public interface Recognizer extends ExtensionPoint {
/**
@@ -31,7 +32,8 @@ public interface Recognizer extends ExtensionPoint {
* @return the maximum number of bytes needed to send to this recognizer in
* the recognize(...) method
*/
- public int numberOfBytesRequired();
+ @Deprecated(forRemoval = true, since = "12.3")
+ public int numberOfBytesRequired();
/**
* Ask the recognizer to recognize some bytes. Return a description String
@@ -43,7 +45,8 @@ public interface Recognizer extends ExtensionPoint {
* @return a String description of the recognition, or null if it is not
* recognized
*/
- public String recognize(byte[] bytes);
+ @Deprecated(forRemoval = true, since = "12.3")
+ public String recognize(byte[] bytes);
/**
* Return the recognizer priority; for instance, a GZIP/TAR recognizer
@@ -55,5 +58,6 @@ public interface Recognizer extends ExtensionPoint {
*
* @return the recognizer priority
*/
- public int getPriority();
+ @Deprecated(forRemoval = true, since = "12.3")
+ public int getPriority();
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/RecognizerService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/RecognizerService.java
index 93937ae850..29d0730fdb 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/RecognizerService.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/recognizer/RecognizerService.java
@@ -15,10 +15,11 @@
*/
package ghidra.app.util.recognizer;
-import ghidra.util.classfinder.ClassSearcher;
-
import java.util.*;
+import ghidra.util.classfinder.ClassSearcher;
+
+@Deprecated(forRemoval = true, since = "12.3")
public class RecognizerService {
private static final Comparator<Recognizer> DESCENDING = new Comparator<Recognizer>() {
@Override
@@ -27,6 +28,7 @@ public class RecognizerService {
}
};
+ @Deprecated(forRemoval = true, since = "12.3")
public static List<Recognizer> getAllRecognizers() {
List<Recognizer> results = new ArrayList<Recognizer>();
List<Recognizer> allRecognizers = getAllRecognizersHelper();
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/ApkLoader.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/ApkLoader.java
index d4b03d1c5b..a3a7d59b1b 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/ApkLoader.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/app/util/opinion/ApkLoader.java
@@ -18,14 +18,13 @@ package ghidra.app.util.opinion;
import java.io.IOException;
import java.util.*;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.importer.MessageLog;
-import ghidra.app.util.recognizer.PkzipRecognizer;
-import ghidra.app.util.recognizer.Recognizer;
import ghidra.file.formats.android.dex.DexHeaderFactory;
import ghidra.file.formats.android.dex.format.DexConstants;
import ghidra.file.formats.android.dex.format.DexHeader;
@@ -124,9 +123,9 @@ public class ApkLoader extends DexLoader {
*/
private boolean isZip(ByteProvider provider) {
try {
- Recognizer recog = new PkzipRecognizer();
- byte[] bytes = provider.readBytes(0, recog.numberOfBytesRequired());
- return recog.recognize(bytes) != null;
+ final int MIN_BYTES_REQUIRED = 4;
+ byte[] bytes = provider.readBytes(0, MIN_BYTES_REQUIRED);
+ return ZipArchiveInputStream.matches(bytes, bytes.length);
}
catch (Exception e) {
//ignore
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystemFactory.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystemFactory.java
index e6d9833bab..249ec7079f 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystemFactory.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/tar/TarFileSystemFactory.java
@@ -23,12 +23,11 @@ import java.util.zip.GZIPInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarConstants;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
import org.tukaani.xz.XZ;
-import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
-import ghidra.app.util.recognizer.Bzip2Recognizer;
import ghidra.formats.gfilesystem.*;
import ghidra.formats.gfilesystem.factory.*;
import ghidra.util.Msg;
@@ -118,29 +117,21 @@ public class TarFileSystemFactory implements GFileSystemFactoryByteProvider<TarF
private static TarCompressors detectCompressor(ByteProvider bp) throws IOException {
- int magicBytes = readMagicShort(bp);
- switch (magicBytes) {
- case GZIPInputStream.GZIP_MAGIC:
- return TarCompressors.GZIP;
- case Bzip2Recognizer.MAGIC_BYTES:
- return TarCompressors.BZIP2;
+ final int BYTES_REQUIRED = XZ.HEADER_MAGIC.length; // this is longer than gzip or bzip's magic const
+ byte[] bytes = bp.readBytes(0, BYTES_REQUIRED);
+ if (GzipCompressorInputStream.matches(bytes, bytes.length)) {
+ return TarCompressors.GZIP;
}
-
- byte[] startBytes = bp.readBytes(0, XZ.HEADER_MAGIC.length);
- if (XZCompressorInputStream.matches(startBytes, startBytes.length)) {
+ else if (BZip2CompressorInputStream.matches(bytes, bytes.length)) {
+ return TarCompressors.BZIP2;
+ }
+ else if (XZCompressorInputStream.matches(bytes, bytes.length)) {
return TarCompressors.XZ;
}
return null;
}
- private static int readMagicShort(ByteProvider bp) throws IOException {
- BinaryReader br = new BinaryReader(bp, true /* LE */);
- int magicBytes = br.readUnsignedShort(0);
-
- return magicBytes;
- }
-
private static boolean hasTarExt(String filename) {
for (String ext : TAR_EXTS) {
if (filename.endsWith(ext)) {
diff --git a/Ghidra/Features/PyGhidra/src/main/py/tests/data/good_plugin/DummyTestRecognizer.java b/Ghidra/Features/PyGhidra/src/main/py/tests/data/good_plugin/DummyTestModuleInitializer.java
similarity index 74%
rename from Ghidra/Features/PyGhidra/src/main/py/tests/data/good_plugin/DummyTestRecognizer.java
rename to Ghidra/Features/PyGhidra/src/main/py/tests/data/good_plugin/DummyTestModuleInitializer.java
index 11930125b0..440aad4583 100644
--- a/Ghidra/Features/PyGhidra/src/main/py/tests/data/good_plugin/DummyTestRecognizer.java
+++ b/Ghidra/Features/PyGhidra/src/main/py/tests/data/good_plugin/DummyTestModuleInitializer.java
@@ -15,15 +15,15 @@
*/
package ghidra.pyghidra.test;
-import ghidra.app.util.recognizer.Recognizer;
+import ghidra.framework.ModuleInitializer;
/**
* Simple ExtensionPoint class for PyGhidra plugin test.
*
- * This can be any ExtensionPoint. Recognizer was chosen here
+ * This can be any ExtensionPoint. ModuleInitializer was chosen here
* because it has a small number of methods and hasn't changed in a long time.
*/
-public class DummyTestRecognizer implements Recognizer {
+public class DummyTestModuleInitializer implements ModuleInitializer {
// simple static field we can reach and check for a pytest
// normally this would be an interface implemented in Python
@@ -31,17 +31,13 @@ public class DummyTestRecognizer implements Recognizer {
public static boolean preLaunchInitialized = false;
@Override
- public int getPriority() {
- return 0;
- }
+ public String getName() {
+ return "Dummy";
+ }
@Override
- public int numberOfBytesRequired() {
- return 0;
- }
-
- @Override
- public String recognize(byte[] bytes) {
- return "";
+ public void run() {
+ // do nothing
}
+
}
diff --git a/Ghidra/Features/PyGhidra/src/main/py/tests/test_plugin.py b/Ghidra/Features/PyGhidra/src/main/py/tests/test_plugin.py
index e69c74aa6e..724f6973da 100644
--- a/Ghidra/Features/PyGhidra/src/main/py/tests/test_plugin.py
+++ b/Ghidra/Features/PyGhidra/src/main/py/tests/test_plugin.py
@@ -149,15 +149,15 @@ class TestValidPlugin(PluginTest):
@classmethod
def prelaunch(cls):
- DummyTestRecognizer = jpype.JClass("ghidra.pyghidra.test.DummyTestRecognizer")
- DummyTestRecognizer.preLaunchInitialized = True
+ DummyTestModuleInitializer = jpype.JClass("ghidra.pyghidra.test.DummyTestModuleInitializer")
+ DummyTestModuleInitializer.preLaunchInitialized = True
@classmethod
def test_extension_point(cls):
from ghidra.app.util.recognizer import Recognizer
from ghidra.util.classfinder import ClassSearcher
- DummyTestRecognizer = jpype.JClass("ghidra.pyghidra.test.DummyTestRecognizer")
- assert DummyTestRecognizer in ClassSearcher.getClasses(Recognizer)
+ DummyTestModuleInitializer = jpype.JClass("ghidra.pyghidra.test.DummyTestModuleInitializer")
+ assert DummyTestModuleInitializer in ClassSearcher.getClasses(ModuleInitializer)
class TestBadPlugin(PluginTest):
diff --git a/Ghidra/Features/Recognizers/README.md b/Ghidra/Features/Recognizers/README.md
index b784d88f8a..8808d92b8f 100644
--- a/Ghidra/Features/Recognizers/README.md
+++ b/Ghidra/Features/Recognizers/README.md
@@ -1 +1,3 @@
# Recognizers
+
+This module is deprecated and will be removed after 12.3
\ No newline at end of file