diff --git a/.gitignore b/.gitignore index d4fb281..a39b6c2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,40 +2,5 @@ *.d # Compiled Object files -*.slo -*.lo *.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Linker files -*.ilk - -# Debugger Files -*.pdb - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# debug information files -*.dwo +*.zip diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9adef8d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright 2025 Yağız Zengin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +cmake_minimum_required(VERSION 3.10) +project(disable_watchdog VERSION 1.0) + +add_executable(disable_watchdog disable_watchdog.cpp) +target_link_libraries(disable_watchdog PRIVATE log) diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..06c7ad7 --- /dev/null +++ b/build.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# Copyright 2025 Yağız Zengin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e + +BUILD_64="build_arm64-v8a" +BUILD_32="build_armeabi-v7a" +THIS="$(basename $0)" + +echo() +{ + command echo "[$THIS]: $@" +} + +checks() +{ + if [ -z "$ANDROID_NDK" ]; then + echo "Please set ANDROID_NDK variable as your NDK path." + exit 1 + fi + if [ ! -f /usr/bin/cmake ] && [ ! -f /bin/cmake ]; then + echo "Please verify your CMake installation." + exit 1 + fi +} + +clean() +{ + echo "Cleaning workspace." + rm -rf $BUILD_32 $BUILD_64 +} + +build() +{ + mkdir -p $BUILD_64 $BUILD_32 + command echo -e "BUILD INFO: + ARCHS: arm64-v8a armeabi-v7a + ANDROID_PLATFORM: android-21 (android 5.0) + ANDROID_TOOLCHAIN_FILE: $ANDROID_NDK/build/cmake/android.toolchain.cmake\n" + + echo "Configuring for arm64-v8a..." + cmake -B $BUILD_64 -S . \ + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=arm64-v8a \ + -DANDROID_PLATFORM=android-21 + + echo "Configuring for armeabi-v7a..." + cmake -B $BUILD_32 -S . \ + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=armeabi-v7a \ + -DANDROID_PLATFORM=android-21 + + echo "Building arm64-v8a artifacts..." + cmake --build $BUILD_64 + echo "arm64-v8a build complete, artifacts: $PWD/$BUILD_64" + + echo "Building armeabi-v7a artifacts..." + cmake --build $BUILD_32 + echo "armeabi-v7a build complete, artifacts: $PWD/$BUILD_32" +} + +if [ $# -eq 0 ]; then + command echo "Usage: $0 build|rebuild|clean" + exit 1 +fi + +case $1 in + "build") checks; build ;; + "clean") clean ;; + "rebuild") clean; checks; build ;; + *) + command echo "$0: Unknown argument: $1" + exit 1 ;; +esac diff --git a/disable_watchdog.cpp b/disable_watchdog.cpp new file mode 100644 index 0000000..8bea976 --- /dev/null +++ b/disable_watchdog.cpp @@ -0,0 +1,77 @@ +/* + Copyright 2025 Yağız Zengin + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "disable_watchdog" +#include +#include + +bool suspendWatchdog(std::list files) +{ + bool suspendOk = false; + + for (const auto& file : files) { + int fd = open(file, O_WRONLY); + if (fd == -1) { + if (errno == ENOENT) { + int last = errno; + fd = open(file, O_WRONLY | O_CREAT, 644); + if (fd == -1) { + ALOGW("Cannot create %s: %s\n", file, strerror(errno)); + continue; + } + } else { + ALOGW("Cannot open %s: %s\n", file, strerror(errno)); + continue; + } + } + + char ch = 'V'; + if (write(fd, &ch, 1) != 1) { + ALOGW("Cannot write %s: %s\n", file, strerror(errno)); + close(fd); + continue; + } + + suspendOk = true; + ALOGI("%s: successfully suspended.\n", file); + close(fd); + } + + return suspendOk; +} + +int main(void) +{ + ALOGI("Service started.\n"); + + while (1) { + if (!suspendWatchdog({"/dev/watchdog1", "/dev/watchdog0", "/dev/watchdog"})) { + ALOGE("watchdog suspend fail!\n"); + break; + } + sleep(8); + } + + ALOGI("Service stopped!\n"); + return 1; +} diff --git a/mkmod.sh b/mkmod.sh new file mode 100644 index 0000000..db548aa --- /dev/null +++ b/mkmod.sh @@ -0,0 +1,109 @@ +#!/bin/bash +# +# Copyright 2025 Yağız Zengin +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e + +BUILD_64="build_arm64-v8a" +BUILD_32="build_armeabi-v7a" +MOD="watchdog_disabler_$(date +%Y-%M-%d).zip" +THIS="$(basename $0)" + +echo() { command echo "[$THIS]: $@"; } + +clean() +{ + rm -rf $MOD \ + $PWD/module/system/bin/disable_watchdog \ + $PWD/module/customize.sh + touch $PWD/module/system/bin/placeholder +} + +prepare() +{ + if [ ! -d $BUILD_32 ] || [ ! -d $BUILD_64 ]; then + echo "Missing artifacts. Please build!" + exit 1 + fi + + if [ ! -f /usr/bin/zip ] && [ ! -f /bin/zip ]; then + echo "Please verify your Zip installation!" + exit 1 + fi + + if [ -f $MOD ]; then rm $MOD; fi +} + +mk_customize() +{ + if [ $1 -eq 32 ]; then + cat </dev/null; then + echo "This module is compatible with 32-bit devices. Your device running a 64-bit system!" + exit 1 +fi +EOF + elif [ $1 -eq 64 ]; then + cat </dev/null; then + echo "This module is compatible with 64-bit devices. Your device running a 32-bit system!" + exit 1 +fi +EOF + else + cat < $PWD/customize.sh + chmod 755 $PWD/customize.sh + cp $dir/disable_watchdog $PWD/system/bin + zip -rq $MOD * + mv $MOD .. + cd .. + + echo "Created module package for $1-bit." +} + +if [ $# -eq 0 ]; then + command echo "Usage: $0 32|64|clean" + exit 1 +fi + +case $1 in + "32") prepare; mkzip 32 ;; + "64") prepare; mkzip 64 ;; + "clean") clean ;; + *) + command echo "$0: Unknown argument: $1" + exit 1 ;; +esac diff --git a/module/META-INF/com/google/android/update-binary b/module/META-INF/com/google/android/update-binary new file mode 100644 index 0000000..ea4889e --- /dev/null +++ b/module/META-INF/com/google/android/update-binary @@ -0,0 +1,33 @@ +#!/sbin/sh + +################# +# Initialization +################# + +umask 022 + +# echo before loading util_functions +ui_print() { echo "$1"; } + +require_new_magisk() { + ui_print "*******************************" + ui_print " Please install Magisk v20.4+! " + ui_print "*******************************" + exit 1 +} + +######################### +# Load util_functions.sh +######################### + +OUTFD=$2 +ZIPFILE=$3 + +mount /data 2>/dev/null + +[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk +. /data/adb/magisk/util_functions.sh +[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk + +install_module +exit 0 \ No newline at end of file diff --git a/module/META-INF/com/google/android/updater-script b/module/META-INF/com/google/android/updater-script new file mode 100644 index 0000000..11d5c96 --- /dev/null +++ b/module/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK diff --git a/module/module.prop b/module/module.prop new file mode 100644 index 0000000..f63c835 --- /dev/null +++ b/module/module.prop @@ -0,0 +1,6 @@ +id=watchdog_fix +name=Watchdog Fix +author=YZBruh +version=v1.0 +versionCode=1 +description=Disables watchdog diff --git a/module/service.sh b/module/service.sh new file mode 100644 index 0000000..6245438 --- /dev/null +++ b/module/service.sh @@ -0,0 +1,3 @@ +#!/system/bin/sh + +suspend_watchdog & diff --git a/module/system/bin/placeholder b/module/system/bin/placeholder new file mode 100644 index 0000000..e69de29