mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
Many changes
- Cleanup - Database view prep - Basic scaffolding for supporting hex signatures
This commit is contained in:
parent
5b173677a2
commit
24c81c7f81
8 changed files with 71 additions and 30 deletions
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -24,7 +24,7 @@
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -33,8 +33,6 @@ dependencies {
|
||||||
implementation 'com.android.support:appcompat-v7:26.1.0'
|
implementation 'com.android.support:appcompat-v7:26.1.0'
|
||||||
implementation 'com.android.support:design:26.1.0'
|
implementation 'com.android.support:design:26.1.0'
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
implementation 'com.android.support:support-vector-drawable:26.1.0'
|
|
||||||
implementation 'com.android.support:support-v4:26.1.0'
|
implementation 'com.android.support:support-v4:26.1.0'
|
||||||
implementation 'com.android.support:preference-v7:26.1.0'
|
implementation 'com.android.support:preference-v7:26.1.0'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class DatabaseManager {
|
||||||
new File(databasePath + "/" + name).delete();
|
new File(databasePath + "/" + name).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadRemoteDatabases() {
|
public static void fetchRemoteDatabases() {
|
||||||
try {
|
try {
|
||||||
signatureDatabases.clear();
|
signatureDatabases.clear();
|
||||||
String api = Utils.getPrefs(context).getString("database_repo", "https://spotco.us/MalwareScannerSignatures/api.php");
|
String api = Utils.getPrefs(context).getString("database_repo", "https://spotco.us/MalwareScannerSignatures/api.php");
|
||||||
|
@ -78,8 +78,23 @@ public class DatabaseManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void fetchLocalDatabases() {
|
||||||
|
try {
|
||||||
|
signatureDatabases.clear();
|
||||||
|
String api = Utils.getPrefs(context).getString("database_repo", "https://spotco.us/MalwareScannerSignatures/api.php");
|
||||||
|
api = api.replaceAll("api.php", "");
|
||||||
|
for (File db : databasePath.listFiles()) {
|
||||||
|
String path = api + db.getName();
|
||||||
|
Signatures.SignatureDatabase newDatabase = new Signatures.SignatureDatabase(db.getName(), path, true);
|
||||||
|
signatureDatabases.add(newDatabase);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateDatabases() {
|
public static void updateDatabases() {
|
||||||
loadRemoteDatabases();
|
fetchRemoteDatabases();
|
||||||
for (Signatures.SignatureDatabase db : signatureDatabases) {
|
for (Signatures.SignatureDatabase db : signatureDatabases) {
|
||||||
if (db.isAvailable()) {
|
if (db.isAvailable()) {
|
||||||
new DownloaderTask().execute(db.getUrl(), databasePath + "/" + db.getName());
|
new DownloaderTask().execute(db.getUrl(), databasePath + "/" + db.getName());
|
||||||
|
@ -115,7 +130,7 @@ public class DatabaseManager {
|
||||||
boolean trim = Utils.getPrefs(context).getBoolean("database_trim_variants", false);
|
boolean trim = Utils.getPrefs(context).getBoolean("database_trim_variants", false);
|
||||||
int maxLength = Utils.getPrefs(context).getInt("database_hash_length", 12);
|
int maxLength = Utils.getPrefs(context).getInt("database_hash_length", 12);
|
||||||
|
|
||||||
if (database.getName().contains(".hdb")) {//.hdb format: md5, size, name
|
if (database.getName().contains(".hdb")) {//.hdb format: MD5:FileSize:MalwareName
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
String[] lineS = line.split(":");
|
String[] lineS = line.split(":");
|
||||||
if (trim) {
|
if (trim) {
|
||||||
|
@ -123,7 +138,7 @@ public class DatabaseManager {
|
||||||
}
|
}
|
||||||
Signatures.MD5.put(lineS[0].substring(0, maxLength), lineS[2]);
|
Signatures.MD5.put(lineS[0].substring(0, maxLength), lineS[2]);
|
||||||
}
|
}
|
||||||
} else if (database.getName().contains(".hsb")) {//.hsb format: sha256, size, name
|
} else if (database.getName().contains(".hsb")) {//.hsb format: SHA{1,256}:FileSize:MalwareName
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
String[] lineS = line.split(":");
|
String[] lineS = line.split(":");
|
||||||
if (trim) {
|
if (trim) {
|
||||||
|
@ -135,6 +150,21 @@ public class DatabaseManager {
|
||||||
Signatures.SHA256.put(lineS[0].substring(0, maxLength), lineS[2]);
|
Signatures.SHA256.put(lineS[0].substring(0, maxLength), lineS[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (database.getName().contains(".ldb")) {//.ldb format: SignatureName;TargetDescriptionBlock;LogicalExpression;Subsig0;Subsig1;Subsig2;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
String[] lineS = line.split(";");
|
||||||
|
if (trim) {
|
||||||
|
lineS[0] = lineS[0].split("-")[0];
|
||||||
|
}
|
||||||
|
if (lineS[2].contains("|") && !lineS[2].contains("&")) {
|
||||||
|
for (int x = 3; x < lineS.length; x++) {
|
||||||
|
String hex = lineS[x];
|
||||||
|
if (hex.matches("[0-9a-fA-F]+")) {
|
||||||
|
Signatures.hex.put(lineS[0], hex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,13 +24,14 @@ public class Signatures {
|
||||||
public final static HashMap<String, String> MD5 = new HashMap<>();
|
public final static HashMap<String, String> MD5 = new HashMap<>();
|
||||||
public final static HashMap<String, String> SHA1 = new HashMap<>();
|
public final static HashMap<String, String> SHA1 = new HashMap<>();
|
||||||
public final static HashMap<String, String> SHA256 = new HashMap<>();
|
public final static HashMap<String, String> SHA256 = new HashMap<>();
|
||||||
|
public final static HashMap<String, String> hex = new HashMap<>();
|
||||||
|
|
||||||
public static boolean available() {
|
public static boolean available() {
|
||||||
return MD5.size() > 0 && SHA1.size() > 0 && SHA256.size() > 0;
|
return MD5.size() > 0 && SHA1.size() > 0 && SHA256.size() > 0 && hex.size() >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSignatureCount() {
|
public static int getSignatureCount() {
|
||||||
return MD5.size() + SHA1.size() + SHA256.size();
|
return MD5.size() + SHA1.size() + SHA256.size() + hex.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
|
|
|
@ -24,7 +24,6 @@ import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
@ -190,4 +189,17 @@ public class Utils {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
|
|
||||||
|
//Credit: https://stackoverflow.com/a/9855338
|
||||||
|
public static String bytesToHex(byte[] bytes) {
|
||||||
|
char[] hexChars = new char[bytes.length * 2];
|
||||||
|
for (int j = 0; j < bytes.length; j++) {
|
||||||
|
int v = bytes[j] & 0xFF;
|
||||||
|
hexChars[j * 2] = hexArray[v >>> 4];
|
||||||
|
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
||||||
|
}
|
||||||
|
return new String(hexChars);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,11 +8,12 @@
|
||||||
android:title="@string/settings_pref_scanner_realtime_enabled"
|
android:title="@string/settings_pref_scanner_realtime_enabled"
|
||||||
android:summary="@string/settings_pref_scanner_realtime_enabled_summary"
|
android:summary="@string/settings_pref_scanner_realtime_enabled_summary"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
<!-- <CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="scanner_realtime_path_apps"
|
android:key="scanner_realtime_path_apps"
|
||||||
android:title="@string/settings_pref_scanner_realtime_path_apps"
|
android:title="@string/settings_pref_scanner_realtime_path_apps"
|
||||||
android:summary="@string/settings_pref_scanner_realtime_path_apps_summary"
|
android:summary="@string/settings_pref_scanner_realtime_path_apps_summary"
|
||||||
android:defaultValue="true" />-->
|
android:defaultValue="true"
|
||||||
|
android:enabled="false" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="scanner_realtime_path_internal"
|
android:key="scanner_realtime_path_internal"
|
||||||
android:title="@string/settings_pref_scanner_realtime_path_internal"
|
android:title="@string/settings_pref_scanner_realtime_path_internal"
|
||||||
|
@ -23,11 +24,12 @@
|
||||||
android:title="@string/settings_pref_scanner_realtime_path_external"
|
android:title="@string/settings_pref_scanner_realtime_path_external"
|
||||||
android:summary="@string/settings_pref_scanner_realtime_path_external_summary"
|
android:summary="@string/settings_pref_scanner_realtime_path_external_summary"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
<!-- <CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="scanner_realtime_path_system"
|
android:key="scanner_realtime_path_system"
|
||||||
android:title="@string/settings_pref_scanner_realtime_path_system"
|
android:title="@string/settings_pref_scanner_realtime_path_system"
|
||||||
android:summary="@string/settings_pref_scanner_realtime_path_system_summary"
|
android:summary="@string/settings_pref_scanner_realtime_path_system_summary"
|
||||||
android:defaultValue="true" />-->
|
android:defaultValue="true"
|
||||||
|
android:enabled="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/settings_category_optimizations">
|
<PreferenceCategory android:title="@string/settings_category_optimizations">
|
||||||
|
@ -35,14 +37,12 @@
|
||||||
android:key="scanner_max_file_size"
|
android:key="scanner_max_file_size"
|
||||||
android:title="@string/settings_pref_optimizations_scanner_max_size"
|
android:title="@string/settings_pref_optimizations_scanner_max_size"
|
||||||
android:summary="@string/settings_pref_optimizations_scanner_max_size_summary"
|
android:summary="@string/settings_pref_optimizations_scanner_max_size_summary"
|
||||||
android:defaultValue="80"
|
|
||||||
android:numeric="integer"
|
android:numeric="integer"
|
||||||
android:inputType="number" />
|
android:inputType="number" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="database_hash_length"
|
android:key="database_hash_length"
|
||||||
android:title="@string/settings_pref_optimizations_database_hash_length"
|
android:title="@string/settings_pref_optimizations_database_hash_length"
|
||||||
android:summary="@string/settings_pref_optimizations_database_hash_length_summary"
|
android:summary="@string/settings_pref_optimizations_database_hash_length_summary"
|
||||||
android:defaultValue="12"
|
|
||||||
android:numeric="integer"
|
android:numeric="integer"
|
||||||
android:inputType="number" />
|
android:inputType="number" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
@ -66,12 +66,13 @@
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<!-- <PreferenceCategory android:title="@string/settings_category_other">
|
<PreferenceCategory android:title="@string/settings_category_other">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="access_third_party"
|
android:key="access_third_party"
|
||||||
android:title="@string/settings_pref_other_third_party"
|
android:title="@string/settings_pref_other_third_party"
|
||||||
android:summary="@string/settings_pref_other_third_party_summary"
|
android:summary="@string/settings_pref_other_third_party_summary"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false"
|
||||||
</PreferenceCategory>-->
|
android:enabled="false" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Add table
Reference in a new issue