mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
Improve log output
This commit is contained in:
parent
a4fdf1d575
commit
b5d9a62835
4 changed files with 32 additions and 16 deletions
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
|
@ -6,8 +6,8 @@ android {
|
||||||
applicationId "us.spotco.malwarescanner"
|
applicationId "us.spotco.malwarescanner"
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 47
|
versionCode 48
|
||||||
versionName "2.10"
|
versionName "2.11"
|
||||||
resConfigs "en"
|
resConfigs "en"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
|
@ -32,8 +32,13 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
|
@ -41,6 +46,7 @@ class Database {
|
||||||
private static TextView log = null;
|
private static TextView log = null;
|
||||||
private static SharedPreferences prefs = null;
|
private static SharedPreferences prefs = null;
|
||||||
private static File databasePath = null;
|
private static File databasePath = null;
|
||||||
|
private static ThreadPoolExecutor threadPoolExecutor = null;
|
||||||
|
|
||||||
public final static HashSet<SignatureDatabase> signatureDatabases = new HashSet<>();
|
public final static HashSet<SignatureDatabase> signatureDatabases = new HashSet<>();
|
||||||
public final static String baseURL = "https://spotco.us/MalwareScannerSignatures/";
|
public final static String baseURL = "https://spotco.us/MalwareScannerSignatures/";
|
||||||
|
@ -50,8 +56,11 @@ class Database {
|
||||||
public final static HashMap<String, String> signaturesSHA1 = new HashMap<>();
|
public final static HashMap<String, String> signaturesSHA1 = new HashMap<>();
|
||||||
public final static HashMap<String, String> signaturesSHA256 = new HashMap<>();
|
public final static HashMap<String, String> signaturesSHA256 = new HashMap<>();
|
||||||
|
|
||||||
|
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||||
|
|
||||||
public Database(TextView log) {
|
public Database(TextView log) {
|
||||||
Database.log = log;
|
Database.log = log;
|
||||||
|
threadPoolExecutor = (ThreadPoolExecutor) Executors.newScheduledThreadPool(Utils.getMaxThreads());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean areDatabasesAvailable() {
|
public static boolean areDatabasesAvailable() {
|
||||||
|
@ -68,9 +77,10 @@ class Database {
|
||||||
|
|
||||||
public static void updateDatabase(Context context, HashSet<SignatureDatabase> signatureDatabases) {
|
public static void updateDatabase(Context context, HashSet<SignatureDatabase> signatureDatabases) {
|
||||||
initDatabase(context);
|
initDatabase(context);
|
||||||
|
log.append("Updating " + signatureDatabases.size() + " databases...\n");
|
||||||
for (SignatureDatabase signatureDatabase : signatureDatabases) {
|
for (SignatureDatabase signatureDatabase : signatureDatabases) {
|
||||||
boolean onionRouting = prefs.getBoolean("ONION_ROUTING", false);
|
boolean onionRouting = prefs.getBoolean("ONION_ROUTING", false);
|
||||||
new Downloader().execute(onionRouting, signatureDatabase.getUrl(), databasePath + "/" + signatureDatabase.getName());
|
new Downloader().executeOnExecutor(threadPoolExecutor, onionRouting, signatureDatabase.getUrl(), databasePath + "/" + signatureDatabase.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,13 +163,11 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Downloader extends AsyncTask<Object, String, String> {
|
public static class Downloader extends AsyncTask<Object, String, String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Object... objects) {
|
protected String doInBackground(Object... objects) {
|
||||||
boolean onionRouting = (boolean) objects[0];
|
boolean onionRouting = (boolean) objects[0];
|
||||||
String url = (String) objects[1];
|
String url = (String) objects[1];
|
||||||
File out = new File((String) objects[2]);
|
File out = new File((String) objects[2]);
|
||||||
publishProgress("Downloading " + url.replaceAll(baseURL, ""));
|
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection;
|
HttpURLConnection connection;
|
||||||
if (onionRouting) {
|
if (onionRouting) {
|
||||||
|
@ -173,10 +181,13 @@ class Database {
|
||||||
connection.setConnectTimeout(90000);
|
connection.setConnectTimeout(90000);
|
||||||
connection.setReadTimeout(30000);
|
connection.setReadTimeout(30000);
|
||||||
connection.addRequestProperty("User-Agent", "Hypatia");
|
connection.addRequestProperty("User-Agent", "Hypatia");
|
||||||
|
String lastModifiedLocal = "";
|
||||||
if (out.exists()) {
|
if (out.exists()) {
|
||||||
connection.setIfModifiedSince(out.lastModified());
|
connection.setIfModifiedSince(out.lastModified());
|
||||||
|
lastModifiedLocal = " since " + dateFormat.format(new Date(out.lastModified()));
|
||||||
}
|
}
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
String lastModifiedServer = dateFormat.format(new Date(connection.getLastModified()));
|
||||||
int res = connection.getResponseCode();
|
int res = connection.getResponseCode();
|
||||||
if (res != 304) {
|
if (res != 304) {
|
||||||
if (res == 200) {
|
if (res == 200) {
|
||||||
|
@ -192,18 +203,23 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
fileOutputStream.close();
|
fileOutputStream.close();
|
||||||
publishProgress("Successfully downloaded\n");
|
publishProgress(url.replaceAll(baseURL, "")
|
||||||
|
+ "\n\tSuccessfully downloaded."
|
||||||
|
+ "\n\tReleased on " + lastModifiedServer + "\n");
|
||||||
} else {
|
} else {
|
||||||
publishProgress("File not downloaded, response code " + res + "\n");
|
publishProgress(url.replaceAll(baseURL, "")
|
||||||
|
+ "\n\tFile not downloaded, response code " + res + "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
publishProgress("File not changed\n");
|
publishProgress(url.replaceAll(baseURL, "")
|
||||||
|
+ "\n\tFile not changed" + lastModifiedLocal + "\n");
|
||||||
}
|
}
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
out.delete();
|
out.delete();
|
||||||
publishProgress("Failed to download, check logcat\n");
|
publishProgress(url.replaceAll(baseURL, "")
|
||||||
|
+ "\nFailed to download, check logcat\n");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,18 +102,18 @@ class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
|
||||||
fileHashesSHA1.clear();
|
fileHashesSHA1.clear();
|
||||||
fileHashesSHA256.clear();
|
fileHashesSHA256.clear();
|
||||||
|
|
||||||
publishProgress(filesToScan[0].size() + " files pending scan\n", true);
|
publishProgress("\t" + filesToScan[0].size() + " files pending scan\n", true);
|
||||||
|
|
||||||
Database.loadDatabase(context, true, Database.signatureDatabases);
|
Database.loadDatabase(context, true, Database.signatureDatabases);
|
||||||
if (Database.getSignatureCount() >= 0) {
|
if (Database.getSignatureCount() >= 0) {
|
||||||
publishProgress("Loaded database with " + Database.getSignatureCount() + " signatures\n", true);
|
publishProgress("\tLoaded database with " + Database.getSignatureCount() + " signatures\n", true);
|
||||||
|
|
||||||
//Get file hashes
|
//Get file hashes
|
||||||
publishProgress("Hashing files...", true);
|
publishProgress("\tHashing files...", true);
|
||||||
for (File file : filesToScan[0]) {
|
for (File file : filesToScan[0]) {
|
||||||
getFileHashes(file);
|
getFileHashes(file);
|
||||||
}
|
}
|
||||||
publishProgress("Calculated MD5/SHA-1/SHA-256 hashes for all files\n", true);
|
publishProgress("\tCalculated hashes for all files\n", true);
|
||||||
|
|
||||||
//Check the hashes
|
//Check the hashes
|
||||||
checkSignature("MD5", fileHashesMD5, Database.signaturesMD5);
|
checkSignature("MD5", fileHashesMD5, Database.signaturesMD5);
|
||||||
|
@ -129,7 +129,7 @@ class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
|
||||||
Log.d("Hypatia", "Scan completed in " + (SystemClock.elapsedRealtime() - scanTime) + " ms!");
|
Log.d("Hypatia", "Scan completed in " + (SystemClock.elapsedRealtime() - scanTime) + " ms!");
|
||||||
publishProgress("Scan completed in " + ((SystemClock.elapsedRealtime() - scanTime) / 1000) + " seconds!\n\n\n\n", true);
|
publishProgress("Scan completed in " + ((SystemClock.elapsedRealtime() - scanTime) / 1000) + " seconds!\n\n\n\n", true);
|
||||||
} else {
|
} else {
|
||||||
publishProgress("No database available, not scanning...", true);
|
publishProgress("\tNo database available, not scanning...", true);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -147,9 +147,9 @@ class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
|
||||||
publishProgress(result + " in " + file.getValue().toString().replaceAll(Environment.getExternalStorageDirectory().toString(), "~"), false);
|
publishProgress(result + " in " + file.getValue().toString().replaceAll(Environment.getExternalStorageDirectory().toString(), "~"), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
publishProgress("Checked all " + hashType + " hashes against signature databases\n", true);
|
publishProgress("\tChecked all " + hashType + " hashes against signature databases\n", true);
|
||||||
} else {
|
} else {
|
||||||
publishProgress("No " + hashType + " signatures available\n", true);
|
publishProgress("\tNo " + hashType + " signatures available\n", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue