mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-19 19:14:55 +00:00
Simplying things, reducing NPEs
This commit is contained in:
parent
e54eab05b3
commit
2b768d7c9f
@ -21,8 +21,7 @@ package org.sleuthkit.autopsy.modules.embeddedfileextractor;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -809,7 +808,8 @@ class SevenZipExtractor {
|
||||
return unpackSuccessful;
|
||||
}
|
||||
|
||||
private String detectFilenamesCharset(Collection<byte[]> byteDatas) {
|
||||
private Charset detectFilenamesCharset(Collection<byte[]> byteDatas) {
|
||||
Charset detectedCharset = null;
|
||||
CharsetDetector charsetDetector = new CharsetDetector();
|
||||
int sum = 0;
|
||||
for (byte[] byteData : byteDatas) {
|
||||
@ -824,22 +824,11 @@ class SevenZipExtractor {
|
||||
charsetDetector.setText(allBytes);
|
||||
CharsetMatch cm = charsetDetector.detect();
|
||||
if (cm.getConfidence() >= 90) {
|
||||
return cm.getName();
|
||||
} else {
|
||||
return null;
|
||||
if (Charset.isSupported(cm.getName())) {
|
||||
detectedCharset = Charset.forName(cm.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private String decodeFilename(byte[] nameBytes, String charset) {
|
||||
String decodedName = null;
|
||||
if (charset != null) {
|
||||
try {
|
||||
decodedName = new String(nameBytes, charset);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
logger.log(Level.WARNING, "Error decoding filename. ", ex); //NON-NLS
|
||||
}
|
||||
}
|
||||
return decodedName;
|
||||
return detectedCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1331,20 +1320,18 @@ class SevenZipExtractor {
|
||||
}
|
||||
names += child.getFileName();
|
||||
}
|
||||
String detectedCharset = detectFilenamesCharset(byteDatas);
|
||||
Charset detectedCharset = detectFilenamesCharset(byteDatas);
|
||||
|
||||
// If a charset was detected, transcode filenames accordingly
|
||||
if (detectedCharset != null) {
|
||||
if (detectedCharset != null && detectedCharset.canEncode()) {
|
||||
for (UnpackedNode child : node.getChildren()) {
|
||||
if (child.getFileNameBytes() != null) {
|
||||
String decodedName = decodeFilename(child.getFileNameBytes(), detectedCharset);
|
||||
|
||||
if (decodedName != null) {
|
||||
String decodedName = new String(child.getFileNameBytes(), detectedCharset);
|
||||
child.setFileName(decodedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//recurse adding the children if this file was incomplete the children presumably need to be added
|
||||
for (UnpackedNode child : node.getChildren()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user