feat: Do not generate a new keystore each time Patcher runs

This commit is contained in:
Alberto Ponces 2022-09-07 18:25:12 +01:00
parent 825a57ee69
commit 63c1fdf9c5
3 changed files with 13 additions and 6 deletions

View file

@ -45,6 +45,7 @@ class MainActivity : FlutterActivity() {
val cacheDirPath = call.argument<String>("cacheDirPath") val cacheDirPath = call.argument<String>("cacheDirPath")
val mergeIntegrations = call.argument<Boolean>("mergeIntegrations") val mergeIntegrations = call.argument<Boolean>("mergeIntegrations")
val resourcePatching = call.argument<Boolean>("resourcePatching") val resourcePatching = call.argument<Boolean>("resourcePatching")
val keyStoreFilePath = call.argument<String>("keyStoreFilePath")
if (patchBundleFilePath != null && if (patchBundleFilePath != null &&
originalFilePath != null && originalFilePath != null &&
inputFilePath != null && inputFilePath != null &&
@ -54,7 +55,8 @@ class MainActivity : FlutterActivity() {
selectedPatches != null && selectedPatches != null &&
cacheDirPath != null && cacheDirPath != null &&
mergeIntegrations != null && mergeIntegrations != null &&
resourcePatching != null resourcePatching != null &&
keyStoreFilePath != null
) { ) {
runPatcher( runPatcher(
result, result,
@ -67,7 +69,8 @@ class MainActivity : FlutterActivity() {
selectedPatches, selectedPatches,
cacheDirPath, cacheDirPath,
mergeIntegrations, mergeIntegrations,
resourcePatching resourcePatching,
keyStoreFilePath
) )
} else { } else {
result.notImplemented() result.notImplemented()
@ -89,13 +92,15 @@ class MainActivity : FlutterActivity() {
selectedPatches: List<String>, selectedPatches: List<String>,
cacheDirPath: String, cacheDirPath: String,
mergeIntegrations: Boolean, mergeIntegrations: Boolean,
resourcePatching: Boolean resourcePatching: Boolean,
keyStoreFilePath: String
) { ) {
val originalFile = File(originalFilePath) val originalFile = File(originalFilePath)
val inputFile = File(inputFilePath) val inputFile = File(inputFilePath)
val patchedFile = File(patchedFilePath) val patchedFile = File(patchedFilePath)
val outFile = File(outFilePath) val outFile = File(outFilePath)
val integrations = File(integrationsPath) val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val patches = val patches =
DexPatchBundle( DexPatchBundle(
@ -314,7 +319,7 @@ class MainActivity : FlutterActivity() {
) )
) )
} }
Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outFile) Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outFile, keyStoreFile)
handler.post { handler.post {
installerChannel.invokeMethod( installerChannel.invokeMethod(

View file

@ -49,10 +49,9 @@ internal class Signer(
return JcaX509CertificateConverter().getCertificate(builder.build(signer)) to pair.private return JcaX509CertificateConverter().getCertificate(builder.build(signer)) to pair.private
} }
fun signApk(input: File, output: File) { fun signApk(input: File, output: File, ks: File) {
Security.addProvider(BouncyCastleProvider()) Security.addProvider(BouncyCastleProvider())
val ks = File(input.parent, "revanced-cli.keystore")
if (!ks.exists()) newKeystore(ks) if (!ks.exists()) newKeystore(ks)
val keyStore = KeyStore.getInstance("BKS", "BC") val keyStore = KeyStore.getInstance("BKS", "BC")

View file

@ -18,6 +18,7 @@ class PatcherAPI {
final ManagerAPI _managerAPI = locator<ManagerAPI>(); final ManagerAPI _managerAPI = locator<ManagerAPI>();
final RootAPI _rootAPI = RootAPI(); final RootAPI _rootAPI = RootAPI();
late Directory _tmpDir; late Directory _tmpDir;
late File _keyStoreFile;
List<Patch> _patches = []; List<Patch> _patches = [];
File? _outFile; File? _outFile;
@ -25,6 +26,7 @@ class PatcherAPI {
await _loadPatches(); await _loadPatches();
Directory appCache = await getTemporaryDirectory(); Directory appCache = await getTemporaryDirectory();
_tmpDir = Directory('${appCache.path}/patcher'); _tmpDir = Directory('${appCache.path}/patcher');
_keyStoreFile = File('${appCache.path}/revanced-manager.keystore');
cleanPatcher(); cleanPatcher();
} }
@ -138,6 +140,7 @@ class PatcherAPI {
'cacheDirPath': cacheDir.path, 'cacheDirPath': cacheDir.path,
'mergeIntegrations': mergeIntegrations, 'mergeIntegrations': mergeIntegrations,
'resourcePatching': resourcePatching, 'resourcePatching': resourcePatching,
'keyStoreFilePath': _keyStoreFile.path,
}, },
); );
} }