Ex2 partially working, unable to access storage

This commit is contained in:
Mariano Sciacco
2021-03-08 17:25:29 +01:00
parent 9c1c8ef14f
commit 676b9b566f
4 changed files with 46 additions and 4 deletions

View File

@@ -9,14 +9,13 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Mobiotsec2filehasher">
<activity android:name=".HashfileActivity">
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HashfileActivity">
<intent-filter>
<action android:name="com.mobiotsec.intent.action.HASHFILE"/>
<category android:name="android.intent.category.DEFAULT" />

View File

@@ -20,6 +20,8 @@ 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();

View File

@@ -2,9 +2,17 @@ package com.example.maliciousapp;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
@Override
@@ -12,6 +20,36 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MOBIOTSEC", "123 HELLOOOOO");
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);
}
}