mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-02-28 21:38:21 +03:00
Add database downloading
This commit is contained in:
parent
cb7cca49c6
commit
a8df8fe3c1
7 changed files with 134 additions and 22 deletions
|
@ -2,6 +2,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="us.spotco.veritas">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
|
|
@ -1,4 +1,106 @@
|
|||
package us.spotco.veritas;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class Database {
|
||||
|
||||
private static Context context = null;
|
||||
private static TextView log = null;
|
||||
private static MenuItem databaseUpdateCheckOption = null;
|
||||
private static File databasePath = null;
|
||||
private static String databaseName = "clamav-main.hsb";
|
||||
private static final String databaseUpdateURL = "https://spotco.us/clamav-main.hsb";
|
||||
|
||||
public Database(Context context, TextView log, MenuItem databaseUpdateCheckOption) {
|
||||
this.context = context;
|
||||
this.log = log;
|
||||
this.databaseUpdateCheckOption = databaseUpdateCheckOption;
|
||||
databasePath = new File(context.getFilesDir() + databaseName);
|
||||
}
|
||||
|
||||
public static boolean doesDatabaseExist() {
|
||||
return databasePath.exists();
|
||||
}
|
||||
|
||||
public static boolean shouldUpdateDatabase() {
|
||||
return databaseUpdateCheckOption.isChecked();
|
||||
}
|
||||
|
||||
public static void updateDatabase() {
|
||||
new Downloader().execute(databaseUpdateURL, databasePath.toString());
|
||||
}
|
||||
|
||||
public static void loadDatabase() {
|
||||
//Database format: md5, size, name, unknown
|
||||
}
|
||||
|
||||
public static String checkInDatabase(String hash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Downloader extends AsyncTask<String, String, String> {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... strings) {
|
||||
String url = strings[0];
|
||||
File out = new File(strings[1]);
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setConnectTimeout(45000);
|
||||
connection.setReadTimeout(45000);
|
||||
connection.addRequestProperty("User-Agent", "Veritas Database Updater");
|
||||
if (out.exists()) {
|
||||
connection.setIfModifiedSince(out.lastModified());
|
||||
}
|
||||
connection.connect();
|
||||
int res = connection.getResponseCode();
|
||||
if (res != 304) {
|
||||
if(res == 200) {
|
||||
if (out.exists()) {
|
||||
out.delete();
|
||||
}
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(out);
|
||||
|
||||
final byte data[] = new byte[1024];
|
||||
int count;
|
||||
while ((count = connection.getInputStream().read(data, 0, 1024)) != -1) {
|
||||
fileOutputStream.write(data, 0, count);
|
||||
}
|
||||
|
||||
fileOutputStream.close();
|
||||
publishProgress("Successfully downloaded " + url + "\n");
|
||||
} else {
|
||||
publishProgress("File not downloaded " + res + "\n");
|
||||
}
|
||||
} else {
|
||||
publishProgress("File not changed " + url + "\n");
|
||||
}
|
||||
connection.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
publishProgress("Failed to download file from " + url + "\n");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(String... progress) {
|
||||
log.append(progress[0] + "\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Bundle;
|
|||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -24,10 +25,15 @@ public class MainActivity extends AppCompatActivity {
|
|||
setSupportActionBar(toolbar);
|
||||
|
||||
TextView logView = findViewById(R.id.txtLogOutput);
|
||||
logView.setMovementMethod(new ScrollingMovementMethod());
|
||||
logView.append("Copyright 2017 Spot Communications, Inc.\n");
|
||||
logView.append("License: GPLv3\n");
|
||||
logView.append("Powered by ClamAV signatures, License: GPLv3\n");
|
||||
logView.append("\nDisclaimer: This is an extremely basic signature scanner\n\n");
|
||||
|
||||
MenuItem databaseUpdateCheckOption = findViewById(R.id.mnuUpdateDatabase);
|
||||
|
||||
final Database database = new Database(this, logView, databaseUpdateCheckOption);
|
||||
final MalwareScanner scanner = new MalwareScanner(this, logView);
|
||||
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
|
|
|
@ -24,7 +24,12 @@ public class MalwareScanner {
|
|||
}
|
||||
|
||||
public void startScanner(boolean scanSystem, boolean scanApps, boolean scanInternal, boolean scanExternal) {
|
||||
malwareScannerTask = new MalwareScannerTask().execute(scanSystem, scanApps, scanInternal, scanExternal);
|
||||
if(Database.doesDatabaseExist()) {
|
||||
malwareScannerTask = new MalwareScannerTask().execute(scanSystem, scanApps, scanInternal, scanExternal);
|
||||
} else {
|
||||
log.append("No database found... downloading!\n");
|
||||
Database.updateDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopScanner() {
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtLogOutput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="us.spotco.veritas.MainActivity"
|
||||
tools:showIn="@layout/activity_main">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtLogOutput"
|
||||
android:layout_width="350dp"
|
||||
android:layout_height="450dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text=""
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
android:text=""
|
||||
android:scrollbars="vertical"
|
||||
android:maxLines="5000"
|
||||
android:gravity="bottom" />
|
||||
</LinearLayout>
|
|
@ -3,6 +3,11 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="us.spotco.veritas.MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/mnuUpdateDatabase"
|
||||
android:title="@string/lblUpdateDatabase"
|
||||
android:checkable="true"
|
||||
android:checked="true" />
|
||||
<item
|
||||
android:id="@+id/mnuScanSystem"
|
||||
android:title="@string/lblScanSystem"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<resources>
|
||||
<string name="app_name">Veritas</string>
|
||||
<string name="lblUpdateDatabase">Update database</string>
|
||||
<string name="lblScanSystem">Scan /system</string>
|
||||
<string name="lblScanApps">Scan App APKs</string>
|
||||
<string name="lblScanInternal">Scan Internal Storage</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue