private List<File> findModules(Set<String> insmodCommands) { if (interestingFiles == null || insmodCommands != null) { interestingFiles = new ArrayList<File>(); scan(new File("/system"), interestingFiles, insmodCommands); scan(new File("/lib"), interestingFiles, insmodCommands); scan(new File("/wifi"), interestingFiles, insmodCommands); scan(new File("/etc"), interestingFiles, insmodCommands); } return interestingFiles; }
private void scan(File folder, List<File> results, Set<String> insmodCommands) { File files[] = folder.listFiles(); if (files == null) return; for (File file : files) { try { if (file.isDirectory()) { if (!isSymLink(file)) scan(file, results, insmodCommands); } else { String path = file.getCanonicalPath(); if (path.contains("wifi") || path.endsWith(".ko")) { results.add(file); } // Only look in small files, and stop looking if a file is // binary if (insmodCommands != null && file.length() < 16384 && ((file.getName().endsWith(".so") == false)) && ((file.getName().endsWith(".ttf") == false)) && ((file.getName().endsWith(".ogg") == false)) && ((file.getName().endsWith(".odex") == false)) && ((file.getName().endsWith(".apk") == false))) { BufferedReader b = new BufferedReader(new FileReader(file)); try { String line = null; String dmp = null; while ((line = b.readLine()) != null) { // Stop looking if the line seems to be binary if (line.length() > 0 && (line.charAt(0) > 0x7d || line.charAt(0) < 0x09)) { // LogActivity.logMessage("guess", file // + " seems to be binary", false); break; } if (line.startsWith("DRIVER_MODULE_PATH=")) dmp = line.substring(19); if (dmp != null && line.startsWith("DRIVER_MODULE_ARG=")) { insmodCommands.add("insmod " + dmp + " \"" + line.substring(18) + "\""); dmp = null; } if (line.contains("insmod ")) { // Ooh, an insmod command. // Let's see if it is interesting. insmodCommands.add(line); } } b.close(); } catch (IOException e) { b.close(); } finally { b.close(); } } } } catch (IOException e) { // ignore } } }