Replacing other files ex2
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?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"/>
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@@ -11,16 +11,16 @@
|
||||
android:theme="@style/Theme.Mobiotsec2filehasher">
|
||||
<activity android:name=".HashfileActivity">
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="com.mobisec.intent.action.HASHFILE" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -2,7 +2,16 @@ 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 HashfileActivity extends AppCompatActivity {
|
||||
|
||||
@@ -10,5 +19,47 @@ public class HashfileActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_hashfile);
|
||||
|
||||
Log.d("MOBIOTSEC", "PROVA 0");
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
Log.d("MOBIOTSEC", "PROVA 1");
|
||||
|
||||
//if(intent.getAction() == "com.mobiotsec.intent.action.HASHFILE") {
|
||||
|
||||
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 {
|
||||
File file = new File(filePath);
|
||||
if(file.exists()) {
|
||||
Log.d("MOBIOTSEC", "PROVA 3");
|
||||
return DigestUtils.sha256Hex(FileUtils.readFileToByteArray(file));
|
||||
}
|
||||
else
|
||||
Log.d("MOBIOTSEC", "Errore");
|
||||
|
||||
return "prova";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user