updates and fixes

This commit is contained in:
Greg DiCristofaro 2024-04-23 15:22:50 -04:00
parent 86fbba9659
commit f5082ead11
4 changed files with 65 additions and 39 deletions

View File

@ -575,11 +575,6 @@ public class Installer extends ModuleInstall {
logger.log(Level.INFO, "close()"); //NON-NLS logger.log(Level.INFO, "close()"); //NON-NLS
//exit JavaFx plat
if (javaFxInit) {
Platform.exit();
}
for (ModuleInstall mi : packageInstallers) { for (ModuleInstall mi : packageInstallers) {
logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
try { try {
@ -591,5 +586,10 @@ public class Installer extends ModuleInstall {
for (Handler h : logger.getHandlers()) { for (Handler h : logger.getHandlers()) {
h.close(); //must call h.close or a .LCK file will remain. h.close(); //must call h.close or a .LCK file will remain.
} }
//exit JavaFx plat
if (javaFxInit) {
Platform.exit();
}
} }
} }

View File

@ -169,6 +169,8 @@ ImageNode.createSheet.type.displayName=Type
ImageNode.createSheet.type.name=Type ImageNode.createSheet.type.name=Type
ImageNode.createSheet.type.text=Image ImageNode.createSheet.type.text=Image
ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes ImageNode.getActions.openFileSearchByAttr.text=Open File Search by Attributes
Installer_validate_tskLibLock_description=<html>It appears that an older version of an application that opens The Sleuth Kit databases is currently running on your system.<br/> Close this application before opening Autopsy, and consider upgrading in order to have a better user experience.</html>
Installer_validate_tskLibLock_title=Error calling Sleuth Kit library
KeyValueNode.menuItemText.viewFileInDir=View Source File in Directory KeyValueNode.menuItemText.viewFileInDir=View Source File in Directory
KeywordHits.createNodeForKey.accessTime.desc=Access Time KeywordHits.createNodeForKey.accessTime.desc=Access Time
KeywordHits.createNodeForKey.accessTime.displayName=Access Time KeywordHits.createNodeForKey.accessTime.displayName=Access Time

View File

@ -19,7 +19,6 @@
package org.sleuthkit.autopsy.datamodel; package org.sleuthkit.autopsy.datamodel;
import java.awt.Component; import java.awt.Component;
import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
@ -51,7 +50,7 @@ public class Installer extends ModuleInstall {
@Messages({ @Messages({
"Installer_validate_tskLibLock_title=Error calling Sleuth Kit library", "Installer_validate_tskLibLock_title=Error calling Sleuth Kit library",
"Installer_validate_tskLibLock_description=It appears that an older version of an application that opens The Sleuth Kit databases is currently running on your system. Close this application before opening Autopsy, and consider upgrading in order to have a better user experience." "Installer_validate_tskLibLock_description=<html>It appears that an older version of an application that opens The Sleuth Kit databases is currently running on your system.<br/> Close this application before opening Autopsy, and consider upgrading in order to have a better user experience.</html>"
}) })
@Override @Override
public void validate() throws IllegalStateException { public void validate() throws IllegalStateException {
@ -70,13 +69,9 @@ public class Installer extends ModuleInstall {
Logger logger = Logger.getLogger(Installer.class.getName()); Logger logger = Logger.getLogger(Installer.class.getName());
try { try {
try { TskLibLock libLock = TskLibLock.acquireLibLock();
TskLibLock libLock = TskLibLock.acquireLibLock(); if (libLock != null && libLock.getLockState() == LockState.HELD_BY_OLD) {
if (libLock != null && libLock.getLockState() == LockState.HELD_BY_OLD) { throw new OldAppLockException("A lock on the libtsk_jni lib is already held by an old application. " + (libLock.getLibTskJniFile() != null ? libLock.getLibTskJniFile().getAbsolutePath() : ""));
throw new OldAppLockException("A lock on the libtsk_jni lib is already held by an old application. " + (libLock.getLibTskJniFile() != null ? libLock.getLibTskJniFile().getAbsolutePath() : ""));
}
} catch (IOException ex) {
logger.log(Level.SEVERE, "An error occurred while acquiring the TSK lib lock", ex);
} }
String skVersion = SleuthkitJNI.getVersion(); String skVersion = SleuthkitJNI.getVersion();
@ -120,7 +115,30 @@ public class Installer extends ModuleInstall {
} }
} }
@Override
public void close() {
try {
TskLibLock.removeLibLock();
} catch (Exception ex) {
Logger logger = Logger.getLogger(Installer.class.getName());
logger.log(Level.WARNING, "There was an error removing the TSK lib lock.", ex);
}
}
@Override
public void uninstalled() {
try {
TskLibLock.removeLibLock();
} catch (Exception ex) {
Logger logger = Logger.getLogger(Installer.class.getName());
logger.log(Level.WARNING, "There was an error removing the TSK lib lock.", ex);
}
}
/** /**
* An exception when an older application (Autopsy * An exception when an older application (Autopsy
*/ */

View File

@ -26,6 +26,7 @@ import java.nio.channels.FileLock;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Level;
/** /**
* Creates a file lock at the old location (Autopsy LTE 4.21.0) of TSK * Creates a file lock at the old location (Autopsy LTE 4.21.0) of TSK
@ -58,7 +59,7 @@ class TskLibLock implements AutoCloseable {
* acquired) and any resources if the lock is acquired. * acquired) and any resources if the lock is acquired.
* @throws IOException * @throws IOException
*/ */
static TskLibLock acquireLibLock() throws IOException { static TskLibLock acquireLibLock() {
if (libLock == null) { if (libLock == null) {
libLock = getLibLock(); libLock = getLibLock();
} }
@ -84,7 +85,7 @@ class TskLibLock implements AutoCloseable {
* acquired) and any resources if the lock is acquired. * acquired) and any resources if the lock is acquired.
* @throws IOException * @throws IOException
*/ */
private static TskLibLock getLibLock() throws IOException { private static TskLibLock getLibLock() {
// TODO error handling cleanup // TODO error handling cleanup
String libExt = getLibExtension(); String libExt = getLibExtension();
@ -104,38 +105,43 @@ class TskLibLock implements AutoCloseable {
: LockState.HELD_BY_OLD; : LockState.HELD_BY_OLD;
return new TskLibLock(lockState, libTskJniFile, lockFileRaf, null, null); return new TskLibLock(lockState, libTskJniFile, lockFileRaf, null, null);
} catch (IOException ex) {
// if there is an error getting read only access, then it is the old application dll
java.util.logging.Logger.getLogger(TskLibLock.class.getCanonicalName()).log(Level.WARNING, "An error occurred while acquiring the TSK lib lock", ex);
return new TskLibLock(LockState.HELD_BY_OLD, libTskJniFile, null, null, null);
} }
} else { } else {
// make directories leading up to that // make directories leading up to that
libTskJniFile.getParentFile().mkdirs(); libTskJniFile.getParentFile().mkdirs();
// get file access to the file // get file access to the file
RandomAccessFile lockFileRaf = new RandomAccessFile(libTskJniFile, "rw"); RandomAccessFile lockFileRaf = null;
FileChannel lockFileChannel = lockFileRaf.getChannel(); FileChannel lockFileChannel = null;
FileLock lockFileLock = lockFileChannel == null FileLock lockFileLock = null;
? null try {
: lockFileChannel.tryLock(1024L, 1L, false); lockFileRaf = new RandomAccessFile(libTskJniFile, "rw");
lockFileChannel = lockFileRaf.getChannel();
lockFileLock = lockFileChannel == null
? null
: lockFileChannel.tryLock(1024L, 1L, false);
if (lockFileLock != null) { if (lockFileLock != null) {
lockFileRaf.setLength(0); lockFileRaf.setLength(0);
lockFileRaf.write(UTF8_BOM); lockFileRaf.write(UTF8_BOM);
lockFileRaf.writeChars(LIB_FILE_LOCK_TEXT); lockFileRaf.writeChars(LIB_FILE_LOCK_TEXT);
return new TskLibLock(LockState.ACQUIRED, libTskJniFile, lockFileRaf, lockFileChannel, lockFileLock); return new TskLibLock(LockState.ACQUIRED, libTskJniFile, lockFileRaf, lockFileChannel, lockFileLock);
} else { } else {
if (lockFileChannel != null) { LockState lockState = isNewLock(lockFileRaf)
lockFileChannel.close(); ? LockState.HELD_BY_NEW
: LockState.HELD_BY_OLD;
return new TskLibLock(lockState, libTskJniFile, lockFileRaf, lockFileChannel, null);
} }
} catch (IOException ex) {
if (lockFileRaf != null) { // if there is an error getting read only access, then it is the old application dll
lockFileRaf.close(); java.util.logging.Logger.getLogger(TskLibLock.class.getCanonicalName()).log(Level.WARNING, "An error occurred while acquiring the TSK lib lock", ex);
} return new TskLibLock(LockState.HELD_BY_OLD, libTskJniFile, lockFileRaf, lockFileChannel, lockFileLock);
LockState lockState = isNewLock(lockFileRaf)
? LockState.HELD_BY_NEW
: LockState.HELD_BY_OLD;
return new TskLibLock(lockState, libTskJniFile, lockFileRaf, lockFileChannel, null);
} }
} }
} }