Ex2 done
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.maliciousapp">
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
package com.example.maliciousapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class HashfileActivity extends AppCompatActivity {
|
||||
@@ -20,33 +28,66 @@ public class HashfileActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_hashfile);
|
||||
|
||||
Log.d("MOBIOTSEC", "Activity called oh yes");
|
||||
|
||||
Intent intent = getIntent();
|
||||
String filePath = intent.getData().getPath();
|
||||
Log.d("MOBIOTSEC", "Activity called..");
|
||||
|
||||
// calculate hash
|
||||
String hash = calcHash(filePath);
|
||||
Intent intent = getIntent();
|
||||
String filePath = intent.getData().getEncodedPath();
|
||||
|
||||
// return the hash in a "result" intent
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("hash", hash);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
// calculate hash
|
||||
String hash = calcHash(filePath);
|
||||
|
||||
// return the hash in a "result" intent
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("hash", hash);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
|
||||
Log.d("MOBIOTSEC", "Activity finished..");
|
||||
}
|
||||
|
||||
static public String calcHash(String filePath) {
|
||||
File file = new File(filePath);
|
||||
byte[] bytes = new byte[0];
|
||||
Log.d("MOBIOTSEC", "HELLOOOOO");
|
||||
try {
|
||||
bytes = FileUtils.readFileToByteArray(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
public String calcHash(String filePath) {
|
||||
|
||||
if (this.isStoragePermissionGranted()) {
|
||||
|
||||
File file = new File(filePath);
|
||||
int size = (int) file.length();
|
||||
byte[] bytes = new byte[size];
|
||||
try {
|
||||
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
|
||||
buf.read(bytes, 0, bytes.length);
|
||||
buf.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DigestUtils.sha256Hex(bytes);
|
||||
}
|
||||
return DigestUtils.sha256Hex(bytes);
|
||||
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public boolean isStoragePermissionGranted() {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d("MOBIOTSEC", "Permission is granted");
|
||||
return true;
|
||||
} else {
|
||||
|
||||
Log.d("MOBIOTSEC", "Permission is revoked");
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
|
||||
return false;
|
||||
}
|
||||
} else { //permission is automatically granted on sdk<23 upon installation
|
||||
Log.d("MOBIOTSEC", "Permission is granted");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.example.maliciousapp;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -19,37 +23,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Intent intent = getIntent();
|
||||
Log.d("MOBIOTSEC", intent.toString());
|
||||
Log.d("MOBIOTSEC", "ACTION = " + intent.getAction());
|
||||
|
||||
if(intent.getAction() != null) {
|
||||
String filePath = intent.getData().getPath();
|
||||
|
||||
// calculate hash
|
||||
String hash = calcHash(filePath);
|
||||
|
||||
// return the hash in a "result" intent
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("hash", hash);
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
Log.d("MOBIOTSEC", "123 END HELLOOOOO");
|
||||
}
|
||||
|
||||
static public String calcHash(String filePath) {
|
||||
File file = new File(filePath);
|
||||
byte[] bytes = new byte[0];
|
||||
Log.d("MOBIOTSEC", "HELLOOOOO");
|
||||
try {
|
||||
bytes = FileUtils.readFileToByteArray(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DigestUtils.sha256Hex(bytes);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user