mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-02-28 21:38:21 +03:00
Various optimizations
- Trim hashes to 8 characters instead of 12. Saves ~10MB by default. - Optimized databases. Saves ~8MB by default. - Deduplicated strings. Saves ~12MB by default. idle usage on arm64 - With defaults: ~165MB, previously ~195MB - With all databases: ~350MB, previously ~650MB Signed-off-by: Tad <tad@spotco.us>
This commit is contained in:
parent
7d774092c6
commit
745d70ced5
6 changed files with 26 additions and 11 deletions
|
@ -6,8 +6,8 @@ android {
|
|||
applicationId "us.spotco.malwarescanner"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 32
|
||||
versionCode 90
|
||||
versionName "2.27"
|
||||
versionCode 91
|
||||
versionName "2.28"
|
||||
resConfigs 'en', 'af', 'de', 'es', 'fi', 'fr', 'it', 'pl', 'pt', 'ru'
|
||||
}
|
||||
buildTypes {
|
||||
|
|
|
@ -139,7 +139,7 @@ class Database {
|
|||
if (line.length() > 0) {
|
||||
String[] lineS = line.split(":");
|
||||
if (lineS[0].length() > 0) {
|
||||
signaturesMD5.put(lineS[0].substring(0, Utils.MAX_HASH_LENGTH), lineS[2]);
|
||||
signaturesMD5.put(lineS[0].substring(0, Utils.MAX_HASH_LENGTH), lineS[2].intern());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,9 +148,9 @@ class Database {
|
|||
if (line.length() > 0) {
|
||||
String[] lineS = line.split(":");
|
||||
if (lineS[0].length() == 32) {
|
||||
signaturesSHA1.put(lineS[0].substring(0, Utils.MAX_HASH_LENGTH), lineS[2]);
|
||||
signaturesSHA1.put(lineS[0].substring(0, Utils.MAX_HASH_LENGTH), lineS[2].intern());
|
||||
} else if (lineS[0].length() > 0) {
|
||||
signaturesSHA256.put(lineS[0].substring(0, Utils.MAX_HASH_LENGTH), lineS[2]);
|
||||
signaturesSHA256.put(lineS[0].substring(0, Utils.MAX_HASH_LENGTH), lineS[2].intern());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ class Database {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
signaturesMD5.put("44d88612fea8a8f36de82e1278abb02f".substring(0, Utils.MAX_HASH_LENGTH), "Eicar-Test-Signature");
|
||||
signaturesSHA256.put("6a0b4866f143c32e651662cebf7f380d27b0db809db3b6a34cf34c7436ab6bbf".substring(0, Utils.MAX_HASH_LENGTH), "Hypatia-Test-Signature");
|
||||
|
|
|
@ -39,7 +39,7 @@ class Utils {
|
|||
public final static int MAX_SCAN_SIZE_REALTIME = MAX_SCAN_SIZE / 2; //40MB
|
||||
public final static String DATABASE_URL_DEFAULT = "https://divested.dev/MalwareScannerSignatures/";
|
||||
|
||||
public final static int MAX_HASH_LENGTH = 12;
|
||||
public final static int MAX_HASH_LENGTH = 8;
|
||||
|
||||
public static final AtomicInteger FILES_SCANNED = new AtomicInteger();
|
||||
private static ThreadPoolExecutor threadPoolExecutor = null;
|
||||
|
|
1
fastlane/metadata/android/en-US/changelogs/91.txt
Normal file
1
fastlane/metadata/android/en-US/changelogs/91.txt
Normal file
|
@ -0,0 +1 @@
|
|||
* Various memory optimizations
|
|
@ -3,7 +3,9 @@
|
|||
#Description: Hypatia conversion script for ClamAV databases (GPL-2.0)
|
||||
|
||||
#sudo -i freshclam
|
||||
origDir="$PWD"
|
||||
mkdir /tmp/mss
|
||||
mkdir /tmp/mss/optimized
|
||||
mkdir /tmp/mss/processed
|
||||
cd /tmp/mss
|
||||
cp /var/lib/clamav/main.c*d .
|
||||
|
@ -30,10 +32,13 @@ grep "Multios\\." daily.hsb >> Android.hsb
|
|||
databases=("Android.hdb" "Android.hsb" "main.hdb" "main.hsb" "daily.hdb" "daily.hsb");
|
||||
for db in "${databases[@]}"
|
||||
do
|
||||
sort --parallel=$(nproc) --unique "$db" --output processed/"$db";
|
||||
#remove unnecessary bits to reduce file size and app memory usage
|
||||
python "$origDir"/optimize.py "$db" >> optimized/"$db";
|
||||
#sort to increase compression efficiency
|
||||
sort -k3 -t ":" --parallel=$(nproc) --output processed/"$db" optimized/"$db";
|
||||
done;
|
||||
|
||||
gzip /tmp/mss/*.hdb
|
||||
gzip /tmp/mss/*.hsb
|
||||
gzip /tmp/mss/processed/*.hdb
|
||||
gzip /tmp/mss/processed/*.hsb
|
||||
gzip -k /tmp/mss/*.hdb
|
||||
gzip -k /tmp/mss/*.hsb
|
||||
gzip -k /tmp/mss/processed/*.hdb
|
||||
gzip -k /tmp/mss/processed/*.hsb
|
||||
|
|
8
scripts/optimize.py
Executable file
8
scripts/optimize.py
Executable file
|
@ -0,0 +1,8 @@
|
|||
import sys
|
||||
|
||||
database = open(sys.argv[1], "r");
|
||||
for line in database:
|
||||
arrSplit = line.strip().split(":");
|
||||
strHash = arrSplit[0];
|
||||
strName = arrSplit[2].split("-")[0];
|
||||
print(strHash + ":0:" + strName);
|
Loading…
Add table
Reference in a new issue