mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
use same fingerprint
This commit is contained in:
parent
83cbb34a5b
commit
e7c8d0e78c
@ -19,41 +19,9 @@ import android.util.Log
|
|||||||
class ExportSettingsActivity : Activity() {
|
class ExportSettingsActivity : Activity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val revancedFingerprint = "b6362c6ea7888efd15c0800f480786ad0f5b133b4f84e12d46afba5f9eac1223"
|
val callingPackageName = getCallingPackage()!!
|
||||||
|
|
||||||
// Get the package name of the app that started the activity
|
if (getFingerprint(callingPackageName) == getFingerprint(getPackageName())) {
|
||||||
val packageName = getCallingPackage()!!
|
|
||||||
|
|
||||||
// Get the signature of the app that matches the package name
|
|
||||||
val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
|
|
||||||
val signatures = packageInfo.signatures
|
|
||||||
|
|
||||||
// Loop through each signature and print its properties
|
|
||||||
for (signature in signatures) {
|
|
||||||
// Get the raw certificate data
|
|
||||||
val rawCert = signature.toByteArray()
|
|
||||||
|
|
||||||
// Generate an X509Certificate from the data
|
|
||||||
val certFactory = CertificateFactory.getInstance("X509")
|
|
||||||
val x509Cert = certFactory.generateCertificate(ByteArrayInputStream(rawCert)) as X509Certificate
|
|
||||||
|
|
||||||
// Get the SHA256 fingerprint
|
|
||||||
val fingerprint = MessageDigest.getInstance("SHA256").digest(x509Cert.encoded).joinToString("") {
|
|
||||||
"%02x".format(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fingerprint == revancedFingerprint) {
|
|
||||||
sendData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send data back
|
|
||||||
val resultIntent = Intent()
|
|
||||||
setResult(Activity.RESULT_CANCELED)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun sendData() {
|
|
||||||
// Create JSON Object
|
// Create JSON Object
|
||||||
val json = JSONObject()
|
val json = JSONObject()
|
||||||
|
|
||||||
@ -92,5 +60,30 @@ class ExportSettingsActivity : Activity() {
|
|||||||
resultIntent.putExtra("data", json.toString())
|
resultIntent.putExtra("data", json.toString())
|
||||||
setResult(Activity.RESULT_OK, resultIntent)
|
setResult(Activity.RESULT_OK, resultIntent)
|
||||||
finish()
|
finish()
|
||||||
|
} else {
|
||||||
|
val resultIntent = Intent()
|
||||||
|
setResult(Activity.RESULT_CANCELED)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFingerprint(packageName: String): String {
|
||||||
|
// Get the signature of the app that matches the package name
|
||||||
|
val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
|
||||||
|
val signature = packageInfo.signatures[0]
|
||||||
|
|
||||||
|
// Get the raw certificate data
|
||||||
|
val rawCert = signature.toByteArray()
|
||||||
|
|
||||||
|
// Generate an X509Certificate from the data
|
||||||
|
val certFactory = CertificateFactory.getInstance("X509")
|
||||||
|
val x509Cert = certFactory.generateCertificate(ByteArrayInputStream(rawCert)) as X509Certificate
|
||||||
|
|
||||||
|
// Get the SHA256 fingerprint
|
||||||
|
val fingerprint = MessageDigest.getInstance("SHA256").digest(x509Cert.encoded).joinToString("") {
|
||||||
|
"%02x".format(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fingerprint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user