mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +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"
|
applicationId "us.spotco.malwarescanner"
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 32
|
targetSdkVersion 32
|
||||||
versionCode 90
|
versionCode 91
|
||||||
versionName "2.27"
|
versionName "2.28"
|
||||||
resConfigs 'en', 'af', 'de', 'es', 'fi', 'fr', 'it', 'pl', 'pt', 'ru'
|
resConfigs 'en', 'af', 'de', 'es', 'fi', 'fr', 'it', 'pl', 'pt', 'ru'
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
|
@ -139,7 +139,7 @@ class Database {
|
||||||
if (line.length() > 0) {
|
if (line.length() > 0) {
|
||||||
String[] lineS = line.split(":");
|
String[] lineS = line.split(":");
|
||||||
if (lineS[0].length() > 0) {
|
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) {
|
if (line.length() > 0) {
|
||||||
String[] lineS = line.split(":");
|
String[] lineS = line.split(":");
|
||||||
if (lineS[0].length() == 32) {
|
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) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.gc();
|
||||||
}
|
}
|
||||||
signaturesMD5.put("44d88612fea8a8f36de82e1278abb02f".substring(0, Utils.MAX_HASH_LENGTH), "Eicar-Test-Signature");
|
signaturesMD5.put("44d88612fea8a8f36de82e1278abb02f".substring(0, Utils.MAX_HASH_LENGTH), "Eicar-Test-Signature");
|
||||||
signaturesSHA256.put("6a0b4866f143c32e651662cebf7f380d27b0db809db3b6a34cf34c7436ab6bbf".substring(0, Utils.MAX_HASH_LENGTH), "Hypatia-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 int MAX_SCAN_SIZE_REALTIME = MAX_SCAN_SIZE / 2; //40MB
|
||||||
public final static String DATABASE_URL_DEFAULT = "https://divested.dev/MalwareScannerSignatures/";
|
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();
|
public static final AtomicInteger FILES_SCANNED = new AtomicInteger();
|
||||||
private static ThreadPoolExecutor threadPoolExecutor = null;
|
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)
|
#Description: Hypatia conversion script for ClamAV databases (GPL-2.0)
|
||||||
|
|
||||||
#sudo -i freshclam
|
#sudo -i freshclam
|
||||||
|
origDir="$PWD"
|
||||||
mkdir /tmp/mss
|
mkdir /tmp/mss
|
||||||
|
mkdir /tmp/mss/optimized
|
||||||
mkdir /tmp/mss/processed
|
mkdir /tmp/mss/processed
|
||||||
cd /tmp/mss
|
cd /tmp/mss
|
||||||
cp /var/lib/clamav/main.c*d .
|
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");
|
databases=("Android.hdb" "Android.hsb" "main.hdb" "main.hsb" "daily.hdb" "daily.hsb");
|
||||||
for db in "${databases[@]}"
|
for db in "${databases[@]}"
|
||||||
do
|
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;
|
done;
|
||||||
|
|
||||||
gzip /tmp/mss/*.hdb
|
gzip -k /tmp/mss/*.hdb
|
||||||
gzip /tmp/mss/*.hsb
|
gzip -k /tmp/mss/*.hsb
|
||||||
gzip /tmp/mss/processed/*.hdb
|
gzip -k /tmp/mss/processed/*.hdb
|
||||||
gzip /tmp/mss/processed/*.hsb
|
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