|
|
@ -30,6 +30,7 @@ import android.text.TextUtils;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
@ -319,78 +320,155 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
String apiKey = prefs.getString("vt_apikey", null);
|
|
|
|
String apiKey = prefs.getString("vt_apikey", null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 tvCount = view.findViewById(R.id.tvCount);
|
|
|
|
|
|
|
|
final TextView tvLabel = view.findViewById(R.id.tvLabel);
|
|
|
|
|
|
|
|
final TextView tvUnknown = view.findViewById(R.id.tvUnknown);
|
|
|
|
|
|
|
|
final Button btnUpload = view.findViewById(R.id.btnUpload);
|
|
|
|
|
|
|
|
final ProgressBar pbUpload = view.findViewById(R.id.pbUpload);
|
|
|
|
|
|
|
|
final ProgressBar pbWait = view.findViewById(R.id.pbWait);
|
|
|
|
|
|
|
|
final TextView tvAnalyzing = view.findViewById(R.id.tvAnalyzing);
|
|
|
|
|
|
|
|
final Group grpAnalysis = view.findViewById(R.id.grpAnalysis);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tvName.setText(attachment.name);
|
|
|
|
|
|
|
|
tvLabel.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
tvUnknown.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
btnUpload.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
pbUpload.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
tvAnalyzing.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
grpAnalysis.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putSerializable("file", attachment.getFile(context));
|
|
|
|
|
|
|
|
args.putString("apiKey", apiKey);
|
|
|
|
args.putString("apiKey", apiKey);
|
|
|
|
|
|
|
|
args.putSerializable("file", attachment.getFile(context));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final SimpleTask<Bundle> taskLookup = new SimpleTask<Bundle>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onPreExecute(Bundle args) {
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onPostExecute(Bundle args) {
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Bundle>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Bundle onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
protected Bundle onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
File file = (File) args.getSerializable("file");
|
|
|
|
|
|
|
|
String apiKey = args.getString("apiKey");
|
|
|
|
String apiKey = args.getString("apiKey");
|
|
|
|
|
|
|
|
File file = (File) args.getSerializable("file");
|
|
|
|
return VirusTotal.lookup(context, file, apiKey);
|
|
|
|
return VirusTotal.lookup(context, file, apiKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Bundle result) {
|
|
|
|
protected void onExecuted(Bundle args, Bundle result) {
|
|
|
|
String uri = result.getString("uri");
|
|
|
|
|
|
|
|
int count = result.getInt("count", -1);
|
|
|
|
int count = result.getInt("count", -1);
|
|
|
|
int malicious = result.getInt("malicious", -1);
|
|
|
|
int malicious = result.getInt("malicious", -1);
|
|
|
|
String label = result.getString("label");
|
|
|
|
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 tvCount = view.findViewById(R.id.tvCount);
|
|
|
|
|
|
|
|
final TextView tvLabel = view.findViewById(R.id.tvLabel);
|
|
|
|
|
|
|
|
final TextView tvUnknown = view.findViewById(R.id.tvUnknown);
|
|
|
|
|
|
|
|
final Group grpAnalysis = view.findViewById(R.id.grpAnalysis);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tvName.setText(attachment.name);
|
|
|
|
|
|
|
|
pbAnalysis.setMax(count);
|
|
|
|
pbAnalysis.setMax(count);
|
|
|
|
pbAnalysis.setProgress(malicious);
|
|
|
|
pbAnalysis.setProgress(malicious);
|
|
|
|
tvCount.setText(malicious + "/" + count);
|
|
|
|
tvCount.setText(malicious + "/" + count);
|
|
|
|
tvLabel.setText(label);
|
|
|
|
tvLabel.setText(label);
|
|
|
|
tvLabel.setVisibility(TextUtils.isEmpty(label) ? View.GONE : View.VISIBLE);
|
|
|
|
tvLabel.setVisibility(TextUtils.isEmpty(label) ? View.GONE : View.VISIBLE);
|
|
|
|
tvUnknown.setVisibility(count == 0 ? View.VISIBLE : View.GONE);
|
|
|
|
tvUnknown.setVisibility(count == 0 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
btnUpload.setVisibility(count == 0 && !TextUtils.isEmpty(apiKey) ? View.VISIBLE : View.GONE);
|
|
|
|
grpAnalysis.setVisibility(count == 0 ? View.GONE : View.VISIBLE);
|
|
|
|
grpAnalysis.setVisibility(count == 0 ? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
|
|
|
|
|
|
|
.setView(view)
|
|
|
|
|
|
|
|
.setPositiveButton(R.string.title_info, new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Helper.view(context, Uri.parse(uri), true);
|
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(apiKey) && BuildConfig.DEBUG)
|
|
|
|
final SimpleTask<Void> taskUpload = new SimpleTask<Void>() {
|
|
|
|
builder.setNeutralButton("Upload", new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
protected void onPreExecute(Bundle args) {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
btnUpload.setEnabled(false);
|
|
|
|
|
|
|
|
pbUpload.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onPostExecute(Bundle args) {
|
|
|
|
|
|
|
|
btnUpload.setEnabled(true);
|
|
|
|
|
|
|
|
tvAnalyzing.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
pbUpload.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
File file = (File) args.getSerializable("file");
|
|
|
|
|
|
|
|
String apiKey = args.getString("apiKey");
|
|
|
|
String apiKey = args.getString("apiKey");
|
|
|
|
VirusTotal.upload(context, file, apiKey);
|
|
|
|
File file = (File) args.getSerializable("file");
|
|
|
|
|
|
|
|
VirusTotal.upload(context, file, apiKey, new Runnable() {
|
|
|
|
|
|
|
|
private int step = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
postProgress(Integer.toString(++step));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onProgress(CharSequence status, Bundle data) {
|
|
|
|
|
|
|
|
tvAnalyzing.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
|
|
|
|
taskLookup.execute(context, owner, args, "attachment:lookup");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "attachment:upload");
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final SimpleTask<String> taskUrl = new SimpleTask<String>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected String onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
|
|
|
|
File file = (File) args.getSerializable("file");
|
|
|
|
|
|
|
|
return VirusTotal.getUrl(file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onExecuted(Bundle args, String uri) {
|
|
|
|
|
|
|
|
Helper.view(context, Uri.parse(uri), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btnUpload.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
taskUpload.execute(context, owner, args, "attachment:upload");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(apiKey))
|
|
|
|
|
|
|
|
taskLookup.execute(context, owner, args, "attachment:lookup");
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
pbWait.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
|
|
|
|
|
|
|
.setView(view)
|
|
|
|
|
|
|
|
.setPositiveButton(R.string.title_info, new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
|
|
|
|
taskUrl.execute(context, owner, args, "attachment:virustotal");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
|
|
|
@ -403,13 +481,6 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.execute(context, owner, args, "attachment:scan");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onShare(EntityAttachment attachment) {
|
|
|
|
private void onShare(EntityAttachment attachment) {
|
|
|
|
String title = (attachment.name == null ? attachment.cid : attachment.name);
|
|
|
|
String title = (attachment.name == null ? attachment.cid : attachment.name);
|
|
|
|
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);
|
|
|
|
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);
|
|
|
|