com.wjholden.nmap
Class NmapUtilities

java.lang.Object
  extended by com.wjholden.nmap.NmapUtilities
All Implemented Interfaces:
NmapConstants

public final class NmapUtilities
extends java.lang.Object
implements NmapConstants

Author:
William John Holden (wjholden@gmail.com) Class created to centralize and more easily manage certain pieces of boilerplate code, often code groups that are required more than once. PMD recommended I make this a "singleton" so here goes.

Field Summary
private static NmapUtilities FINAL_INSTANCE
          Not used, but makes sure that only one instance of this class runs at once.
 
Fields inherited from interface com.wjholden.nmap.NmapConstants
BUFFER_SIZE, FORCE_RESTART, INSTALL_ERROR, INSTALL_FILENAMES, INSTALL_GOOD, INSTALL_NO_ROOT, INSTALL_RESOURCES, MG_DEBUG, MG_DEFAULT, MI_DEBUG_EMAIL, MI_DEBUG_ENABLE, MI_EXIT, MI_MORE_HELP, MI_REINSTALL, MI_SURVEY, RUN_COMPLETE, RUN_ERROR, RUN_LINE, SCANTYPE_NCAT, SCANTYPE_NDIFF, SCANTYPE_NMAP, SCANTYPE_NPING, TAG, THREAD_ERROR
 
Constructor Summary
private NmapUtilities()
          Private constructor can only be called in the above FINAL_INSTANCE.
 
Method Summary
static boolean checkRootPermissions()
          Mimics 'which' function to find 'su' command.
static java.lang.String findBinDir(java.lang.String myDataDir)
          Based on whether 'su' is available or not this method sets the location to write compiled binaries for later execution.
static java.lang.String getDataDirectory(Context context)
          Find the data directory to store applications in.
static java.lang.String verifyTemporaryFolder(Context context)
          Removed from verifyInstallation for version 21.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FINAL_INSTANCE

private static final NmapUtilities FINAL_INSTANCE
Not used, but makes sure that only one instance of this class runs at once.

Constructor Detail

NmapUtilities

private NmapUtilities()
Private constructor can only be called in the above FINAL_INSTANCE. This ensures that only one instance of this "static" class exists, hence it's a singleton.

Method Detail

checkRootPermissions

public static boolean checkRootPermissions()
Mimics 'which' function to find 'su' command. Sets Nmap.sh and Nmap.canGetRoot. Originally, the program just looked for a hard-coded 'su' path, but CM6 has 'su' in a different location. Logic robusted to look everywhere in $PATH. Also sets shell, using Nmap.setSh(String).

Returns:
true if su found in $PATH.
Since:
0.4.1

findBinDir

public static java.lang.String findBinDir(java.lang.String myDataDir)
Based on whether 'su' is available or not this method sets the location to write compiled binaries for later execution.

Parameters:
myDataDir - - directory set by (above) getDataDirectory(Context)
Returns:
Absolute location to write binaries as String.
Since:
22 - UPDATE - now ALWAYS uses the {dataDir}/bin/ folder

getDataDirectory

public static java.lang.String getDataDirectory(Context context)
Find the data directory to store applications in. Normally will be of form /data/da

Parameters:
c -
Returns:
Absolute path of data directory as String.

verifyTemporaryFolder

public static java.lang.String verifyTemporaryFolder(Context context)
                                              throws java.io.IOException,
                                                     NameNotFoundException
Removed from verifyInstallation for version 21. If temporary folder does not already exist, create it.

Parameters:
c - Context the application is executing in.
Returns:
Absolute path of the temporary folder as String.
Throws:
java.io.IOException
NameNotFoundException