Added VirusTotal result dialog

This commit is contained in:
M66B 2022-07-23 10:28:22 +02:00
parent dbc8dc5266
commit 1fd5b957e6
3 changed files with 113 additions and 7 deletions

View File

@ -52,8 +52,11 @@ public class VirusTotal {
hash = Helper.getHash(is, "SHA-256");
}
String uri = URI_ENDPOINT + "gui/file/" + hash;
Log.i("VT uri=" + uri);
Bundle result = new Bundle();
result.putString("uri", URI_ENDPOINT + "gui/file/" + hash);
result.putString("uri", uri);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String apikey = prefs.getString("vt_apikey", null);
@ -83,7 +86,10 @@ public class VirusTotal {
throw new FileNotFoundException(error);
}
if (status == HttpsURLConnection.HTTP_OK) {
if (status == HttpsURLConnection.HTTP_NOT_FOUND) {
result.putInt("count", 0);
result.putInt("malicious", 0);
} else {
String response = Helper.readStream(connection.getInputStream());
Log.i("VT response=" + response);
@ -93,8 +99,8 @@ public class VirusTotal {
JSONObject jdata = jroot.getJSONObject("data");
JSONObject jattributes = jdata.getJSONObject("attributes");
JSONObject jclassification = jattributes.getJSONObject("popular_threat_classification");
String label = jclassification.getString("suggested_threat_label");
JSONObject jclassification = jattributes.optJSONObject("popular_threat_classification");
String label = (jclassification == null ? null : jclassification.getString("suggested_threat_label"));
int count = 0;
int malicious = 0;
@ -111,11 +117,11 @@ public class VirusTotal {
malicious++;
}
Log.i("VT label=" + label + " " + malicious + "/" + count);
Log.i("VT analysis=" + malicious + "/" + count + " label=" + label);
result.putString("label", label);
result.putInt("count", count);
result.putInt("malicious", malicious);
result.putString("label", label);
}
} finally {
connection.disconnect();

View File

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
@ -36,6 +37,7 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
@ -330,7 +332,38 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
@Override
protected void onExecuted(Bundle args, Bundle result) {
String uri = result.getString("uri");
Helper.view(context, Uri.parse(uri), true);
int count = result.getInt("count", -1);
int malicious = result.getInt("malicious", -1);
String label = result.getString("label");
if (count < 0) {
Helper.view(context, Uri.parse(uri), true);
return;
}
View view = LayoutInflater.from(context).inflate(R.layout.dialog_virus_total, null);
final TextView tvName = view.findViewById(R.id.tvName);
final ProgressBar pbAnalysis = view.findViewById(R.id.pbAnalysis);
final TextView tvAnalysis = view.findViewById(R.id.tvAnalysis);
final TextView tvLabel = view.findViewById(R.id.tvLabel);
tvName.setText(attachment.name);
pbAnalysis.setMax(count);
pbAnalysis.setProgress(malicious);
tvAnalysis.setText(malicious + "/" + count);
tvLabel.setText(label);
tvLabel.setVisibility(TextUtils.isEmpty(label) ? View.GONE : View.VISIBLE);
new AlertDialog.Builder(context)
.setView(view)
.setPositiveButton(R.string.title_info, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Helper.view(context, Uri.parse(uri), true);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
@Override

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/twotone_travel_explore_24"
android:drawablePadding="6dp"
android:text="VirusTotal"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="File name"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<ProgressBar
android:id="@+id/pbAnalysis"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="6dp"
android:progress="50"
android:scaleY="3"
app:layout_constraintEnd_toStartOf="@+id/tvAnalysis"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
<TextView
android:id="@+id/tvAnalysis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="10/100"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/pbAnalysis"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/tvLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Label"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAnalysis" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>