Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.coreutils;
20 
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.text.MessageFormat;
25 import java.util.logging.Level;
26 import org.apache.commons.lang3.StringUtils;
27 
31 public class DataSourceUtils {
32  private static final Logger logger = Logger.getLogger(DataSourceUtils.class.getName());
33 
45  public static boolean imageHasFileSystem(Path dataSourcePath) throws IOException {
46  return SleuthkitJNI.isImageSupported(dataSourcePath.toString());
47  }
48 
61  public static boolean imageHasFileSystem(Path dataSourcePath, String password) throws IOException {
62  try {
63  SleuthkitJNI.TestOpenImageResult openImageResult = SleuthkitJNI.testOpenImage(dataSourcePath.toString(), password);
64  if (openImageResult.wasSuccessful()) {
65  return true;
66  } else {
67  String message = MessageFormat.format("An error occurred while opening {0}: {1}",
68  dataSourcePath.toString(),
69  openImageResult == null || StringUtils.isBlank(openImageResult.getMessage())
70  ? "<unknown>"
71  : openImageResult.getMessage());
72  logger.log(Level.INFO, message);
73  return false;
74  }
75  } catch (Throwable ex) {
76  String message = "An error occurred while opening " + dataSourcePath.toString();
77  logger.log(Level.WARNING, message);
78  return false;
79  }
80  }
81 }
82 
static boolean imageHasFileSystem(Path dataSourcePath, String password)
static boolean isImageSupported(String imagePath)
static TestOpenImageResult testOpenImage(String imagePath, String password)
static boolean imageHasFileSystem(Path dataSourcePath)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on: Mon Feb 17 2025
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.