Skip to content

Commit

Permalink
Merge pull request #5589 from eugene7646/python_report_fix
Browse files Browse the repository at this point in the history
Python report fix (5959)
  • Loading branch information
rcordovano committed Jan 14, 2020
2 parents 731cd75 + 3d78507 commit a39bcf1
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.autopsy.modules.interestingitems.FilesSet;
import org.sleuthkit.autopsy.python.FactoryClassNameNormalizer;

/**
* Encapsulates a data source and the ingest module pipelines used to process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.modules.interestingitems.FilesSet;
import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager;
import org.sleuthkit.autopsy.python.FactoryClassNameNormalizer;

/**
* The settings for an ingest job.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.sleuthkit.autopsy.ingest;

import org.sleuthkit.autopsy.python.FactoryClassNameNormalizer;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.ingest;
package org.sleuthkit.autopsy.python;

import org.sleuthkit.autopsy.coreutils.Logger;

/**
* Used to strip Python IDs on factory class names.
*/
class FactoryClassNameNormalizer {
public class FactoryClassNameNormalizer {

private static final CharSequence pythonModuleSettingsPrefixCS = "org.python.proxies.".subSequence(0, "org.python.proxies.".length() - 1); //NON-NLS
private static final Logger logger = Logger.getLogger(FactoryClassNameNormalizer.class.getName());

static String normalize(String canonicalClassName) {
if (isPythonModuleSettingsFile(canonicalClassName)) {
public static String normalize(String canonicalClassName) {
if (isPythonClassName(canonicalClassName)) {
// Compiled Python modules have variable instance number as a part
// of their file name. This block of code gets rid of that variable
// instance number and helps maitains constant module name over
Expand All @@ -41,17 +41,17 @@ static String normalize(String canonicalClassName) {
}

/**
* Determines if the moduleSettingsFilePath is that of a serialized Jython
* Determines if the classNameToVerify is that of a serialized Jython
* instance. Serialized Jython instances (settings saved on the disk)
* contain "org.python.proxies." in their fileName based on the current
* implementation.
*
* @param moduleSettingsFilePath path to the module settings file.
* @param classNameToVerify class name to verify.
*
* @return True or false
*/
private static boolean isPythonModuleSettingsFile(String moduleSettingsFilePath) {
return moduleSettingsFilePath.contains(pythonModuleSettingsPrefixCS);
private static boolean isPythonClassName(String classNameToVerify) {
return classNameToVerify.contains(pythonModuleSettingsPrefixCS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.python.FactoryClassNameNormalizer;
import org.sleuthkit.autopsy.report.ReportProgressPanel;
import org.sleuthkit.autopsy.report.ReportProgressPanel.ReportStatus;
import org.sleuthkit.datamodel.AbstractFile;
Expand Down Expand Up @@ -119,12 +120,47 @@ public ReportGenerator(String configName, ReportProgressIndicator progressIndica
this.progressIndicator = panel.getProgressPanel();
this.configName = configName;
}

/**
* Generates the reports specified by the reporting configuration passed
* in via the constructor. Does lookup of all existing report modules.
*/
public void generateReports() {
// load all report modules
Map<String, ReportModule> modules = new HashMap<>();
for (TableReportModule module : ReportModuleLoader.getTableReportModules()) {
modules.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
}

for (GeneralReportModule module : ReportModuleLoader.getGeneralReportModules()) {
modules.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
}

for (FileReportModule module : ReportModuleLoader.getFileReportModules()) {
modules.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
}

// special case for PortableCaseReportModule
modules.put(FactoryClassNameNormalizer.normalize(PortableCaseReportModule.class.getCanonicalName()), new PortableCaseReportModule());

generateReports(modules);
}

/**
* Generates the reports specified by the reporting configuration passed in
* via the constructor.
* via the constructor.
*
* @param modules Map of report module objects to use. This is useful when we want to
* re-use the module instances or limit which reports are generated.
*/
public void generateReports() {
public void generateReports(Map<String, ReportModule> modules) {

if (modules == null || modules.isEmpty()) {
logger.log(Level.SEVERE, "No report modules found");
progressIndicator.updateStatusLabel("No report modules found. Exiting");
return;
}

ReportingConfig config = null;
try {
config = ReportingConfigLoader.loadConfig(configName);
Expand All @@ -141,23 +177,6 @@ public void generateReports() {
}

try {
// load all report modules
Map<String, ReportModule> modules = new HashMap<>();
for (TableReportModule module : ReportModuleLoader.getTableReportModules()) {
modules.put(module.getClass().getCanonicalName(), module);
}

for (GeneralReportModule module : ReportModuleLoader.getGeneralReportModules()) {
modules.put(module.getClass().getCanonicalName(), module);
}

for (FileReportModule module : ReportModuleLoader.getFileReportModules()) {
modules.put(module.getClass().getCanonicalName(), module);
}

// special case for PortableCaseReportModule
modules.put(PortableCaseReportModule.class.getCanonicalName(), new PortableCaseReportModule());

// generate reports for enabled modules
for (Map.Entry<String, ReportModuleConfig> entry : config.getModuleConfigs().entrySet()) {
ReportModuleConfig moduleConfig = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.python.FactoryClassNameNormalizer;

/**
* Display reports modules.
Expand Down Expand Up @@ -128,7 +129,7 @@ private void initModules() {
ReportModuleSettings settings = null;
if (moduleConfigs != null) {
// get configuration for this module
ReportModuleConfig config = moduleConfigs.get(module.getClass().getCanonicalName());
ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()));
if (config != null) {
// there is an existing configuration for this module
settings = config.getModuleSettings();
Expand Down Expand Up @@ -239,16 +240,24 @@ Map<String, ReportModuleConfig> getUpdatedModuleConfigs() {
for (ReportModule module : modules) {
// get updated module configuration
ReportModuleSettings settings = module.getConfiguration();
moduleConfigs.put(module.getClass().getCanonicalName(), new ReportModuleConfig(module, false, settings));
moduleConfigs.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), new ReportModuleConfig(module, false, settings));
}

// set "enabled" flag for the selected module
ReportModule mod = getSelectedModule();
ReportModuleConfig config = moduleConfigs.get(mod.getClass().getCanonicalName());
ReportModuleConfig config = moduleConfigs.get(FactoryClassNameNormalizer.normalize(mod.getClass().getCanonicalName()));
config.setEnabled(true);

return moduleConfigs;
}

Map<String, ReportModule> getReportModules() {
Map<String, ReportModule> modulesMap = new HashMap<>();
for (ReportModule module : modules) {
modulesMap.put(FactoryClassNameNormalizer.normalize(module.getClass().getCanonicalName()), module);
}
return modulesMap;
}

/**
* This method is called from within the constructor to initialize the form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.report.ReportModule;

@ActionID(category = "Tools", id = "org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
@ActionRegistration(displayName = "#CTL_ReportWizardAction", lazy = false)
Expand Down Expand Up @@ -101,9 +102,10 @@ public static void doReportWizard(String configName, boolean displayCaseSpecific
if (runReports) {
// generate reports in a separate thread
panel = new ReportGenerationPanel();
Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty("modules");
ReportGenerator generator = new ReportGenerator(configName, panel); //NON-NLS
ReportWorker worker = new ReportWorker(() -> {
generator.generateReports();
generator.generateReports(modules);
});
worker.execute();
generator.displayProgressPanel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;
import org.sleuthkit.autopsy.report.ReportModule;

class ReportWizardPanel1 implements WizardDescriptor.FinishablePanel<WizardDescriptor> {

Expand Down Expand Up @@ -110,6 +111,7 @@ public void readSettings(WizardDescriptor wiz) {
@Override
public void storeSettings(WizardDescriptor wiz) {
wiz.putProperty("moduleConfigs", getComponent().getUpdatedModuleConfigs()); //NON-NLS
wiz.putProperty("modules", getComponent().getReportModules()); //NON-NLS

// Store preferences that WizardIterator will use to determine what
// panels need to be shown
Expand Down

0 comments on commit a39bcf1

Please sign in to comment.