Search in sources :

Example 1 with IDirectoryTraversalCallback

use of com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback in project binnavi by google.

the class PluginLoader method collectPluginFiles.

/**
   * Collects all plugin files from the plugin directory.
   *
   * @param directory The plugin directory.
   *
   * @return The collected plugin files.
   */
public static Set<File> collectPluginFiles(final String directory) {
    final Set<File> pluginFiles = new HashSet<File>();
    final File file = new File(directory);
    DirUtils.traverse(file, new IDirectoryTraversalCallback() {

        @Override
        public void entering(final File directory) {
            System.out.println(directory.getName());
        // Unused
        }

        @Override
        public void leaving(final File directory) {
        // Unused
        }

        @Override
        public void nextFile(final File pluginFile) {
            System.out.println(pluginFile.getName());
            if (pluginFile.getName().endsWith(".jar") || pluginFile.getName().endsWith(".class")) {
                pluginFiles.add(pluginFile);
            }
        }
    });
    return pluginFiles;
}
Also used : File(java.io.File) IDirectoryTraversalCallback(com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback) HashSet(java.util.HashSet)

Example 2 with IDirectoryTraversalCallback

use of com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback in project binnavi by google.

the class JarLoader method collectJars.

/**
   * Finds the JAR files in the additional JAR file directory.
   *
   * @param rootPath The BinNavi root path.
   *
   * @return The list of JAR files found.
   */
public static Set<File> collectJars(final String rootPath) {
    Preconditions.checkNotNull(rootPath, "IE00827: BinNavi root path can't be null");
    final Set<File> jarFiles = Sets.newHashSet();
    final File jarDirectory = new File(rootPath + File.separator + JAR_DIRECTORY);
    DirUtils.traverse(jarDirectory, new IDirectoryTraversalCallback() {

        @Override
        public void entering(final File directory) {
        // Not necessary
        }

        @Override
        public void leaving(final File directory) {
        // Not necessary
        }

        @Override
        public void nextFile(final File file) {
            if (!FileUtils.getFileExtension(file).equals("jar")) {
                return;
            }
            jarFiles.add(file);
        }
    });
    return jarFiles;
}
Also used : File(java.io.File) IDirectoryTraversalCallback(com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback)

Example 3 with IDirectoryTraversalCallback

use of com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback in project binnavi by google.

the class CTutorialLoader method readTutorials.

/**
   * Loads all tutorial files from the given directory.
   * 
   * @param directory Directory from which the tutorials are loaded.
   * 
   * @return List of tutorials loaded from the tutorial files in the given directory.
   */
public static IFilledList<CTutorial> readTutorials(final String directory) {
    final IFilledList<CTutorial> tutorials = new FilledList<CTutorial>();
    DirUtils.traverse(new File(directory), new IDirectoryTraversalCallback() {

        @Override
        public void entering(final File directory) {
        // Irrelevant
        }

        @Override
        public void leaving(final File directory) {
        // Irrelevant
        }

        @Override
        public void nextFile(final File file) {
            if (file.getAbsolutePath().endsWith("xml")) {
                try {
                    tutorials.add(loadTutorial(file));
                } catch (final ParserConfigurationException e) {
                    CUtilityFunctions.logException(e);
                } catch (final SAXException e) {
                    CUtilityFunctions.logException(e);
                } catch (final IOException e) {
                    CUtilityFunctions.logException(e);
                }
            }
        }
    });
    return tutorials;
}
Also used : FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) File(java.io.File) IDirectoryTraversalCallback(com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback) SAXException(org.xml.sax.SAXException)

Example 4 with IDirectoryTraversalCallback

use of com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback in project binnavi by google.

the class ScriptLoader method collectScripts.

/**
   * Collects all script files that can be found in the default scripts directory.
   *
   * @param startupPath BinNavi startup path.
   *
   * @return Script files found in the scripts path.
   */
public static Set<File> collectScripts(final String startupPath) {
    final Set<File> scriptFiles = new HashSet<>();
    final String scriptPath = startupPath + File.separator + "scripts";
    final File scriptDir = new File(scriptPath);
    DirUtils.traverse(scriptDir, new IDirectoryTraversalCallback() {

        private boolean skip = false;

        @Override
        public void entering(final File directory) {
            skip = isLibDirectory(scriptDir, directory);
        }

        @Override
        public void leaving(final File directory) {
            skip = false;
        }

        @Override
        public void nextFile(final File file) {
            if (skip) {
                return;
            }
            final String filename = FileUtils.getFileBasename(file);
            if ("init".equals(filename) || !ScriptRunner.canRun(file)) {
                return;
            }
            scriptFiles.add(file);
        }
    });
    return scriptFiles;
}
Also used : File(java.io.File) IDirectoryTraversalCallback(com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback) HashSet(java.util.HashSet)

Aggregations

IDirectoryTraversalCallback (com.google.security.zynamics.zylib.io.IDirectoryTraversalCallback)4 File (java.io.File)4 HashSet (java.util.HashSet)2 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)1 IFilledList (com.google.security.zynamics.zylib.types.lists.IFilledList)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1