예제 #1
0
파일: Util.java 프로젝트: paour/XPrivacy
  public static String hasProLicense(Context context) {
    try {
      // Get license
      String[] license = getProLicenseUnchecked();
      if (license == null) return null;
      String name = license[0];
      String email = license[1];
      String signature = license[2];

      // Get bytes
      byte[] bEmail = email.getBytes("UTF-8");
      byte[] bSignature = hex2bytes(signature);
      if (bEmail.length == 0 || bSignature.length == 0) {
        Util.log(null, Log.ERROR, "Licensing: invalid file");
        return null;
      }

      // Verify license
      boolean licensed = verifyData(bEmail, bSignature, getPublicKey(context));
      if (licensed) Util.log(null, Log.INFO, "Licensing: ok for " + name);
      else Util.log(null, Log.ERROR, "Licensing: invalid for " + name);

      // Return result
      if (licensed) return name;
    } catch (Throwable ex) {
      Util.bug(null, ex);
    }
    return null;
  }
예제 #2
0
 @Override
 public boolean onCreate() {
   try {
     String packageName = PrivacyManager.class.getPackage().getName();
     File out =
         new File(
             Environment.getDataDirectory()
                 + File.separator
                 + "data"
                 + File.separator
                 + packageName
                 + File.separator
                 + "meta.xml");
     Util.log(null, Log.INFO, "Writing meta=" + out.getAbsolutePath());
     InputStream is = getContext().getAssets().open("meta.xml");
     OutputStream os = new FileOutputStream(out.getAbsolutePath());
     byte[] buffer = new byte[1024];
     int read;
     while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read);
     is.close();
     os.flush();
     os.close();
     out.setReadable(true, false);
   } catch (Throwable ex) {
     Util.bug(null, ex);
   }
   return true;
 }
예제 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    if (PrivacyService.checkClient()) {
      // Set theme
      int userId = Util.getUserId(Process.myUid());
      String themeName = PrivacyManager.getSetting(userId, PrivacyManager.cSettingTheme, "");
      mThemeId = (themeName.equals("Dark") ? R.style.CustomTheme : R.style.CustomTheme_Light);
      setTheme(mThemeId);
      super.onCreate(savedInstanceState);
    } else {
      super.onCreate(savedInstanceState);
      // Privacy client now available
      setContentView(R.layout.reboot);

      try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
        tvVersion.setText(pInfo.versionName);
      } catch (Throwable ex) {
        Util.bug(null, ex);
      }

      // Show reason
      if (PrivacyService.getClient() == null) {
        TextView tvRebootClient = (TextView) findViewById(R.id.tvRebootClient);
        tvRebootClient.setVisibility(View.VISIBLE);
        Requirements.checkCompatibility(this);
      } else {
        TextView tvRebootClient = (TextView) findViewById(R.id.tvRebootVersion);
        tvRebootClient.setVisibility(View.VISIBLE);
        Requirements.check(this);
      }
    }
  }
예제 #4
0
 private boolean isAccountAllowed(String accountName, String accountType, int uid) {
   try {
     String sha1 = Util.sha1(accountName + accountType);
     if (PrivacyManager.getSettingBool(uid, Meta.cTypeAccount, sha1, false, true)) return true;
   } catch (Throwable ex) {
     Util.bug(this, ex);
   }
   return false;
 }
예제 #5
0
파일: Util.java 프로젝트: paour/XPrivacy
 public static String getSelfVersionName(Context context) {
   try {
     String self = Util.class.getPackage().getName();
     PackageManager pm = context.getPackageManager();
     PackageInfo pInfo = pm.getPackageInfo(self, 0);
     return pInfo.versionName;
   } catch (NameNotFoundException ex) {
     Util.bug(null, ex);
     return null;
   }
 }
예제 #6
0
파일: Util.java 프로젝트: paour/XPrivacy
 public static Version getProEnablerVersion(Context context) {
   try {
     String proPackageName = context.getPackageName() + ".pro";
     PackageManager pm = context.getPackageManager();
     PackageInfo pi = pm.getPackageInfo(proPackageName, 0);
     return new Version(pi.versionName);
   } catch (NameNotFoundException ignored) {
   } catch (Throwable ex) {
     Util.bug(null, ex);
   }
   return null;
 }
예제 #7
0
파일: Util.java 프로젝트: paour/XPrivacy
 @SuppressLint("NewApi")
 public static int getAppId(int uid) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
     try {
       // UserHandle: public static final int getAppId(int uid)
       Method method = (Method) UserHandle.class.getDeclaredMethod("getAppId", int.class);
       uid = (Integer) method.invoke(null, uid);
     } catch (Throwable ex) {
       Util.bug(null, ex);
     }
   return uid;
 }
예제 #8
0
파일: Util.java 프로젝트: paour/XPrivacy
  public static String[] getProLicenseUnchecked() {
    // Get license file name
    String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    File licenseFile = new File(storageDir + File.separator + LICENSE_FILE_NAME);
    if (!licenseFile.exists())
      licenseFile =
          new File(storageDir + File.separator + ".xprivacy" + File.separator + LICENSE_FILE_NAME);

    // Get imported license file name
    String importedLicense =
        getUserDataDirectory(Process.myUid()) + File.separator + LICENSE_FILE_NAME;

    // Import license file
    if (licenseFile.exists()) {
      try {
        File out = new File(importedLicense);
        Util.log(null, Log.WARN, "Licensing: importing " + out.getAbsolutePath());
        InputStream is = new FileInputStream(licenseFile.getAbsolutePath());
        OutputStream os = new FileOutputStream(out.getAbsolutePath());
        byte[] buffer = new byte[1024];
        int read;
        while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read);
        is.close();
        os.flush();
        os.close();

        // Protect license file
        setPermissions(out.getAbsolutePath(), 0700, Process.myUid(), Process.myUid());

        licenseFile.delete();
      } catch (Throwable ex) {
        Util.bug(null, ex);
      }
    }

    // Check license file
    licenseFile = new File(importedLicense);
    if (licenseFile.exists()) {
      // Read license
      try {
        IniFile iniFile = new IniFile(licenseFile);
        String name = iniFile.get("name", "");
        String email = iniFile.get("email", "");
        String signature = iniFile.get("signature", "");
        return new String[] {name, email, signature};
      } catch (Throwable ex) {
        bug(null, ex);
        return null;
      }
    } else Util.log(null, Log.INFO, "Licensing: no license file");
    return null;
  }
예제 #9
0
파일: Util.java 프로젝트: paour/XPrivacy
 public static boolean hasLBE() {
   if (!mHasLBEDetermined) {
     mHasLBEDetermined = true;
     try {
       File apps = new File(Environment.getDataDirectory() + File.separator + "app");
       File[] files = (apps == null ? null : apps.listFiles());
       if (files != null)
         for (File file : files) if (file.getName().startsWith("com.lbe.security")) mHasLBE = true;
     } catch (Throwable ex) {
       Util.bug(null, ex);
     }
   }
   return mHasLBE;
 }
예제 #10
0
파일: Util.java 프로젝트: paour/XPrivacy
 public static void setPermissions(String path, int mode, int uid, int gid) {
   try {
     // frameworks/base/core/java/android/os/FileUtils.java
     Class<?> fileUtils = Class.forName("android.os.FileUtils");
     Method setPermissions =
         fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class);
     setPermissions.invoke(null, path, mode, uid, gid);
     Util.log(
         null,
         Log.WARN,
         "Changed permission path="
             + path
             + " mode="
             + Integer.toOctalString(mode)
             + " uid="
             + uid
             + " gid="
             + gid);
   } catch (Throwable ex) {
     Util.bug(null, ex);
   }
 }
예제 #11
0
  @Override
  protected void after(MethodHookParam param) throws Throwable {
    if (mMethod != Methods.addGeofence
        && mMethod != Methods.addNmeaListener
        && mMethod != Methods.addProximityAlert
        && mMethod != Methods.removeUpdates
        && mMethod != Methods.requestLocationUpdates
        && mMethod != Methods.requestSingleUpdate)
      if (mMethod == Methods.isProviderEnabled) {
        if (isRestricted(param)) param.setResult(false);

      } else if (mMethod == Methods.getGpsStatus) {
        if (param.getResult() != null && isRestricted(param)) {
          GpsStatus status = (GpsStatus) param.getResult();
          // private GpsSatellite mSatellites[]
          try {
            Field mSatellites = status.getClass().getDeclaredField("mSatellites");
            mSatellites.setAccessible(true);
            mSatellites.set(status, new GpsSatellite[0]);
          } catch (Throwable ex) {
            Util.bug(null, ex);
          }
        }
      } else if (mMethod == Methods.getLastLocation || mMethod == Methods.getLastKnownLocation) {
        Location location = (Location) param.getResult();
        if (location != null && isRestricted(param))
          param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));

      } else if (mMethod == Methods.getProviders) {
        if (param.getResult() != null && isRestricted(param))
          param.setResult(new ArrayList<String>());

      } else if (mMethod == Methods.sendExtraCommand) {
        if (isRestricted(param)) param.setResult(false);

      } else Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
  }