27 package org.sleuthkit.autopsy.recentactivity;
30 import java.io.FileInputStream;
31 import java.io.FileNotFoundException;
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Scanner;
35 import java.util.logging.Level;
38 import org.openide.util.NbBundle;
44 class UsbDeviceIdMapper {
45 private static final Logger logger = Logger.getLogger(UsbDeviceIdMapper.class.getName());
46 private HashMap<String, USBInfo> devices;
47 private static final String DataFile =
"USB_DATA.txt";
49 public UsbDeviceIdMapper() {
52 }
catch (FileNotFoundException ex) {
53 logger.log(Level.SEVERE,
"Could not find file " + DataFile +
".", ex);
55 }
catch (IOException ex) {
56 logger.log(Level.SEVERE,
"Unknown IO error occurred in method devices.", ex);
66 public USBInfo parseAndLookup(String dev) {
67 String[] dtokens = dev.split(
"[_&]");
68 String vID = dtokens[1].toUpperCase();
70 if (dtokens.length < 4 || dtokens[3].length() < 4) {
75 pID = pID.toUpperCase();
78 String key = vID + pID;
79 if (devices.containsKey(key)) {
80 return devices.get(key);
85 if (devices.containsKey(key)) {
86 USBInfo info = devices.get(key);
87 return new USBInfo(info.getVendor(),
88 NbBundle.getMessage(this.getClass(),
"UsbDeviceIdMapper.parseAndLookup.text", pID));
91 return new USBInfo(null, null);
100 private void loadDeviceMap() throws FileNotFoundException, IOException {
101 devices =
new HashMap<>();
102 PlatformUtil.extractResourceToUserConfigDir(this.getClass(), DataFile,
false);
103 try (Scanner dat =
new Scanner(
new FileInputStream(
new java.io.File(PlatformUtil.getUserConfigDirectory() + File.separator +
"USB_DATA.txt")))) {
110 String line = dat.nextLine();
111 while (dat.hasNext()) {
114 if ((line.startsWith(
"#")) || (line.equals(
""))) {
115 line = dat.nextLine();
120 if (line.startsWith(
"C 00")) {
125 String[] tokens = line.split(
"[\\t\\s]+");
126 String vID = tokens[0];
127 for (
int n = 1; n < tokens.length; n++) {
128 dvc += tokens[n] +
" ";
132 String pID = vID +
"0000";
133 pID = pID.toUpperCase();
134 USBInfo info =
new USBInfo(dvc, null);
135 devices.put(pID, info);
138 line = dat.nextLine();
139 if (line.startsWith(
"\t")) {
140 while (dat.hasNext() && line.startsWith(
"\t")) {
141 tokens = line.split(
"[\\t\\s]+");
144 pID = vID + tokens[1];
145 pID = pID.toUpperCase();
148 line = dat.nextLine();
149 for (
int n = 2; n < tokens.length; n++) {
150 device += tokens[n] +
" ";
153 info =
new USBInfo(dvc, device);
156 devices.put(pID, info);
USBInfo(String vend, String prod)