From de5a8b8b8711538fbf3f4e1a9d730d870e6ec1eb Mon Sep 17 00:00:00 2001 From: KOWX712 Date: Tue, 4 Mar 2025 03:45:19 +0800 Subject: [PATCH] misc: disable security patch auto config by default --- module/install_func.sh | 10 +-- module/service.sh | 2 +- module/uninstall.sh | 2 +- module/webui/scripts/security_patch.js | 93 +++++++++++--------------- 4 files changed, 47 insertions(+), 60 deletions(-) diff --git a/module/install_func.sh b/module/install_func.sh index 89509cd..5bc1fba 100644 --- a/module/install_func.sh +++ b/module/install_func.sh @@ -40,11 +40,11 @@ migrate_config() { fi # Migrate security_patch config* - if [ ! -s "/data/adb/security_patch" ]; then - echo "#Tricky Addon security patch auto config" > "/data/adb/security_patch" - fi - if ! grep -q "^auto_config=" "/data/adb/security_patch"; then - echo "auto_config=1" >> "/data/adb/security_patch" + if [ -f "/data/adb/security_patch" ]; then + if grep -q "^auto_config=1" "/data/adb/security_patch"; then + touch "/data/adb/tricky_store/security_patch_auto_config" + fi + rm -f "/data/adb/security_patch" fi # Additional system app diff --git a/module/service.sh b/module/service.sh index e3fca8e..9b6ea4a 100644 --- a/module/service.sh +++ b/module/service.sh @@ -23,7 +23,7 @@ add_denylist_to_target() { } # Spoof security patch -if grep -q "^auto_config=1" "/data/adb/security_patch"; then +if [ -f "/data/adb/tricky_store/security_patch_auto_config" ]; then sh "$MODPATH/common/get_extra.sh" --security-patch fi diff --git a/module/uninstall.sh b/module/uninstall.sh index 940bf6e..e1fbd0f 100644 --- a/module/uninstall.sh +++ b/module/uninstall.sh @@ -10,7 +10,7 @@ fi # Remove residue and restore aosp keybox. rm -rf "/data/adb/modules/.TA_utl" rm -f "/data/adb/boot_hash" -rm -f "/data/adb/security_patch" +rm -f "/data/adb/tricky_store/security_patch_auto_config" rm -f "/data/adb/tricky_store/target_from_denylist" rm -f "/data/adb/tricky_store/system_app" if [ -d "$TS" ]; then diff --git a/module/webui/scripts/security_patch.js b/module/webui/scripts/security_patch.js index 5cabf8e..df88e13 100644 --- a/module/webui/scripts/security_patch.js +++ b/module/webui/scripts/security_patch.js @@ -36,7 +36,7 @@ async function handleSecurityPatch(mode, value = null) { if (mode === 'disable') { try { await execCommand(` - sed -i "s/^auto_config=.*/auto_config=0/" /data/adb/security_patch + rm -f /data/adb/tricky_store/security_patch_auto_config rm -f /data/adb/tricky_store/security_patch.txt `); showPrompt('security_patch.value_empty'); @@ -48,7 +48,7 @@ async function handleSecurityPatch(mode, value = null) { } else if (mode === 'manual') { try { await execCommand(` - sed -i "s/^auto_config=.*/auto_config=0/" /data/adb/security_patch + rm -f /data/adb/tricky_store/security_patch_auto_config echo "${value}" > /data/adb/tricky_store/security_patch.txt chmod 644 /data/adb/tricky_store/security_patch.txt `); @@ -63,60 +63,47 @@ async function handleSecurityPatch(mode, value = null) { // Load current configuration async function loadCurrentConfig() { + let allValue, systemValue, bootValue, vendorValue; try { - const result = await execCommand('cat /data/adb/security_patch'); - if (result) { - const lines = result.split('\n'); - let autoConfig = '1', allValue = '0', systemValue = '0', bootValue = '0', vendorValue = '0'; - for (const line of lines) { - if (line.startsWith('auto_config=')) { - autoConfig = line.split('=')[1]; - } - } - - if (autoConfig === '1') { - allValue = null; - systemValue = null; - bootValue = null; - vendorValue = null; - overlay.classList.add('hidden'); - } else { - // Read values from tricky_store if auto_config is 0 - const trickyResult = await execCommand('cat /data/adb/tricky_store/security_patch.txt'); - if (trickyResult) { - const trickyLines = trickyResult.split('\n'); - for (const line of trickyLines) { - if (line.startsWith('all=')) { - allValue = line.split('=')[1] || null; - if (allValue !== null) allPatchInput.value = allValue; - } else { - allValue = null; - } - if (line.startsWith('system=')) { - systemValue = line.split('=')[1] || null; - if (systemValue !== null) systemPatchInput.value = systemValue; - } else { - systemValue = null; - } - if (line.startsWith('boot=')) { - bootValue = line.split('=')[1] || null; - if (bootValue !== null) bootPatchInput.value = bootValue; - } else { - bootValue = null; - } - if (line.startsWith('vendor=')) { - vendorValue = line.split('=')[1] || null; - if (vendorValue !== null) vendorPatchInput.value = vendorValue; - } else { - vendorValue = null; - } + const autoConfig = await execCommand('[ -f /data/adb/tricky_store/security_patch_auto_config ] && echo "true" || echo "false"'); + if (autoConfig.trim() === 'true') { + allValue = null; + systemValue = null; + bootValue = null; + vendorValue = null; + } else { + // Read values from tricky_store if auto_config is 0 + const trickyResult = await execCommand('cat /data/adb/tricky_store/security_patch.txt'); + if (trickyResult) { + const trickyLines = trickyResult.split('\n'); + for (const line of trickyLines) { + if (line.startsWith('all=')) { + allValue = line.split('=')[1] || null; + if (allValue !== null) allPatchInput.value = allValue; + } else { + allValue = null; + } + if (line.startsWith('system=')) { + systemValue = line.split('=')[1] || null; + if (systemValue !== null) systemPatchInput.value = systemValue; + } else { + systemValue = null; + } + if (line.startsWith('boot=')) { + bootValue = line.split('=')[1] || null; + if (bootValue !== null) bootPatchInput.value = bootValue; + } else { + bootValue = null; + } + if (line.startsWith('vendor=')) { + vendorValue = line.split('=')[1] || null; + if (vendorValue !== null) vendorPatchInput.value = vendorValue; + } else { + vendorValue = null; } } - overlay.classList.add('hidden'); } - - // Check if in advanced mode - if (autoConfig === '0' && allValue === null && (bootValue || systemValue || vendorValue)) { + if (allValue === null && (bootValue || systemValue || vendorValue)) { checkAdvanced(true); } } @@ -239,7 +226,7 @@ export function securityPatch() { if (output.trim() === "not set") { showPrompt('security_patch.auto_failed', false); } else { - await execCommand(`sed -i "s/^auto_config=.*/auto_config=1/" /data/adb/security_patch`); + await execCommand(`touch /data/adb/tricky_store/security_patch_auto_config`); // Reset inputs allPatchInput.value = ''; systemPatchInput.value = '';