19 package org.sleuthkit.autopsy.coreutils;
 
   22 import java.io.IOException;
 
   23 import java.net.InetAddress;
 
   24 import java.nio.file.Files;
 
   25 import java.nio.file.Path;
 
   26 import java.nio.file.Paths;
 
   27 import java.util.HashMap;
 
   29 import java.util.NoSuchElementException;
 
   30 import java.util.Scanner;
 
   31 import java.util.UUID;
 
   32 import java.util.concurrent.TimeUnit;
 
   33 import java.util.logging.Level;
 
   37     private static Map<String, String> 
drives;
 
   41     private static final String 
OK_TXT = 
"OK"; 
 
   42     private static final String 
COLON = 
":"; 
 
   44     private static final String 
C_DRIVE = 
"C:"; 
 
   56         this.nameString = UUID.randomUUID().toString();
 
   79         if (inputPath != null) {
 
   81             if (inputPath.toUpperCase().startsWith(C_DRIVE)) {
 
   84             if (
false == 
isUNC(inputPath)) {
 
   85                 String uncPath = null;
 
   87                     String currentDrive = Paths.get(inputPath).getRoot().toString().substring(STARTING_OFFSET, REPLACEMENT_SIZE);
 
   88                     String uncMapping = drives.get(currentDrive.toUpperCase());
 
   89                     if (uncMapping != null) {
 
   90                         uncPath = uncMapping + inputPath.substring(REPLACEMENT_SIZE, inputPath.length());
 
   92                 } 
catch (Exception ex) {
 
  123         if (inputPath != null) {
 
  125             if (uncPath == null) {
 
  128                 return Paths.get(uncPath);
 
  143         if (inputPath != null) {
 
  158         if (inputPath != null) {
 
  159             String shortenedPath = inputPath.substring(STARTING_OFFSET, DRIVE_LEN);
 
  160             for (String s : drives.keySet()) {
 
  161                 if (shortenedPath.equals(s)) {
 
  182         if (inputPath != null) {
 
  202         if (inputPath != null) {
 
  203             String result = null;
 
  205                 if (
isUNC(Paths.get(inputPath))) {
 
  206                     String potentialIP = Paths.get(inputPath.substring(REPLACEMENT_SIZE)).getName(FIRST_ITEM).toString();
 
  207                     String hostname = InetAddress.getByName(potentialIP).getHostName();
 
  208                     result = inputPath.replaceAll(potentialIP, hostname);
 
  210             } 
catch (Exception ex) {
 
  226     synchronized public static boolean isUNC(Path inputPath) {
 
  227         if (inputPath != null) {
 
  228             return isUNC(inputPath.toString());
 
  241     synchronized public static boolean isUNC(String inputPath) {
 
  242         if (inputPath != null) {
 
  243             return inputPath.startsWith(UNC_PATH_START);
 
  269         Map<String, String> driveMap = 
new HashMap<>();
 
  275         File mappedDrive = Paths.get(System.getenv(TEMP_FOLDER), nameString + 
MAPPED_DRIVES).toFile();
 
  277             Files.deleteIfExists(mappedDrive.toPath());
 
  278             ProcessBuilder builder = 
new ProcessBuilder(
"cmd", 
"/c", 
"net", 
"use"); 
 
  279             builder.redirectOutput(mappedDrive);
 
  280             builder.redirectError(mappedDrive);
 
  281             Process p = builder.start(); 
 
  282             p.waitFor(10, TimeUnit.SECONDS);
 
  283             try (Scanner scanner = 
new Scanner(mappedDrive)) {
 
  285                 while (scanner.hasNext()) {
 
  286                     String entry1 = scanner.next();
 
  287                     if (entry1.startsWith(DATA_TRIGGER)) {
 
  290                     String entry2 = scanner.next();
 
  291                     if (entry2.startsWith(DATA_TRIGGER)) {
 
  294                     String entry3 = scanner.next();
 
  295                     if (entry3.startsWith(DATA_TRIGGER)) {
 
  299                     if (entry1.length() == DRIVE_LEN && !entry1.equals(OK_TXT) && entry1.endsWith(COLON)) {
 
  300                         driveMap.put(entry1, entry2); 
 
  301                     } 
else if (entry2.length() == DRIVE_LEN && entry2.endsWith(COLON)) {
 
  302                         driveMap.put(entry2, entry3); 
 
  306         } 
catch (IOException | InterruptedException | NoSuchElementException | IllegalStateException ex) {
 
  311                 Files.deleteIfExists(mappedDrive.toPath());
 
  312             } 
catch (IOException ex) {
 
  334         if (result == null) {
 
  338         if (result == null) {
 
synchronized void rescanDrives()
synchronized static boolean isUNC(String inputPath)
static final String UNC_PATH_START
static final String COLON
synchronized String mappedDriveToUNC(String inputPath)
static final int STARTING_OFFSET
static final String DATA_TRIGGER
static final int REPLACEMENT_SIZE
synchronized static boolean isUNC(Path inputPath)
synchronized String ipToHostName(String inputPath)
synchronized String convertPathToUNC(String indexDir)
synchronized Map< String, String > getMappedDrives()
synchronized boolean isDriveMapped(String inputPath)
static final int FIRST_ITEM
synchronized Path mappedDriveToUNC(Path inputPath)
static final String OK_TXT
static Map< String, String > drives
static final String TEMP_FOLDER
static final int DRIVE_LEN
static final String C_DRIVE
synchronized boolean isDriveMapped(Path inputPath)
synchronized static Logger getLogger(String name)
synchronized Path ipToHostName(Path inputPath)
static final String MAPPED_DRIVES