Skip to content

Commit

Permalink
Merge pull request #6027 from rubnogueira/data-source-processor-jython
Browse files Browse the repository at this point in the history
Add DataSourceProcessor Jython support
  • Loading branch information
eugene7646 committed Sep 20, 2022
2 parents a1258c8 + 230848a commit 577bfd4
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2018 Basis Technology Corp.
* Copyright 2011-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.python.JythonModuleLoader;

/**
* visual component for the first panel of add image wizard. Allows the user to
Expand Down Expand Up @@ -76,6 +77,14 @@ private void discoverDataSourceProcessors() {
logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
}
}

for (DataSourceProcessor dsProcessor : JythonModuleLoader.getDataSourceProcessorModules()) {
if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
} else {
logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2018 Basis Technology Corp.
* Copyright 2011-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -42,6 +42,7 @@
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datasourceprocessors.RawDSProcessor;
import org.sleuthkit.autopsy.logicalimager.dsp.LogicalImagerDSProcessor;
import org.sleuthkit.autopsy.python.JythonModuleLoader;

/**
* Panel which displays the available DataSourceProcessors and allows selection
Expand Down Expand Up @@ -196,6 +197,15 @@ private List<String> getListOfDsps() {
logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
}
}

for (DataSourceProcessor dsProcessor : JythonModuleLoader.getDataSourceProcessorModules()) {
if (!datasourceProcessorsMap.containsKey(dsProcessor.getDataSourceType())) {
datasourceProcessorsMap.put(dsProcessor.getDataSourceType(), dsProcessor);
} else {
logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS
}
}

dspList.add(ImageDSProcessor.getType());
dspList.add(LocalDiskDSProcessor.getType());
dspList.add(LocalFilesDSProcessor.getType());
Expand Down
1 change: 1 addition & 0 deletions Core/src/org/sleuthkit/autopsy/core/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ private static void preloadJython() {
try {
JythonModuleLoader.getIngestModuleFactories();
JythonModuleLoader.getGeneralReportModules();
JythonModuleLoader.getDataSourceProcessorModules();
} catch (Exception ex) {
// This is a firewall exception to ensure that any possible exception caused
// by this initial load of the Jython modules are caught and logged.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2014-2022 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* 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.
*/
package org.sleuthkit.autopsy.datasourceprocessors;

import javax.swing.JPanel;

import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorCallback;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor;

import org.sleuthkit.datamodel.Host;

/**
* An adapter that provides no-op implementations of various DataSourceProcessor
* methods.
*/

public abstract class DataSourceProcessorAdapter implements DataSourceProcessor {
@Override
public abstract String getDataSourceType();

@Override
public JPanel getPanel() {
return null;
}

@Override
public boolean isPanelValid() {
return false;
}

@Override
public void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
}
}
31 changes: 30 additions & 1 deletion Core/src/org/sleuthkit/autopsy/python/JythonModuleLoader.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2014 Basis Technology Corp.
* Copyright 2014-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,6 +41,7 @@
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.ingest.IngestModuleFactory;
import org.sleuthkit.autopsy.report.GeneralReportModule;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Comparator;
Expand Down Expand Up @@ -72,6 +73,17 @@ public static synchronized List<IngestModuleFactory> getIngestModuleFactories()
public static synchronized List<GeneralReportModule> getGeneralReportModules() {
return getInterfaceImplementations(new GeneralReportModuleDefFilter(), GeneralReportModule.class);
}

/**
* Get data source processors modules implemented using Jython.
*
* @return A list of objects that implement the DataSourceProcessor
* interface.
*/
public static synchronized List<DataSourceProcessor> getDataSourceProcessorModules() {
return getInterfaceImplementations(new DataSourceProcessorDefFilter(), DataSourceProcessor.class);
}

@Messages({"JythonModuleLoader.pythonInterpreterError.title=Python Modules",
"JythonModuleLoader.pythonInterpreterError.msg=Failed to load python modules, See log for more details"})
private static <T> List<T> getInterfaceImplementations(LineFilter filter, Class<T> interfaceClass) {
Expand Down Expand Up @@ -169,6 +181,9 @@ private static interface LineFilter {
boolean accept(String line);
}

/**
* Filter IngestModule interface implementations
*/
private static class IngestModuleFactoryDefFilter implements LineFilter {

@Override
Expand All @@ -177,11 +192,25 @@ public boolean accept(String line) {
}
}

/**
* Filter GeneralReportModule interface implementations
*/
private static class GeneralReportModuleDefFilter implements LineFilter {

@Override
public boolean accept(String line) {
return (line.contains("GeneralReportModuleAdapter") || line.contains("GeneralReportModule")); //NON-NLS
}
}

/**
* Filter DataSourceProcessor interface implementations
*/
private static class DataSourceProcessorDefFilter implements LineFilter {

@Override
public boolean accept(String line) {
return (line.contains("DataSourceProcessorAdapter") || line.contains("DataSourceProcessor")); //NON-NLS
}
}
}

0 comments on commit 577bfd4

Please sign in to comment.