diff --git a/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java index 8a24bd7c9bdd846c2e1f0618c4b204b05f6cd30b..e4152604c0cbe16038a299041f7e64fc4846fdca 100755 --- a/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java @@ -49,8 +49,9 @@ * It does a stupid calculation of the number of null bytes in the beginning of the * file in order to show the basic flow. * - * Autopsy has been hard coded to ignore this module based on the name returned in - * getName(). Ensure that you change the module name when you use this as a template. + * Autopsy has been hard coded to ignore this module based on the it's package name. + * IngestModuleLoader will not load things from the org.sleuthkit.autopsy.examples package. + * Either change the package or the loading code to make this module actually run. */ public class SampleFileIngestModule extends org.sleuthkit.autopsy.ingest.IngestModuleAbstractFile { private int attrId = -1; @@ -70,12 +71,6 @@ public static synchronized SampleFileIngestModule getDefault() { } - @Override - public String getName() { - // @@@ CHANGE THIS IN A REAL MODULE -- AUTOPSY IGNORES MODULES WITH THIS NAME - return "SampleFileIngestIgnore"; - } - @Override public void init(IngestModuleInit initContext) { /* For this demo, we are going to make a private attribute to post our @@ -164,6 +159,11 @@ public void stop() { public String getVersion() { return "1.0"; } + + @Override + public String getName() { + return "SampleFileIngestModule"; + } @Override public String getDescription() { diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleLoader.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleLoader.java index df5eceaadf961029562748a25bd1fa2f5f956169..6597eadc9d7d28fbda56d7e38c1710b680932db4 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleLoader.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleLoader.java @@ -466,11 +466,13 @@ private Set<URL> getJarPaths(Collection<? extends ModuleInfo> moduleInfos) { @SuppressWarnings("unchecked") private void autodiscover() throws IngestModuleLoaderException { + // Use Lookup to find the other NBM modules. We'll later search them for ingest modules Collection<? extends ModuleInfo> moduleInfos = Lookup.getDefault().lookupAll(ModuleInfo.class); logger.log(Level.INFO, "Autodiscovery, found #platform modules: " + moduleInfos.size()); Set<URL> urls = getJarPaths(moduleInfos); - + ArrayList<Reflections> reflectionsSet = new ArrayList<>(); + for (final ModuleInfo moduleInfo : moduleInfos) { if (moduleInfo.isEnabled()) { String basePackageName = moduleInfo.getCodeNameBase(); @@ -489,104 +491,115 @@ private void autodiscover() throws IngestModuleLoaderException { cb.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(basePackageName))); cb.setUrls(urls); cb.setScanners(new SubTypesScanner(), new ResourcesScanner()); - Reflections reflections = new Reflections(cb); + reflectionsSet.add(new Reflections(cb)); + } + } + + /* This area is used to load the example modules. They are not found via lookup since they + * are in this NBM module. + * Uncomment this section to rum the examples. + */ + /* + ConfigurationBuilder cb = new ConfigurationBuilder(); + cb.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.sleuthkit.autopsy.examples"))); + cb.setUrls(urls); + cb.setScanners(new SubTypesScanner(), new ResourcesScanner()); + reflectionsSet.add(new Reflections(cb)); + */ + + for (Reflections reflections : reflectionsSet) { - Set<?> fileModules = reflections.getSubTypesOf(IngestModuleAbstractFile.class); - Iterator<?> it = fileModules.iterator(); - while (it.hasNext()) { - logger.log(Level.INFO, "Found file ingest module in: " + basePackageName + ": " + it.next().toString()); - } + Set<?> fileModules = reflections.getSubTypesOf(IngestModuleAbstractFile.class); + Iterator<?> it = fileModules.iterator(); + while (it.hasNext()) { + logger.log(Level.INFO, "Found file ingest module in: " + reflections.getClass().getSimpleName() + ": " + it.next().toString()); + } - Set<?> dataSourceModules = reflections.getSubTypesOf(IngestModuleDataSource.class); - it = dataSourceModules.iterator(); - while (it.hasNext()) { - logger.log(Level.INFO, "Found DataSource ingest module in: " + basePackageName + ": " + it.next().toString()); - } + Set<?> dataSourceModules = reflections.getSubTypesOf(IngestModuleDataSource.class); + it = dataSourceModules.iterator(); + while (it.hasNext()) { + logger.log(Level.INFO, "Found DataSource ingest module in: " + reflections.getClass().getSimpleName() + ": " + it.next().toString()); + } - //find out which modules to add - //TODO check which modules to remove (which modules were uninstalled) - boolean modulesChanged = false; + //find out which modules to add + //TODO check which modules to remove (which modules were uninstalled) + boolean modulesChanged = false; - it = fileModules.iterator(); - while (it.hasNext()) { - boolean exists = false; - Class<IngestModuleAbstractFile> foundClass = (Class<IngestModuleAbstractFile>) it.next(); + it = fileModules.iterator(); + while (it.hasNext()) { + boolean exists = false; + Class<IngestModuleAbstractFile> foundClass = (Class<IngestModuleAbstractFile>) it.next(); - for (IngestModuleLoader.XmlPipelineRaw rawP : pipelinesXML) { - if (!rawP.type.equals(IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.FILE_ANALYSIS.toString())) { - continue; //skip - } + for (IngestModuleLoader.XmlPipelineRaw rawP : pipelinesXML) { + if (!rawP.type.equals(IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.FILE_ANALYSIS.toString())) { + continue; //skip + } - for (IngestModuleLoader.XmlModuleRaw rawM : rawP.modules) { - //logger.log(Level.INFO, "CLASS NAME : " + foundClass.getName()); - if (foundClass.getName().equals(rawM.location)) { - exists = true; - break; - } - } - if (exists == true) { + for (IngestModuleLoader.XmlModuleRaw rawM : rawP.modules) { + //logger.log(Level.INFO, "CLASS NAME : " + foundClass.getName()); + if (foundClass.getName().equals(rawM.location)) { + exists = true; break; } } - - if (exists == false) { - logger.log(Level.INFO, "Discovered a new file module to load: " + foundClass.getName()); - //ADD MODULE - addModuleToRawPipeline(foundClass, IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.FILE_ANALYSIS); - modulesChanged = true; + if (exists == true) { + break; } + } + if (exists == false) { + logger.log(Level.INFO, "Discovered a new file module to load: " + foundClass.getName()); + //ADD MODULE + addModuleToRawPipeline(foundClass, IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.FILE_ANALYSIS); + modulesChanged = true; } - it = dataSourceModules.iterator(); - while (it.hasNext()) { - boolean exists = false; - Class<IngestModuleDataSource> foundClass = (Class<IngestModuleDataSource>) it.next(); + } - for (IngestModuleLoader.XmlPipelineRaw rawP : pipelinesXML) { - if (!rawP.type.equals(IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.DATA_SOURCE_ANALYSIS.toString())) { - continue; //skip - } + it = dataSourceModules.iterator(); + while (it.hasNext()) { + boolean exists = false; + Class<IngestModuleDataSource> foundClass = (Class<IngestModuleDataSource>) it.next(); + for (IngestModuleLoader.XmlPipelineRaw rawP : pipelinesXML) { + if (!rawP.type.equals(IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.DATA_SOURCE_ANALYSIS.toString())) { + continue; //skip + } - for (IngestModuleLoader.XmlModuleRaw rawM : rawP.modules) { - //logger.log(Level.INFO, "CLASS NAME : " + foundClass.getName()); - if (foundClass.getName().equals(rawM.location)) { - exists = true; - break; - } - } - if (exists == true) { + + for (IngestModuleLoader.XmlModuleRaw rawM : rawP.modules) { + //logger.log(Level.INFO, "CLASS NAME : " + foundClass.getName()); + if (foundClass.getName().equals(rawM.location)) { + exists = true; break; } } - - if (exists == false) { - logger.log(Level.INFO, "Discovered a new DataSource module to load: " + foundClass.getName()); - //ADD MODULE - addModuleToRawPipeline(foundClass, IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.DATA_SOURCE_ANALYSIS); - modulesChanged = true; + if (exists == true) { + break; } - } - if (modulesChanged) { - save(); - pcs.firePropertyChange(IngestModuleLoader.Event.ModulesReloaded.toString(), 0, 1); + if (exists == false) { + logger.log(Level.INFO, "Discovered a new DataSource module to load: " + foundClass.getName()); + //ADD MODULE + addModuleToRawPipeline(foundClass, IngestModuleLoader.XmlPipelineRaw.PIPELINE_TYPE.DATA_SOURCE_ANALYSIS); + modulesChanged = true; } - /* - //Enumeration<URL> resources = moduleClassLoader.getResources(basePackageName); - Enumeration<URL> resources = classLoader.getResources(basePackageName); - while (resources.hasMoreElements()) { - System.out.println(resources.nextElement()); - } */ + } - } else { - //logger.log(Level.INFO, "Module disabled: " + moduleInfo.getDisplayName() ); + if (modulesChanged) { + save(); + pcs.firePropertyChange(IngestModuleLoader.Event.ModulesReloaded.toString(), 0, 1); } - } + /* + //Enumeration<URL> resources = moduleClassLoader.getResources(basePackageName); + Enumeration<URL> resources = classLoader.getResources(basePackageName); + while (resources.hasMoreElements()) { + System.out.println(resources.nextElement()); + } */ + } } /**