Other edits ex2

This commit is contained in:
Mariano Sciacco
2021-03-08 16:51:04 +01:00
parent 6ddfaf5d97
commit 9c1c8ef14f
5 changed files with 27 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

View File

@@ -10,17 +10,19 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Mobiotsec2filehasher"> android:theme="@style/Theme.Mobiotsec2filehasher">
<activity android:name=".HashfileActivity"> <activity android:name=".HashfileActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.mobiotsec.intent.action.HASHFILE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> </activity>
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="com.mobiotsec.intent.action.HASHFILE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:scheme="file" />
</intent-filter>
</activity> </activity>
</application> </application>
</manifest> </manifest>

View File

@@ -20,41 +20,30 @@ public class HashfileActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hashfile); setContentView(R.layout.activity_hashfile);
Log.d("MOBIOTSEC", "PROVA 0");
Intent intent = getIntent(); Intent intent = getIntent();
String filePath = intent.getData().getPath();
Log.d("MOBIOTSEC", "PROVA 1"); // calculate hash
Log.d("MOBIOTSEC", intent.getAction()); String hash = calcHash(filePath);
if(intent.getAction() == "com.mobiotsec.intent.action.HASHFILE") { // return the hash in a "result" intent
Intent resultIntent = new Intent();
resultIntent.putExtra("hash", hash);
setResult(Activity.RESULT_OK, resultIntent);
finish();
String filePath = intent.getData().getPath();
Log.d("MOBIOTSEC", filePath);
// calculate hash
String hash = null;
try {
hash = calcHash(filePath);
// return the hash in a "result" intent
Intent resultIntent = new Intent();
resultIntent.putExtra("hash", hash);
setResult(Activity.RESULT_OK, resultIntent);
finish();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
static public String calcHash(String filePath) throws IOException { static public String calcHash(String filePath) {
File file = new File(filePath); File file = new File(filePath);
Log.d("MOBIOTSEC", "PROVA 3"); byte[] bytes = new byte[0];
byte[] bytes = FileUtils.readFileToByteArray(file); Log.d("MOBIOTSEC", "HELLOOOOO");
Log.d("MOBIOTSEC", "PROVA 4"); try {
bytes = FileUtils.readFileToByteArray(file);
} catch (IOException e) {
e.printStackTrace();
}
return DigestUtils.sha256Hex(bytes); return DigestUtils.sha256Hex(bytes);
} }

View File

@@ -3,6 +3,7 @@ package com.example.maliciousapp;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@@ -10,5 +11,7 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
Log.d("MOBIOTSEC", "123 HELLOOOOO");
} }
} }

View File

@@ -1,5 +1,3 @@
--------- beginning of main --------- beginning of main
--------- beginning of system --------- beginning of system
--------- beginning of kernel --------- beginning of kernel
03-04 14:10:11.909 15435 15435 I MOBIOTSEC: /storage/emulated/0/YM3oPnYG.dat
--------- beginning of crash