You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.1 KiB
58 lines
2.1 KiB
4 years ago
|
import org.jsoup.Jsoup;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.util.*;
|
||
|
|
||
|
/**
|
||
|
* downloads all files on each page, unpacks the cab file, and scans the driver files for desired imports.
|
||
|
* inspection of the drivers must be done manually until further notice.
|
||
|
*/
|
||
|
public class UpdateScanner extends Thread {
|
||
|
private static final String searchUrl = "https://www.catalog.update.microsoft.com/Search.aspx?q=";
|
||
|
private String searchKey;
|
||
|
private Map<String, String> dataMap = new HashMap<>();
|
||
|
private static String[] imports;
|
||
|
|
||
|
public UpdateScanner(String searchKey) {
|
||
|
this.searchKey = searchKey;
|
||
|
}
|
||
|
|
||
|
public UpdateScanner(String searchKey, String[] imports) {
|
||
|
this.searchKey = searchKey;
|
||
|
this.imports = imports;
|
||
|
}
|
||
|
|
||
|
public UpdateScanner(String searchKey, Map<String, String> dataMap) {
|
||
|
this.searchKey = searchKey;
|
||
|
this.dataMap = dataMap;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* used to scan all pages with as many threads as possible.
|
||
|
* Each page contains data needed to get to the next so as soon as that is obtained
|
||
|
* we make a new thread to scan the next page.
|
||
|
*/
|
||
|
public void run() {
|
||
|
try {
|
||
|
// get page
|
||
|
var result = Jsoup
|
||
|
.connect(this.searchUrl.concat(this.searchKey.replace(" ", "+")))
|
||
|
.data(this.dataMap)
|
||
|
.post();
|
||
|
|
||
|
// get the pages values
|
||
|
var pageValues = new UpdatePageValues(result.getAllElements());
|
||
|
System.out.printf("[+] scanning page %d of %d\n", pageValues.getPageIndex(), pageValues.getMaxPageIndex());
|
||
|
|
||
|
// if there is a next page, fork a thread to process it whilst we process this page
|
||
|
if (pageValues.hasNextPage())
|
||
|
new UpdateScanner(this.searchKey, pageValues.getAspNetHiddenUrlEncoded()).start();
|
||
|
|
||
|
// for each uuid on this page make a new thread to download and scan the file
|
||
|
pageValues.getPageTableValues().getDriverUuids().forEach(uuid -> {
|
||
|
new DriverDownloader(uuid, this.imports).start();
|
||
|
});
|
||
|
} catch (IOException e) { }
|
||
|
}
|
||
|
}
|