// Path: app/src/main/java/fuzion24/device/vulnerability/util/SharedPreferencesUtils.java
// public class SharedPreferencesUtils {
// 
//     private static final String PREFS_LAST_LIST_OF_SCANS = "PREFS_LIST_OF_SCANS";
//     private static final String PREFS_FIRST_RUN = "PREFS_FIRST_RUN";
//     private static final String PREFS_AUTOMATIC_SHARING_ENABLE = "PREFS_AUTOMATIC_SHARING_ENABLE";
//     private static final String BUILD_FINGERPRINT_HASH   = "BUILD_FINGERPRINT_HASH";
// 
// 
//     private static final String PREFS_NAME = "com.nowsecure.android.vts.PREFERENCE_FILE_KEY";
// 
//     private SharedPreferencesUtils() {
//     }
// 
//     private static SharedPreferences getPreferences(Context context) {
//         return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
//     }
// 
//     public static Boolean isAutomaticSharingEnable(Context context) {
//         return  getPreferences(context).getBoolean(PREFS_AUTOMATIC_SHARING_ENABLE, false);
//     }
// 
//     public static void setIsAutomaticSharingEnable(Context context, Boolean isAutomaticSharingEnable) {
//         getPreferences(context).edit().putBoolean(PREFS_AUTOMATIC_SHARING_ENABLE, isAutomaticSharingEnable).commit();
//     }
// 
//     public static Boolean isTheFirstRun(Context context) {
//         return getPreferences(context).getBoolean(PREFS_FIRST_RUN, true);
//     }
// 
//     public static void disableFirstRun(Context context) {
//         getPreferences(context).edit().putBoolean(PREFS_FIRST_RUN, false).commit();
//     }
// 
// 
//     public static List<String> getTheListOfScansAvailable(Context context) {
//         Set<String> listOfPreviousScans = getPreferences(context).getStringSet(PREFS_LAST_LIST_OF_SCANS, null);
// 
//         if (listOfPreviousScans == null) {
//             return null;
//         }
// 
//         List<String> listOfScans = Arrays.asList(listOfPreviousScans.toArray(new String[listOfPreviousScans.size()]));
// 
//         return listOfScans;
//     }
// 
//     public static void setTheListOfScansAvailable(Context context, List<String> listOfScans) {
//         SharedPreferences.Editor editor = getPreferences(context).edit();
// 
//         editor.putStringSet(PREFS_LAST_LIST_OF_SCANS, new HashSet<>(listOfScans));
// 
//         editor.apply();
//     }
// 
//     public static void setBuildUpdateFingerPrint(Context context, String fingerprint){
//         SharedPreferences.Editor editor = getPreferences(context).edit();
// 
//         editor.putString(BUILD_FINGERPRINT_HASH, fingerprint);
// 
//         editor.apply();
//     }
// 
//     public static String getBuildUpdateFingerprint(Context context){
//         return getPreferences(context).getString(BUILD_FINGERPRINT_HASH, null);
//     }
// 
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Base64;
import java.io.File;
import java.security.MessageDigest;
import java.util.HashSet;
import java.util.Scanner;
import fuzion24.device.vulnerability.util.SharedPreferencesUtils;
package fuzion24.device.vulnerability.vulnerabilities.helper;




/**
 * Created by fuzion24 on 12/4/15.
 */
public class DeviceUpdateChecker {
    private DeviceUpdateChecker() {
    }

    public static boolean wasDeviceUpdated(Context ctx){

        /*
            Take a hash of the build.prop and /proc/version
            If this changes, assume the device has been updated
        */
        String buildPropFile = readFile("/system/build.prop");
        String procVersion   = readFile("/proc/version");

        String fingerprint = hashString(buildPropFile + procVersion);
        String lastFingerprint = SharedPreferencesUtils.getBuildUpdateFingerprint(ctx);
        if(fingerprint.equals(lastFingerprint)){
            return false;
        } else {
            SharedPreferencesUtils.setBuildUpdateFingerPrint(ctx, fingerprint);
            return true;
        }
    }

    private static String hashString(String data){
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(data.getBytes());
            byte[] hash = md.digest();
            return Base64.encodeToString(hash, Base64.DEFAULT);
        } catch (Exception e) {
            return "";
        }
    }

    private static String readFile(String filename){
        try {
            return new Scanner(new File(filename)).useDelimiter("\\Z").next();
// Path: app/src/main/java/fuzion24/device/vulnerability/util/SharedPreferencesUtils.java
// public class SharedPreferencesUtils {
// 
//     private static final String PREFS_LAST_LIST_OF_SCANS = "PREFS_LIST_OF_SCANS";
//     private static final String PREFS_FIRST_RUN = "PREFS_FIRST_RUN";
//     private static final String PREFS_AUTOMATIC_SHARING_ENABLE = "PREFS_AUTOMATIC_SHARING_ENABLE";
//     private static final String BUILD_FINGERPRINT_HASH   = "BUILD_FINGERPRINT_HASH";
// 
// 
//     private static final String PREFS_NAME = "com.nowsecure.android.vts.PREFERENCE_FILE_KEY";
// 
//     private SharedPreferencesUtils() {
//     }
// 
//     private static SharedPreferences getPreferences(Context context) {
//         return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
//     }
// 
//     public static Boolean isAutomaticSharingEnable(Context context) {
//         return  getPreferences(context).getBoolean(PREFS_AUTOMATIC_SHARING_ENABLE, false);
//     }
// 
//     public static void setIsAutomaticSharingEnable(Context context, Boolean isAutomaticSharingEnable) {
//         getPreferences(context).edit().putBoolean(PREFS_AUTOMATIC_SHARING_ENABLE, isAutomaticSharingEnable).commit();
//     }
// 
//     public static Boolean isTheFirstRun(Context context) {
//         return getPreferences(context).getBoolean(PREFS_FIRST_RUN, true);
//     }
// 
//     public static void disableFirstRun(Context context) {
//         getPreferences(context).edit().putBoolean(PREFS_FIRST_RUN, false).commit();
//     }
// 
// 
//     public static List<String> getTheListOfScansAvailable(Context context) {
//         Set<String> listOfPreviousScans = getPreferences(context).getStringSet(PREFS_LAST_LIST_OF_SCANS, null);
// 
//         if (listOfPreviousScans == null) {
//             return null;
//         }
// 
//         List<String> listOfScans = Arrays.asList(listOfPreviousScans.toArray(new String[listOfPreviousScans.size()]));
// 
//         return listOfScans;
//     }
// 
//     public static void setTheListOfScansAvailable(Context context, List<String> listOfScans) {
//         SharedPreferences.Editor editor = getPreferences(context).edit();
// 
//         editor.putStringSet(PREFS_LAST_LIST_OF_SCANS, new HashSet<>(listOfScans));
// 
//         editor.apply();
//     }
// 
//     public static void setBuildUpdateFingerPrint(Context context, String fingerprint){
//         SharedPreferences.Editor editor = getPreferences(context).edit();
// 
//         editor.putString(BUILD_FINGERPRINT_HASH, fingerprint);
// 
//         editor.apply();
//     }
// 
//     public static String getBuildUpdateFingerprint(Context context){
//         return getPreferences(context).getString(BUILD_FINGERPRINT_HASH, null);
//     }
// 
// }


// Path: app/src/main/java/fuzion24/device/vulnerability/vulnerabilities/helper/DeviceUpdateChecker.java
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Base64;
import java.io.File;
import java.security.MessageDigest;
import java.util.HashSet;
import java.util.Scanner;
import fuzion24.device.vulnerability.util.SharedPreferencesUtils;

package fuzion24.device.vulnerability.vulnerabilities.helper;




/**
 * Created by fuzion24 on 12/4/15.
 */
public class DeviceUpdateChecker {
    private DeviceUpdateChecker() {
    }

    public static boolean wasDeviceUpdated(Context ctx){

        /*
            Take a hash of the build.prop and /proc/version
            If this changes, assume the device has been updated
        */
        String buildPropFile = readFile("/system/build.prop");
        String procVersion   = readFile("/proc/version");

        String fingerprint = hashString(buildPropFile + procVersion);
        String lastFingerprint = SharedPreferencesUtils.getBuildUpdateFingerprint(ctx);
        if(fingerprint.equals(lastFingerprint)){
            return false;
        } else {
            SharedPreferencesUtils.setBuildUpdateFingerPrint(ctx, fingerprint);
            return true;
        }
    }

    private static String hashString(String data){
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(data.getBytes());
            byte[] hash = md.digest();
            return Base64.encodeToString(hash, Base64.DEFAULT);
        } catch (Exception e) {
            return "";
        }
    }

    private static String readFile(String filename){
        try {
            return new Scanner(new File(filename)).useDelimiter("\\Z").next();
        }catch(Exception e){