Search in sources :

Example 1 with IdaException

use of com.google.security.zynamics.zylib.system.IdaException in project binnavi by google.

the class CBinExportImporter method createIdaProcess.

/**
   * Creates the IDA Pro process that is used to export the data from the IDB file to the database.
   *
   * @param idaExe The location of the IDA Pro executable.
   * @param idbFileName The location of the IDB file to import.
   * @param host Host of the database.
   * @param port Port of the database.
   * @param user Name of the user used to connect to the database.
   * @param password Password of the user.
   * @param name Name of the database to connect to.
   *
   * @return The spawned IDA Pro process.
   *
   * @throws IdaException Thrown if the IDA Pro process could not be created.
   */
private static Process createIdaProcess(final String idaExe, final String idbFileName, final String host, final int port, final String user, final String password, final String name) throws IdaException {
    final String tempPath = SystemHelpers.getTempDirectory();
    final File idcFile = new File(tempPath + BINEXPORT_IDC_FILE);
    try {
        if (!idcFile.exists()) {
            idcFile.createNewFile();
        }
        FileWriter fw = new FileWriter(idcFile.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(BINEXPORT_IDC_FILE_CONTENT);
        bw.close();
    } catch (final IOException exception) {
        CUtilityFunctions.logException(exception);
    }
    final String idcPath = idcFile.getAbsolutePath();
    // Setup the invocation of the IDA to SQL exporter
    final ProcessBuilder processBuilder = new ProcessBuilder(idaExe, "-A", "-OExporterHost:" + host, "-OExporterPort:" + port, "-OExporterUser:" + user, "-OExporterPassword:" + password, "-OExporterDatabase:" + name, "-OExporterSchema:public", IdaHelpers.getSArgument(idcPath, SystemHelpers.isRunningWindows()), idbFileName);
    // Now launch the exporter to export the IDB to the database
    try {
        Process processInfo = null;
        processBuilder.redirectErrorStream(true);
        processInfo = processBuilder.start();
        // Java manages the streams internally - if they are full, the process blocks, i.e. IDA
        // hangs, so we need to consume them.
        final BufferedReader reader = new BufferedReader(new InputStreamReader(processInfo.getInputStream()));
        @SuppressWarnings("unused") String line;
        try {
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (final IOException exception) {
            reader.close();
        }
        reader.close();
        return processInfo;
    } catch (final Exception exception) {
        try {
            CUtilityFunctions.logException(exception);
        } catch (final UnknownFormatConversionException e) {
        // Some Windows error messages contain %1 characters.
        }
        throw new IdaException("E00210: Failed attempting to launch the importer with IDA: " + exception, exception);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IdaException(com.google.security.zynamics.zylib.system.IdaException) UnknownFormatConversionException(java.util.UnknownFormatConversionException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) UnknownFormatConversionException(java.util.UnknownFormatConversionException) BufferedReader(java.io.BufferedReader) IdaException(com.google.security.zynamics.zylib.system.IdaException) File(java.io.File)

Aggregations

IdaException (com.google.security.zynamics.zylib.system.IdaException)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnknownFormatConversionException (java.util.UnknownFormatConversionException)1