From 676b9b566f4ab80fc25cee2d325c72e9c184aa27 Mon Sep 17 00:00:00 2001 From: Mariano Sciacco <34033090+Maxelweb@users.noreply.github.com> Date: Mon, 8 Mar 2021 17:25:29 +0100 Subject: [PATCH] Ex2 partially working, unable to access storage --- .../app/src/main/AndroidManifest.xml | 5 +-- .../maliciousapp/HashfileActivity.java | 2 + .../example/maliciousapp/MainActivity.java | 40 ++++++++++++++++++- .../filehasher/filehasher_logs.txt | 3 ++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/mobiotsec2filehasher/app/src/main/AndroidManifest.xml b/mobiotsec2filehasher/app/src/main/AndroidManifest.xml index 8463bfe..5067315 100644 --- a/mobiotsec2filehasher/app/src/main/AndroidManifest.xml +++ b/mobiotsec2filehasher/app/src/main/AndroidManifest.xml @@ -9,14 +9,13 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Mobiotsec2filehasher"> - - - + + diff --git a/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/HashfileActivity.java b/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/HashfileActivity.java index eca4154..0a3b562 100644 --- a/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/HashfileActivity.java +++ b/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/HashfileActivity.java @@ -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(); diff --git a/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/MainActivity.java b/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/MainActivity.java index dd2c101..b570f35 100644 --- a/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/MainActivity.java +++ b/mobiotsec2filehasher/app/src/main/java/com/example/maliciousapp/MainActivity.java @@ -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); + } } \ No newline at end of file diff --git a/mobiotsec2filehasher/filehasher/filehasher_logs.txt b/mobiotsec2filehasher/filehasher/filehasher_logs.txt index 2dd604b..09796d4 100644 --- a/mobiotsec2filehasher/filehasher/filehasher_logs.txt +++ b/mobiotsec2filehasher/filehasher/filehasher_logs.txt @@ -1,3 +1,6 @@ --------- beginning of main --------- beginning of system --------- beginning of kernel +03-08 16:23:39.191 8344 8344 I MOBIOTSEC: /storage/emulated/0/YM3oPnYG.dat +03-08 16:23:40.933 8372 8372 D MOBIOTSEC: Activity called oh yes +03-08 16:23:40.933 8372 8372 D MOBIOTSEC: HELLOOOOO