mirror of
https://github.com/leminlimez/Nugget.git
synced 2025-04-08 04:23:05 +08:00
randomize descriptor uuid & id (untested)
This commit is contained in:
16
controllers/plist_handler.py
Normal file
16
controllers/plist_handler.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import plistlib
|
||||||
|
|
||||||
|
def recursive_set(plist: dict, key: str, value: any):
|
||||||
|
new_plist: dict = plist
|
||||||
|
for curr_key in plist.keys:
|
||||||
|
if curr_key == key:
|
||||||
|
new_plist[curr_key] = value
|
||||||
|
elif isinstance(plist[curr_key], dict):
|
||||||
|
new_plist[curr_key] = recursive_set(plist[key], key, value)
|
||||||
|
return new_plist
|
||||||
|
|
||||||
|
def set_plist_value(file: str, key: str, value: any):
|
||||||
|
with open(file, 'rb') as in_fp:
|
||||||
|
plist = plistlib.load(in_fp)
|
||||||
|
new_plist = recursive_set(plist, key, value)
|
||||||
|
return plistlib.dumps(new_plist)
|
||||||
@@ -19,7 +19,7 @@ from tweaks.custom_gestalt_tweaks import CustomGestaltTweaks, ValueTypeStrings
|
|||||||
from tweaks.daemons_tweak import Daemon
|
from tweaks.daemons_tweak import Daemon
|
||||||
|
|
||||||
App_Version = "5.0"
|
App_Version = "5.0"
|
||||||
App_Build = 2
|
App_Build = 3
|
||||||
|
|
||||||
class Page(Enum):
|
class Page(Enum):
|
||||||
Home = 0
|
Home = 0
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
from .tweak_classes import Tweak
|
from .tweak_classes import Tweak
|
||||||
from Sparserestore.restore import FileToRestore
|
from Sparserestore.restore import FileToRestore
|
||||||
|
from controllers.plist_handler import set_plist_value
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import uuid
|
||||||
|
from random import randint
|
||||||
|
|
||||||
class PosterboardTweak(Tweak):
|
class PosterboardTweak(Tweak):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -11,24 +14,50 @@ class PosterboardTweak(Tweak):
|
|||||||
self.resetting = False
|
self.resetting = False
|
||||||
self.resetType = 0 # 0 for descriptor 1 for prb
|
self.resetType = 0 # 0 for descriptor 1 for prb
|
||||||
|
|
||||||
def recursive_add(self, files_to_restore: list[FileToRestore], curr_path: str, restore_path: str = "", isAdding: bool = False):
|
def update_plist_id(self, file_path: str, file_name: str, randomizedID: int):
|
||||||
|
if file_name == "com.apple.posterkit.provider.descriptor.identifier":
|
||||||
|
return randomizedID.to_bytes()
|
||||||
|
elif file_name == "com.apple.posterkit.provider.contents.userInfo":
|
||||||
|
return set_plist_value(file=os.path.join(file_path, file_name), key="wallpaperRepresentingIdentifier", value=randomizedID)
|
||||||
|
elif file_name == "Wallpaper.plist":
|
||||||
|
return set_plist_value(file=os.path.join(file_path, file_name), key="identifier", value=randomizedID)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def recursive_add(self,
|
||||||
|
files_to_restore: list[FileToRestore],
|
||||||
|
curr_path: str, restore_path: str = "",
|
||||||
|
isAdding: bool = False,
|
||||||
|
randomizeUUID: bool = False, randomizedID: int = None
|
||||||
|
):
|
||||||
for folder in sorted(os.listdir(curr_path)):
|
for folder in sorted(os.listdir(curr_path)):
|
||||||
if folder.startswith('.') or folder == "__MACOSX":
|
if folder.startswith('.') or folder == "__MACOSX":
|
||||||
continue
|
continue
|
||||||
if isAdding:
|
if isAdding:
|
||||||
|
# randomize uuid
|
||||||
|
folder_name = folder
|
||||||
|
if randomizeUUID:
|
||||||
|
folder_name = str(uuid.uuid4()).upper()
|
||||||
# if file then add it, otherwise recursively call again
|
# if file then add it, otherwise recursively call again
|
||||||
if os.path.isfile(os.path.join(curr_path, folder)):
|
if os.path.isfile(os.path.join(curr_path, folder)):
|
||||||
try:
|
try:
|
||||||
|
# update plist ids if needed
|
||||||
|
new_contents = None
|
||||||
|
contents_path = os.path.join(curr_path, folder)
|
||||||
|
if randomizedID != None:
|
||||||
|
new_contents = self.update_plist_id(curr_path, folder, randomizedID)
|
||||||
|
if new_contents != None:
|
||||||
|
contents_path = None
|
||||||
files_to_restore.append(FileToRestore(
|
files_to_restore.append(FileToRestore(
|
||||||
contents=None,
|
contents=new_contents,
|
||||||
contents_path=os.path.join(curr_path, folder),
|
contents_path=contents_path,
|
||||||
restore_path=f"{restore_path}/{folder}",
|
restore_path=f"{restore_path}/{folder_name}",
|
||||||
domain=f"AppDomain-{self.bundle_id}"
|
domain=f"AppDomain-{self.bundle_id}"
|
||||||
))
|
))
|
||||||
except IOError:
|
except IOError:
|
||||||
print(f"Failed to open file: {folder}") # TODO: Add QDebug equivalent
|
print(f"Failed to open file: {folder}") # TODO: Add QDebug equivalent
|
||||||
else:
|
else:
|
||||||
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), f"{restore_path}/{folder}", isAdding)
|
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), f"{restore_path}/{folder_name}", isAdding, randomizedID=randomizedID)
|
||||||
else:
|
else:
|
||||||
# look for container folder
|
# look for container folder
|
||||||
name = folder.lower()
|
name = folder.lower()
|
||||||
@@ -40,7 +69,8 @@ class PosterboardTweak(Tweak):
|
|||||||
files_to_restore,
|
files_to_restore,
|
||||||
os.path.join(curr_path, folder),
|
os.path.join(curr_path, folder),
|
||||||
restore_path="/Library/Application Support/PRBPosterExtensionDataStore/61/Extensions/com.apple.WallpaperKit.CollectionsPoster/descriptors",
|
restore_path="/Library/Application Support/PRBPosterExtensionDataStore/61/Extensions/com.apple.WallpaperKit.CollectionsPoster/descriptors",
|
||||||
isAdding=True
|
isAdding=True,
|
||||||
|
randomizeUUID=True, randomizedID=randint(9999, 99999)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), isAdding=False)
|
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), isAdding=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user