fix config observer

This commit is contained in:
5ec1cff
2024-07-12 07:06:08 +08:00
parent 2db359090e
commit 8cac6c5a8c
3 changed files with 9 additions and 5 deletions

View File

@@ -34,12 +34,12 @@ object Config {
private const val KEYBOX_FILE = "keybox.xml"
private val root = File(CONFIG_PATH)
object ConfigObserver : FileObserver(root, CLOSE_WRITE or DELETE) {
object ConfigObserver : FileObserver(root, CLOSE_WRITE or DELETE or MOVED_FROM or MOVED_TO) {
override fun onEvent(event: Int, path: String?) {
path ?: return
val f = when (event) {
CLOSE_WRITE -> File(root, path)
DELETE -> null
CLOSE_WRITE, MOVED_TO -> File(root, path)
DELETE, MOVED_FROM -> null
else -> return
}
when (path) {

View File

@@ -33,7 +33,7 @@ object KeystoreInterceptor : BinderInterceptor() {
callingPid: Int,
data: Parcel
): Result {
if (code == targetTransaction) {
if (code == targetTransaction && CertHack.canHack() && Config.targetPackages.isNotEmpty()) {
Logger.d("intercept pre $target uid=$callingUid pid=$callingPid dataSz=${data.dataSize()}")
kotlin.runCatching {
val ps = getPm()?.getPackagesForUid(callingUid)

View File

@@ -55,6 +55,10 @@ public final class CertHack {
}
}
public static boolean canHack() {
return !keyboxes.isEmpty();
}
public static void readFromXml(String data) {
keyboxes.clear();
if (data == null) {
@@ -91,7 +95,7 @@ public final class CertHack {
}
Logger.i("update " + numberOfKeyboxes + " keyboxes");
} catch (Throwable t) {
Logger.e("Error loading xml file: " + t);
Logger.e("Error loading xml file (keyboxes cleared): " + t);
}
}