mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
feat: use provided patches.json to load patches
This commit is contained in:
parent
080ceae784
commit
03b45e0db0
11 changed files with 210 additions and 338 deletions
|
@ -10,13 +10,7 @@ import app.revanced.manager.utils.zip.ZipFile
|
||||||
import app.revanced.manager.utils.zip.structures.ZipEntry
|
import app.revanced.manager.utils.zip.structures.ZipEntry
|
||||||
import app.revanced.patcher.Patcher
|
import app.revanced.patcher.Patcher
|
||||||
import app.revanced.patcher.PatcherOptions
|
import app.revanced.patcher.PatcherOptions
|
||||||
import app.revanced.patcher.data.Data
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.description
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.include
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.version
|
|
||||||
import app.revanced.patcher.patch.Patch
|
|
||||||
import app.revanced.patcher.util.patch.impl.DexPatchBundle
|
import app.revanced.patcher.util.patch.impl.DexPatchBundle
|
||||||
import dalvik.system.DexClassLoader
|
import dalvik.system.DexClassLoader
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
@ -30,7 +24,6 @@ import java.nio.file.StandardCopyOption
|
||||||
class MainActivity : FlutterActivity() {
|
class MainActivity : FlutterActivity() {
|
||||||
private val PATCHER_CHANNEL = "app.revanced.manager/patcher"
|
private val PATCHER_CHANNEL = "app.revanced.manager/patcher"
|
||||||
private val INSTALLER_CHANNEL = "app.revanced.manager/installer"
|
private val INSTALLER_CHANNEL = "app.revanced.manager/installer"
|
||||||
private var patches = mutableListOf<Class<out Patch<Data>>>()
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
private lateinit var installerChannel: MethodChannel
|
private lateinit var installerChannel: MethodChannel
|
||||||
|
|
||||||
|
@ -41,27 +34,8 @@ class MainActivity : FlutterActivity() {
|
||||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, INSTALLER_CHANNEL)
|
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, INSTALLER_CHANNEL)
|
||||||
mainChannel.setMethodCallHandler { call, result ->
|
mainChannel.setMethodCallHandler { call, result ->
|
||||||
when (call.method) {
|
when (call.method) {
|
||||||
"loadPatches" -> {
|
|
||||||
val jarPatchBundlePath = call.argument<String>("jarPatchBundlePath")
|
|
||||||
val cacheDirPath = call.argument<String>("cacheDirPath")
|
|
||||||
if (jarPatchBundlePath != null && cacheDirPath != null) {
|
|
||||||
loadPatches(result, jarPatchBundlePath, cacheDirPath)
|
|
||||||
} else {
|
|
||||||
result.notImplemented()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"getCompatiblePackages" -> getCompatiblePackages(result)
|
|
||||||
"getFilteredPatches" -> {
|
|
||||||
val targetPackage = call.argument<String>("targetPackage")
|
|
||||||
val targetVersion = call.argument<String>("targetVersion")
|
|
||||||
val ignoreVersion = call.argument<Boolean>("ignoreVersion")
|
|
||||||
if (targetPackage != null && targetVersion != null && ignoreVersion != null) {
|
|
||||||
getFilteredPatches(result, targetPackage, targetVersion, ignoreVersion)
|
|
||||||
} else {
|
|
||||||
result.notImplemented()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"runPatcher" -> {
|
"runPatcher" -> {
|
||||||
|
val patchBundleFilePath = call.argument<String>("patchBundleFilePath")
|
||||||
val originalFilePath = call.argument<String>("originalFilePath")
|
val originalFilePath = call.argument<String>("originalFilePath")
|
||||||
val inputFilePath = call.argument<String>("inputFilePath")
|
val inputFilePath = call.argument<String>("inputFilePath")
|
||||||
val patchedFilePath = call.argument<String>("patchedFilePath")
|
val patchedFilePath = call.argument<String>("patchedFilePath")
|
||||||
|
@ -71,7 +45,8 @@ 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")
|
||||||
if (originalFilePath != null &&
|
if (patchBundleFilePath != null &&
|
||||||
|
originalFilePath != null &&
|
||||||
inputFilePath != null &&
|
inputFilePath != null &&
|
||||||
patchedFilePath != null &&
|
patchedFilePath != null &&
|
||||||
outFilePath != null &&
|
outFilePath != null &&
|
||||||
|
@ -83,6 +58,7 @@ class MainActivity : FlutterActivity() {
|
||||||
) {
|
) {
|
||||||
runPatcher(
|
runPatcher(
|
||||||
result,
|
result,
|
||||||
|
patchBundleFilePath,
|
||||||
originalFilePath,
|
originalFilePath,
|
||||||
inputFilePath,
|
inputFilePath,
|
||||||
patchedFilePath,
|
patchedFilePath,
|
||||||
|
@ -102,79 +78,9 @@ class MainActivity : FlutterActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadPatches(
|
|
||||||
result: MethodChannel.Result,
|
|
||||||
jarPatchBundlePath: String,
|
|
||||||
cacheDirPath: String
|
|
||||||
) {
|
|
||||||
Thread(
|
|
||||||
Runnable {
|
|
||||||
patches.addAll(
|
|
||||||
DexPatchBundle(
|
|
||||||
jarPatchBundlePath,
|
|
||||||
DexClassLoader(
|
|
||||||
jarPatchBundlePath,
|
|
||||||
cacheDirPath,
|
|
||||||
null,
|
|
||||||
javaClass.classLoader
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.loadPatches()
|
|
||||||
)
|
|
||||||
handler.post { result.success(null) }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCompatiblePackages(result: MethodChannel.Result) {
|
|
||||||
Thread(
|
|
||||||
Runnable {
|
|
||||||
val filteredPackages = mutableListOf<String>()
|
|
||||||
patches.forEach patch@{ patch ->
|
|
||||||
patch.compatiblePackages?.forEach { pkg ->
|
|
||||||
filteredPackages.add(pkg.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
handler.post { result.success(filteredPackages.distinct()) }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFilteredPatches(
|
|
||||||
result: MethodChannel.Result,
|
|
||||||
targetPackage: String,
|
|
||||||
targetVersion: String,
|
|
||||||
ignoreVersion: Boolean
|
|
||||||
) {
|
|
||||||
Thread(
|
|
||||||
Runnable {
|
|
||||||
val filteredPatches = mutableListOf<Map<String, Any?>>()
|
|
||||||
patches.forEach patch@{ patch ->
|
|
||||||
patch.compatiblePackages?.forEach { pkg ->
|
|
||||||
if (pkg.name == targetPackage &&
|
|
||||||
(ignoreVersion ||
|
|
||||||
pkg.versions.isNotEmpty() ||
|
|
||||||
pkg.versions.contains(targetVersion))
|
|
||||||
) {
|
|
||||||
var p = mutableMapOf<String, Any?>()
|
|
||||||
p.put("name", patch.patchName)
|
|
||||||
p.put("version", patch.version)
|
|
||||||
p.put("description", patch.description)
|
|
||||||
p.put("include", patch.include)
|
|
||||||
filteredPatches.add(p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
handler.post { result.success(filteredPatches) }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun runPatcher(
|
fun runPatcher(
|
||||||
result: MethodChannel.Result,
|
result: MethodChannel.Result,
|
||||||
|
patchBundleFilePath: String,
|
||||||
originalFilePath: String,
|
originalFilePath: String,
|
||||||
inputFilePath: String,
|
inputFilePath: String,
|
||||||
patchedFilePath: String,
|
patchedFilePath: String,
|
||||||
|
@ -190,8 +96,19 @@ class MainActivity : FlutterActivity() {
|
||||||
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 filteredPatches =
|
|
||||||
patches.filter { patch -> selectedPatches.any { it == patch.patchName } }
|
val patches =
|
||||||
|
DexPatchBundle(
|
||||||
|
patchBundleFilePath,
|
||||||
|
DexClassLoader(
|
||||||
|
patchBundleFilePath,
|
||||||
|
cacheDirPath,
|
||||||
|
null,
|
||||||
|
javaClass.classLoader
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.loadPatches()
|
||||||
|
.filter { patch -> selectedPatches.any { it == patch.patchName } }
|
||||||
|
|
||||||
Thread(
|
Thread(
|
||||||
Runnable {
|
Runnable {
|
||||||
|
@ -234,53 +151,69 @@ class MainActivity : FlutterActivity() {
|
||||||
app.revanced.patcher.logging.Logger {
|
app.revanced.patcher.logging.Logger {
|
||||||
override fun error(msg: String) {
|
override fun error(msg: String) {
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel
|
||||||
"update",
|
.invokeMethod(
|
||||||
mapOf(
|
"update",
|
||||||
"progress" to 0.2,
|
mapOf(
|
||||||
"header" to "",
|
"progress" to
|
||||||
"log" to msg
|
0.2,
|
||||||
|
"header" to
|
||||||
|
"",
|
||||||
|
"log" to
|
||||||
|
msg
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun warn(msg: String) {
|
override fun warn(msg: String) {
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel
|
||||||
"update",
|
.invokeMethod(
|
||||||
mapOf(
|
"update",
|
||||||
"progress" to 0.2,
|
mapOf(
|
||||||
"header" to "",
|
"progress" to
|
||||||
"log" to msg
|
0.2,
|
||||||
|
"header" to
|
||||||
|
"",
|
||||||
|
"log" to
|
||||||
|
msg
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun info(msg: String) {
|
override fun info(msg: String) {
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel
|
||||||
"update",
|
.invokeMethod(
|
||||||
mapOf(
|
"update",
|
||||||
"progress" to 0.2,
|
mapOf(
|
||||||
"header" to "",
|
"progress" to
|
||||||
"log" to msg
|
0.2,
|
||||||
|
"header" to
|
||||||
|
"",
|
||||||
|
"log" to
|
||||||
|
msg
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun trace(msg: String) {
|
override fun trace(msg: String) {
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel
|
||||||
"update",
|
.invokeMethod(
|
||||||
mapOf(
|
"update",
|
||||||
"progress" to 0.2,
|
mapOf(
|
||||||
"header" to "",
|
"progress" to
|
||||||
"log" to msg
|
0.2,
|
||||||
|
"header" to
|
||||||
|
"",
|
||||||
|
"log" to
|
||||||
|
msg
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,12 +222,8 @@ class MainActivity : FlutterActivity() {
|
||||||
|
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel.invokeMethod(
|
||||||
"update",
|
"update",
|
||||||
mapOf(
|
mapOf("progress" to 0.3, "header" to "", "log" to "")
|
||||||
"progress" to 0.3,
|
|
||||||
"header" to "",
|
|
||||||
"log" to ""
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (mergeIntegrations) {
|
if (mergeIntegrations) {
|
||||||
|
@ -321,7 +250,7 @@ class MainActivity : FlutterActivity() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
patcher.addPatches(filteredPatches)
|
patcher.addPatches(patches)
|
||||||
patcher.applyPatches().forEach { (patch, res) ->
|
patcher.applyPatches().forEach { (patch, res) ->
|
||||||
if (res.isSuccess) {
|
if (res.isSuccess) {
|
||||||
val msg = "[success] $patch"
|
val msg = "[success] $patch"
|
||||||
|
@ -341,11 +270,7 @@ class MainActivity : FlutterActivity() {
|
||||||
handler.post {
|
handler.post {
|
||||||
installerChannel.invokeMethod(
|
installerChannel.invokeMethod(
|
||||||
"update",
|
"update",
|
||||||
mapOf(
|
mapOf("progress" to 0.5, "header" to "", "log" to msg)
|
||||||
"progress" to 0.5,
|
|
||||||
"header" to "",
|
|
||||||
"log" to msg
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:revanced_manager/app/app.locator.dart';
|
||||||
import 'package:revanced_manager/app/app.router.dart';
|
import 'package:revanced_manager/app/app.router.dart';
|
||||||
import 'package:revanced_manager/main_viewmodel.dart';
|
import 'package:revanced_manager/main_viewmodel.dart';
|
||||||
import 'package:revanced_manager/services/manager_api.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
|
import 'package:revanced_manager/services/patcher_api.dart';
|
||||||
import 'package:revanced_manager/theme.dart';
|
import 'package:revanced_manager/theme.dart';
|
||||||
import 'package:revanced_manager/ui/views/home/home_view.dart';
|
import 'package:revanced_manager/ui/views/home/home_view.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
||||||
|
@ -69,6 +70,7 @@ class MyApp extends StatelessWidget {
|
||||||
|
|
||||||
Future<Widget> _init() async {
|
Future<Widget> _init() async {
|
||||||
await locator<ManagerAPI>().initialize();
|
await locator<ManagerAPI>().initialize();
|
||||||
|
await locator<PatcherAPI>().initialize();
|
||||||
bool? isRooted = locator<ManagerAPI>().isRooted();
|
bool? isRooted = locator<ManagerAPI>().isRooted();
|
||||||
if (isRooted != null) {
|
if (isRooted != null) {
|
||||||
return const Navigation();
|
return const Navigation();
|
||||||
|
|
|
@ -1,15 +1,47 @@
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
import 'package:revanced_manager/utils/string.dart';
|
||||||
|
|
||||||
|
part 'patch.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
class Patch {
|
class Patch {
|
||||||
final String name;
|
final String name;
|
||||||
final String simpleName;
|
|
||||||
final String version;
|
|
||||||
final String description;
|
final String description;
|
||||||
final bool include;
|
final String version;
|
||||||
|
final bool excluded;
|
||||||
|
final List<String> dependencies;
|
||||||
|
final List<Package> compatiblePackages;
|
||||||
|
|
||||||
Patch({
|
Patch({
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.simpleName,
|
|
||||||
required this.version,
|
|
||||||
required this.description,
|
required this.description,
|
||||||
required this.include,
|
required this.version,
|
||||||
|
required this.excluded,
|
||||||
|
required this.dependencies,
|
||||||
|
required this.compatiblePackages,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
factory Patch.fromJson(Map<String, dynamic> json) => _$PatchFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$PatchToJson(this);
|
||||||
|
|
||||||
|
String getSimpleName() {
|
||||||
|
return name.replaceAll('-', ' ').split('-').join(' ').toTitleCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class Package {
|
||||||
|
final String name;
|
||||||
|
final List<String> versions;
|
||||||
|
|
||||||
|
Package({
|
||||||
|
required this.name,
|
||||||
|
required this.versions,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Package.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$PackageFromJson(json);
|
||||||
|
|
||||||
|
Map toJson() => _$PackageToJson(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class PatchedApplication {
|
||||||
factory PatchedApplication.fromJson(Map<String, dynamic> json) =>
|
factory PatchedApplication.fromJson(Map<String, dynamic> json) =>
|
||||||
_$PatchedApplicationFromJson(json);
|
_$PatchedApplicationFromJson(json);
|
||||||
|
|
||||||
Map toJson() => _$PatchedApplicationToJson(this);
|
Map<String, dynamic> toJson() => _$PatchedApplicationToJson(this);
|
||||||
|
|
||||||
static Uint8List decodeBase64(String icon) => base64.decode(icon);
|
static Uint8List decodeBase64(String icon) => base64.decode(icon);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import 'package:timeago/timeago.dart';
|
||||||
class GithubAPI {
|
class GithubAPI {
|
||||||
final GitHub _github = GitHub();
|
final GitHub _github = GitHub();
|
||||||
|
|
||||||
Future<String?> latestReleaseVersion(String org, repoName) async {
|
Future<String?> latestReleaseVersion(String org, String repoName) async {
|
||||||
try {
|
try {
|
||||||
var latestRelease = await _github.repositories.getLatestRelease(
|
var latestRelease = await _github.repositories.getLatestRelease(
|
||||||
RepositorySlug(org, repoName),
|
RepositorySlug(org, repoName),
|
||||||
|
@ -20,7 +20,7 @@ class GithubAPI {
|
||||||
Future<File?> latestReleaseFile(
|
Future<File?> latestReleaseFile(
|
||||||
String extension,
|
String extension,
|
||||||
String org,
|
String org,
|
||||||
repoName,
|
String repoName,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
var latestRelease = await _github.repositories.getLatestRelease(
|
var latestRelease = await _github.repositories.getLatestRelease(
|
||||||
|
@ -42,7 +42,7 @@ class GithubAPI {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> latestCommitTime(String org, repoName) async {
|
Future<String> latestCommitTime(String org, String repoName) async {
|
||||||
try {
|
try {
|
||||||
var repo = await _github.repositories.getRepository(
|
var repo = await _github.repositories.getRepository(
|
||||||
RepositorySlug(org, repoName),
|
RepositorySlug(org, repoName),
|
||||||
|
@ -55,13 +55,13 @@ class GithubAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Contributor>> getContributors(String org, repoName) async {
|
Future<List<Contributor>> getContributors(String org, String repoName) async {
|
||||||
return await (_github.repositories.listContributors(
|
return await (_github.repositories.listContributors(
|
||||||
RepositorySlug(org, repoName),
|
RepositorySlug(org, repoName),
|
||||||
)).toList();
|
)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<RepositoryCommit>> getCommits(String org, repoName) async {
|
Future<List<RepositoryCommit>> getCommits(String org, String repoName) async {
|
||||||
return await (_github.repositories.listCommits(
|
return await (_github.repositories.listCommits(
|
||||||
RepositorySlug(org, repoName),
|
RepositorySlug(org, repoName),
|
||||||
)).toList();
|
)).toList();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:app_installer/app_installer.dart';
|
import 'package:app_installer/app_installer.dart';
|
||||||
import 'package:device_apps/device_apps.dart';
|
import 'package:device_apps/device_apps.dart';
|
||||||
|
@ -9,7 +10,6 @@ import 'package:revanced_manager/models/patch.dart';
|
||||||
import 'package:revanced_manager/models/patched_application.dart';
|
import 'package:revanced_manager/models/patched_application.dart';
|
||||||
import 'package:revanced_manager/services/manager_api.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
import 'package:revanced_manager/services/root_api.dart';
|
import 'package:revanced_manager/services/root_api.dart';
|
||||||
import 'package:revanced_manager/utils/string.dart';
|
|
||||||
import 'package:share_extend/share_extend.dart';
|
import 'package:share_extend/share_extend.dart';
|
||||||
|
|
||||||
@lazySingleton
|
@lazySingleton
|
||||||
|
@ -19,194 +19,123 @@ class PatcherAPI {
|
||||||
);
|
);
|
||||||
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||||
final RootAPI _rootAPI = RootAPI();
|
final RootAPI _rootAPI = RootAPI();
|
||||||
|
List<Patch> _patches = [];
|
||||||
Directory? _tmpDir;
|
Directory? _tmpDir;
|
||||||
Directory? _workDir;
|
|
||||||
Directory? _cacheDir;
|
|
||||||
File? _jarPatchBundleFile;
|
|
||||||
File? _integrations;
|
|
||||||
File? _inputFile;
|
|
||||||
File? _patchedFile;
|
|
||||||
File? _outFile;
|
File? _outFile;
|
||||||
|
|
||||||
Future<void> initPatcher() async {
|
Future<void> initialize() async {
|
||||||
Directory appCache = await getTemporaryDirectory();
|
await _loadPatches();
|
||||||
_tmpDir = Directory('${appCache.path}/patcher');
|
|
||||||
_tmpDir!.createSync();
|
|
||||||
_workDir = _tmpDir!.createTempSync('tmp-');
|
|
||||||
_inputFile = File('${_workDir!.path}/base.apk');
|
|
||||||
_patchedFile = File('${_workDir!.path}/patched.apk');
|
|
||||||
_outFile = File('${_workDir!.path}/out.apk');
|
|
||||||
_cacheDir = Directory('${_workDir!.path}/cache');
|
|
||||||
_cacheDir!.createSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> loadPatches() async {
|
Future<void> _loadPatches() async {
|
||||||
if (_tmpDir == null) {
|
try {
|
||||||
await initPatcher();
|
if (_patches.isEmpty) {
|
||||||
}
|
File? patchJsonFile = await _managerAPI.downloadPatches('.json');
|
||||||
if (_jarPatchBundleFile == null) {
|
if (patchJsonFile != null) {
|
||||||
_jarPatchBundleFile = await _managerAPI.downloadPatches('.jar');
|
List<dynamic> list = json.decode(patchJsonFile.readAsStringSync());
|
||||||
if (_jarPatchBundleFile != null) {
|
_patches = list.map((patch) => Patch.fromJson(patch)).toList();
|
||||||
try {
|
|
||||||
await patcherChannel.invokeMethod<bool>(
|
|
||||||
'loadPatches',
|
|
||||||
{
|
|
||||||
'jarPatchBundlePath': _jarPatchBundleFile!.path,
|
|
||||||
'cacheDirPath': _cacheDir!.path,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} on Exception {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} on Exception {
|
||||||
|
_patches = List.empty();
|
||||||
}
|
}
|
||||||
return _jarPatchBundleFile != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps() async {
|
Future<List<ApplicationWithIcon>> getFilteredInstalledApps() async {
|
||||||
List<ApplicationWithIcon> filteredPackages = [];
|
List<ApplicationWithIcon> filteredApps = [];
|
||||||
bool isLoaded = await loadPatches();
|
await _loadPatches();
|
||||||
if (isLoaded) {
|
for (Patch patch in _patches) {
|
||||||
try {
|
for (Package package in patch.compatiblePackages) {
|
||||||
List<String>? patchesPackages = await patcherChannel
|
|
||||||
.invokeListMethod<String>('getCompatiblePackages');
|
|
||||||
if (patchesPackages != null) {
|
|
||||||
for (String package in patchesPackages) {
|
|
||||||
try {
|
|
||||||
ApplicationWithIcon? app = await DeviceApps.getApp(package, true)
|
|
||||||
as ApplicationWithIcon?;
|
|
||||||
if (app != null) {
|
|
||||||
filteredPackages.add(app);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} on Exception {
|
|
||||||
return List.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredPackages;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<Patch>> getFilteredPatches(
|
|
||||||
PatchedApplication? selectedApp,
|
|
||||||
) async {
|
|
||||||
List<Patch> filteredPatches = [];
|
|
||||||
if (selectedApp != null) {
|
|
||||||
bool isLoaded = await loadPatches();
|
|
||||||
if (isLoaded) {
|
|
||||||
try {
|
try {
|
||||||
var patches =
|
if (!filteredApps.any((app) => app.packageName == package.name)) {
|
||||||
await patcherChannel.invokeListMethod<Map<dynamic, dynamic>>(
|
ApplicationWithIcon? app =
|
||||||
'getFilteredPatches',
|
await DeviceApps.getApp(package.name, true)
|
||||||
{
|
as ApplicationWithIcon?;
|
||||||
'targetPackage': selectedApp.packageName,
|
if (app != null) {
|
||||||
'targetVersion': selectedApp.version,
|
filteredApps.add(app);
|
||||||
'ignoreVersion': true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (patches != null) {
|
|
||||||
for (var patch in patches) {
|
|
||||||
if (!filteredPatches
|
|
||||||
.any((element) => element.name == patch['name'])) {
|
|
||||||
filteredPatches.add(
|
|
||||||
Patch(
|
|
||||||
name: patch['name'],
|
|
||||||
simpleName: (patch['name'] as String)
|
|
||||||
.replaceAll('-', ' ')
|
|
||||||
.split('-')
|
|
||||||
.join(' ')
|
|
||||||
.toTitleCase(),
|
|
||||||
version: patch['version'] ?? '?.?.?',
|
|
||||||
description: patch['description'] ?? 'N/A',
|
|
||||||
include: patch['include'] ?? true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on Exception {
|
} catch (e) {
|
||||||
return List.empty();
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredPatches;
|
return filteredApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Patch>> getAppliedPatches(
|
Future<List<Patch>> getFilteredPatches(String packageName) async {
|
||||||
PatchedApplication? selectedApp,
|
await _loadPatches();
|
||||||
) async {
|
return _patches
|
||||||
List<Patch> appliedPatches = [];
|
.where((patch) =>
|
||||||
if (selectedApp != null) {
|
!patch.name.contains('settings') &&
|
||||||
bool isLoaded = await loadPatches();
|
patch.compatiblePackages.any((pack) => pack.name == packageName))
|
||||||
if (isLoaded) {
|
.toList();
|
||||||
try {
|
|
||||||
var patches =
|
|
||||||
await patcherChannel.invokeListMethod<Map<dynamic, dynamic>>(
|
|
||||||
'getFilteredPatches',
|
|
||||||
{
|
|
||||||
'targetPackage': selectedApp.packageName,
|
|
||||||
'targetVersion': selectedApp.version,
|
|
||||||
'ignoreVersion': true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (patches != null) {
|
|
||||||
for (var patch in patches) {
|
|
||||||
if (selectedApp.appliedPatches.contains(patch['name'])) {
|
|
||||||
appliedPatches.add(
|
|
||||||
Patch(
|
|
||||||
name: patch['name'],
|
|
||||||
simpleName: (patch['name'] as String)
|
|
||||||
.replaceAll('-', ' ')
|
|
||||||
.split('-')
|
|
||||||
.join(' ')
|
|
||||||
.toTitleCase(),
|
|
||||||
version: patch['version'] ?? '?.?.?',
|
|
||||||
description: patch['description'] ?? 'N/A',
|
|
||||||
include: patch['include'] ?? true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} on Exception {
|
|
||||||
return List.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return appliedPatches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mergeIntegrations(bool mergeIntegrations) async {
|
Future<List<Patch>> getAppliedPatches(List<String> appliedPatches) async {
|
||||||
if (mergeIntegrations) {
|
await _loadPatches();
|
||||||
_integrations = await _managerAPI.downloadIntegrations('.apk');
|
return _patches
|
||||||
} else {
|
.where((patch) => appliedPatches.contains(patch.name))
|
||||||
_integrations = null;
|
.toList();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> runPatcher(
|
Future<void> runPatcher(
|
||||||
|
String packageName,
|
||||||
String originalFilePath,
|
String originalFilePath,
|
||||||
List<Patch> selectedPatches,
|
List<Patch> selectedPatches,
|
||||||
bool mergeIntegrations,
|
|
||||||
bool resourcePatching,
|
|
||||||
) async {
|
) async {
|
||||||
await patcherChannel.invokeMethod(
|
bool mergeIntegrations = selectedPatches.any(
|
||||||
'runPatcher',
|
(patch) => patch.dependencies.contains('integrations'),
|
||||||
{
|
|
||||||
'originalFilePath': originalFilePath,
|
|
||||||
'inputFilePath': _inputFile!.path,
|
|
||||||
'patchedFilePath': _patchedFile!.path,
|
|
||||||
'outFilePath': _outFile!.path,
|
|
||||||
'integrationsPath': _integrations != null ? _integrations!.path : '',
|
|
||||||
'selectedPatches': selectedPatches.map((p) => p.name).toList(),
|
|
||||||
'cacheDirPath': _cacheDir!.path,
|
|
||||||
'mergeIntegrations': mergeIntegrations,
|
|
||||||
'resourcePatching': resourcePatching,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
bool resourcePatching = selectedPatches.any(
|
||||||
|
(patch) => patch.dependencies.any((dep) => dep.contains('resource-')),
|
||||||
|
);
|
||||||
|
bool includeSettings = selectedPatches.any(
|
||||||
|
(patch) => patch.dependencies.contains('settings'),
|
||||||
|
);
|
||||||
|
if (includeSettings) {
|
||||||
|
try {
|
||||||
|
Patch settingsPatch = _patches.firstWhere(
|
||||||
|
(patch) =>
|
||||||
|
patch.name.contains('settings') &&
|
||||||
|
patch.compatiblePackages.any((pack) => pack.name == packageName),
|
||||||
|
);
|
||||||
|
selectedPatches.add(settingsPatch);
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File? patchBundleFile = await _managerAPI.downloadPatches('.jar');
|
||||||
|
File? integrationsFile;
|
||||||
|
if (mergeIntegrations) {
|
||||||
|
integrationsFile = await _managerAPI.downloadIntegrations('.apk');
|
||||||
|
}
|
||||||
|
if (patchBundleFile != null) {
|
||||||
|
Directory appCache = await getTemporaryDirectory();
|
||||||
|
_tmpDir = Directory('${appCache.path}/patcher');
|
||||||
|
_tmpDir!.createSync();
|
||||||
|
Directory workDir = _tmpDir!.createTempSync('tmp-');
|
||||||
|
File inputFile = File('${workDir.path}/base.apk');
|
||||||
|
File patchedFile = File('${workDir.path}/patched.apk');
|
||||||
|
_outFile = File('${workDir.path}/out.apk');
|
||||||
|
Directory cacheDir = Directory('${workDir.path}/cache');
|
||||||
|
cacheDir.createSync();
|
||||||
|
await patcherChannel.invokeMethod(
|
||||||
|
'runPatcher',
|
||||||
|
{
|
||||||
|
'patchBundleFilePath': patchBundleFile.path,
|
||||||
|
'originalFilePath': originalFilePath,
|
||||||
|
'inputFilePath': inputFile.path,
|
||||||
|
'patchedFilePath': patchedFile.path,
|
||||||
|
'outFilePath': _outFile!.path,
|
||||||
|
'integrationsPath': mergeIntegrations ? integrationsFile!.path : '',
|
||||||
|
'selectedPatches': selectedPatches.map((p) => p.name).toList(),
|
||||||
|
'cacheDirPath': cacheDir.path,
|
||||||
|
'mergeIntegrations': mergeIntegrations,
|
||||||
|
'resourcePatching': resourcePatching,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> installPatchedFile(PatchedApplication patchedApp) async {
|
Future<bool> installPatchedFile(PatchedApplication patchedApp) async {
|
||||||
|
|
|
@ -27,7 +27,6 @@ class HomeViewModel extends BaseViewModel {
|
||||||
|
|
||||||
Future<void> initialize() async {
|
Future<void> initialize() async {
|
||||||
await _getPatchedApps();
|
await _getPatchedApps();
|
||||||
await _patcherAPI.loadPatches();
|
|
||||||
await flutterLocalNotificationsPlugin.initialize(
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
const InitializationSettings(
|
const InitializationSettings(
|
||||||
android: AndroidInitializationSettings('ic_notification'),
|
android: AndroidInitializationSettings('ic_notification'),
|
||||||
|
@ -45,7 +44,7 @@ class HomeViewModel extends BaseViewModel {
|
||||||
void navigateToPatcher(PatchedApplication app) async {
|
void navigateToPatcher(PatchedApplication app) async {
|
||||||
locator<PatcherViewModel>().selectedApp = app;
|
locator<PatcherViewModel>().selectedApp = app;
|
||||||
locator<PatcherViewModel>().selectedPatches =
|
locator<PatcherViewModel>().selectedPatches =
|
||||||
await _patcherAPI.getAppliedPatches(app);
|
await _patcherAPI.getAppliedPatches(app.appliedPatches);
|
||||||
locator<PatcherViewModel>().notifyListeners();
|
locator<PatcherViewModel>().notifyListeners();
|
||||||
locator<MainViewModel>().setIndex(1);
|
locator<MainViewModel>().setIndex(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,22 +108,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update(0.0, '', 'Creating working directory');
|
update(0.0, '', 'Creating working directory');
|
||||||
bool mergeIntegrations = false;
|
await _patcherAPI.runPatcher(_app!.packageName, apkFilePath, _patches);
|
||||||
bool resourcePatching = false;
|
|
||||||
if (_app!.packageName == 'com.google.android.youtube') {
|
|
||||||
mergeIntegrations = true;
|
|
||||||
resourcePatching = true;
|
|
||||||
} else if (_app!.packageName ==
|
|
||||||
'com.google.android.apps.youtube.music') {
|
|
||||||
resourcePatching = true;
|
|
||||||
}
|
|
||||||
await _patcherAPI.mergeIntegrations(mergeIntegrations);
|
|
||||||
await _patcherAPI.runPatcher(
|
|
||||||
apkFilePath,
|
|
||||||
_patches,
|
|
||||||
mergeIntegrations,
|
|
||||||
resourcePatching,
|
|
||||||
);
|
|
||||||
} on Exception {
|
} on Exception {
|
||||||
update(1.0, 'Aborting...', 'An error occurred! Aborting');
|
update(1.0, 'Aborting...', 'An error occurred! Aborting');
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||||
.getQueriedPatches(_query)
|
.getQueriedPatches(_query)
|
||||||
.map((patch) => PatchItem(
|
.map((patch) => PatchItem(
|
||||||
name: patch.name,
|
name: patch.name,
|
||||||
simpleName: patch.simpleName,
|
simpleName: patch.getSimpleName(),
|
||||||
version: patch.version,
|
version: patch.version,
|
||||||
description: patch.description,
|
description: patch.description,
|
||||||
isSelected: model.isSelected(patch),
|
isSelected: model.isSelected(patch),
|
||||||
|
|
|
@ -12,11 +12,11 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||||
|
|
||||||
Future<void> initialize() async {
|
Future<void> initialize() async {
|
||||||
patches.addAll(await _patcherAPI.getFilteredPatches(
|
patches.addAll(await _patcherAPI.getFilteredPatches(
|
||||||
locator<PatcherViewModel>().selectedApp,
|
locator<PatcherViewModel>().selectedApp!.packageName,
|
||||||
));
|
));
|
||||||
patches.sort((a, b) => a.simpleName.compareTo(b.simpleName));
|
patches.sort((a, b) => a.name.compareTo(b.name));
|
||||||
for (Patch p in patches) {
|
for (Patch p in patches) {
|
||||||
if (p.include) {
|
if (!p.excluded) {
|
||||||
selectedPatches.add(p);
|
selectedPatches.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||||
.where((patch) =>
|
.where((patch) =>
|
||||||
query.isEmpty ||
|
query.isEmpty ||
|
||||||
query.length < 2 ||
|
query.length < 2 ||
|
||||||
patch.simpleName.toLowerCase().contains(
|
patch.name.toLowerCase().contains(
|
||||||
query.toLowerCase(),
|
query.toLowerCase(),
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
|
@ -72,7 +72,7 @@ class PatchSelectorCard extends StatelessWidget {
|
||||||
String _getPatchesSelection() {
|
String _getPatchesSelection() {
|
||||||
String text = '';
|
String text = '';
|
||||||
for (Patch p in locator<PatcherViewModel>().selectedPatches) {
|
for (Patch p in locator<PatcherViewModel>().selectedPatches) {
|
||||||
text += '${p.simpleName} (v${p.version})\n';
|
text += '${p.getSimpleName()} (v${p.version})\n';
|
||||||
}
|
}
|
||||||
return text.substring(0, text.length - 1);
|
return text.substring(0, text.length - 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue