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;
45 class UsbDeviceIdMapper {
47 private static final Logger logger = Logger.getLogger(UsbDeviceIdMapper.class.getName());
48 private HashMap<String, USBInfo> devices;
49 private static final String DataFile =
"USB_DATA.txt";
51 public UsbDeviceIdMapper() {
54 }
catch (FileNotFoundException ex) {
55 logger.log(Level.SEVERE,
"Could not find file " + DataFile +
".", ex);
57 }
catch (IOException ex) {
58 logger.log(Level.SEVERE,
"Unknown IO error occurred in method devices.", ex);
70 public USBInfo parseAndLookup(String dev) {
71 String[] dtokens = dev.split(
"[_&]");
72 String vID = dtokens[1].toUpperCase();
74 if (dtokens.length < 4 || dtokens[3].length() < 4) {
79 pID = pID.toUpperCase();
82 String key = vID + pID;
83 if (devices.containsKey(key)) {
84 return devices.get(key);
89 if (devices.containsKey(key)) {
90 USBInfo info = devices.get(key);
91 return new USBInfo(info.getVendor(),
92 NbBundle.getMessage(this.getClass(),
"UsbDeviceIdMapper.parseAndLookup.text", pID));
95 return new USBInfo(null, null);
104 private void loadDeviceMap() throws FileNotFoundException, IOException {
105 devices =
new HashMap<>();
106 PlatformUtil.extractResourceToUserConfigDir(this.getClass(), DataFile,
false);
107 try (Scanner dat =
new Scanner(
new FileInputStream(
new java.io.File(PlatformUtil.getUserConfigDirectory() + File.separator +
"USB_DATA.txt")))) {
114 String line = dat.nextLine();
115 while (dat.hasNext()) {
118 if ((line.startsWith(
"#")) || (line.equals(
""))) {
119 line = dat.nextLine();
124 if (line.startsWith(
"C 00")) {
129 String[] tokens = line.split(
"[\\t\\s]+");
130 String vID = tokens[0];
131 for (
int n = 1; n < tokens.length; n++) {
132 dvc += tokens[n] +
" ";
136 String pID = vID +
"0000";
137 pID = pID.toUpperCase();
138 USBInfo info =
new USBInfo(dvc, null);
139 devices.put(pID, info);
142 line = dat.nextLine();
143 if (line.startsWith(
"\t")) {
144 while (dat.hasNext() && line.startsWith(
"\t")) {
145 tokens = line.split(
"[\\t\\s]+");
148 pID = vID + tokens[1];
149 pID = pID.toUpperCase();
152 line = dat.nextLine();
153 for (
int n = 2; n < tokens.length; n++) {
154 device += tokens[n] +
" ";
157 info =
new USBInfo(dvc, device);
160 devices.put(pID, info);
USBInfo(String vend, String prod)