19package org.sleuthkit.autopsy.coreutils;
22import java.io.IOException;
23import java.net.InetAddress;
24import java.nio.file.Files;
25import java.nio.file.Path;
26import java.nio.file.Paths;
27import java.util.HashMap;
29import java.util.NoSuchElementException;
30import java.util.Scanner;
32import java.util.concurrent.TimeUnit;
33import 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;
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) {
124 String uncPath =
UNCPathUtilities.this.mappedDriveToUNC(inputPath.toString());
125 if (uncPath ==
null) {
128 return Paths.get(uncPath);
143 if (inputPath !=
null) {
158 if (inputPath !=
null) {
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))) {
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) {
269 Map<String, String> driveMap =
new HashMap<>();
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();
290 String entry2 = scanner.next();
294 String entry3 = scanner.next();
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 static Logger getLogger(String name)
static final int FIRST_ITEM
synchronized static boolean isUNC(Path inputPath)
synchronized boolean isDriveMapped(String inputPath)
static final String UNC_PATH_START
static Map< String, String > drives
synchronized String mappedDriveToUNC(String inputPath)
synchronized Map< String, String > getMappedDrives()
static final String C_DRIVE
synchronized boolean isDriveMapped(Path inputPath)
synchronized static boolean isUNC(String inputPath)
static final String OK_TXT
static final String TEMP_FOLDER
static final int DRIVE_LEN
static final int REPLACEMENT_SIZE
static final String DATA_TRIGGER
synchronized String convertPathToUNC(String indexDir)
static final String MAPPED_DRIVES
static final String COLON
synchronized void rescanDrives()
synchronized Path mappedDriveToUNC(Path inputPath)
static final int STARTING_OFFSET
synchronized Path ipToHostName(Path inputPath)
synchronized String ipToHostName(String inputPath)