diff --git a/boot_patch.sh b/boot_patch.sh deleted file mode 100644 index fe35508..0000000 --- a/boot_patch.sh +++ /dev/null @@ -1,174 +0,0 @@ -#!/system/bin/sh -####################################################################################### -# Magisk Boot Image Patcher -####################################################################################### -# -# Usage: boot_patch.sh -# -# The following flags can be set in environment variables: -# KEEPVERITY, KEEPFORCEENCRYPT, RECOVERYMODE -# -# This script should be placed in a directory with the following files: -# -# File name Type Description -# -# boot_patch.sh script A script to patch boot image for Magisk. -# (this file) The script will use files in its same -# directory to complete the patching process -# util_functions.sh script A script which hosts all functions required -# for this script to work properly -# magiskinit binary The binary to replace /init -# magisk(32/64) binary The magisk binaries -# magiskboot binary A tool to manipulate boot images -# chromeos folder This folder includes the utility and keys to sign -# (optional) chromeos boot images. Only used for Pixel C. -# -####################################################################################### - -############ -# Functions -############ - -# Pure bash dirname implementation -getdir() { - case "$1" in - */*) - dir=${1%/*} - if [ -z $dir ]; then - echo "/" - else - echo $dir - fi - ;; - *) echo "." ;; - esac -} - -################# -# Initialization -################# - -[ -e "$BOOTIMAGE" ] || abort "$BOOTIMAGE does not exist!" - -# Dump image for MTD/NAND character device boot partitions -if [ -c "$BOOTIMAGE" ]; then - nanddump -f boot.img "$BOOTIMAGE" - BOOTNAND="$BOOTIMAGE" - BOOTIMAGE=boot.img -fi - -# Flags -[ -z $KEEPVERITY ] && KEEPVERITY=false -[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false -[ -z $RECOVERYMODE ] && RECOVERYMODE=false -export KEEPVERITY -export KEEPFORCEENCRYPT - -chmod -R 755 . - -######### -# Unpack -######### - -CHROMEOS=false - -ui_print "- Unpacking boot image" -$MAGISKBIN/magiskboot unpack "$BOOTIMAGE" - -case $? in - 0 ) ;; - 1 ) - abort "! Unsupported/Unknown image format" - ;; - 2 ) - ui_print "- ChromeOS boot image detected" - CHROMEOS=true - ;; - * ) - abort "! Unable to unpack boot image" - ;; -esac - -[ -f recovery_dtbo ] && RECOVERYMODE=true - -################### -# Ramdisk Restores -################### - -# Test patch status and do restore -ui_print "- Checking ramdisk status" -if [ -e ramdisk.cpio ]; then - $MAGISKBIN/magiskboot cpio ramdisk.cpio test - STATUS=$? -else - # Stock A only system-as-root - STATUS=0 -fi -case $((STATUS & 3)) in - 0 ) # Stock boot - ui_print "- Stock boot image detected" - abort "! magisk must be installed" - ;; - 1 ) # Magisk patched - ui_print "- Magisk patched boot image detected" - # Find SHA1 of stock boot image - [ -z $SHA1 ] && SHA1=$($MAGISKBIN/magiskboot cpio ramdisk.cpio sha1 2>/dev/null) - cp -af ramdisk.cpio ramdisk.cpio.stock.magisk - ;; - 2 ) # Unsupported - ui_print "! Boot image patched by unsupported programs" - abort "! Please restore back to stock boot image" - ;; -esac - -################## -# Ramdisk Patches -################## - -ui_print "- Patching ramdisk" - -echo "KEEPVERITY=$KEEPVERITY" > config -echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config -echo "RECOVERYMODE=$RECOVERYMODE" >> config -[ ! -z $SHA1 ] && echo "SHA1=$SHA1" >> config - -$MAGISKBIN/magiskboot cpio ramdisk.cpio "extract overlay.d/ghid.rc ghid.rc" 2>/dev/null -if ! diff $MODPATH/overlay.d/ghid.rc ghid.rc 2>/dev/null; then - ui_print "- Adding overlay.d/ghid.rc" - - $MAGISKBIN/magiskboot cpio ramdisk.cpio \ - "mkdir 755 overlay.d" \ - "add 755 overlay.d/ghid.rc $MODPATH/overlay.d/ghid.rc" - - rm -f ramdisk.cpio.orig config magisk*.xz - -################# -# Binary Patches -################# - - if [ $((STATUS & 4)) -ne 0 ]; then - ui_print "- Compressing ramdisk" - $MAGISKBIN/magiskboot cpio ramdisk.cpio compress - fi - - rm -f ramdisk.cpio.stock.magisk config ghid.rc -################# -# Repack & Flash -################# - - ui_print "- Repacking boot image" - $MAGISKBIN/magiskboot repack "$BOOTIMAGE" || abort "! Unable to repack boot image!" -# Sign chromeos boot -$CHROMEOS && sign_chromeos - - # Sign chromeos boot - $CHROMEOS && sign_chromeos -else - ui_print "- ghid.rc already installed. Skipping boot patching." - rm -f ramdisk.cpio.stock.magisk config ghid.rc -fi -# Restore the original boot partition path -[ -e "$BOOTNAND" ] && BOOTIMAGE="$BOOTNAND" - -# Reset any error code -true diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..55cc0f0 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +rm *.zip 2>/dev/null +eval $(grep -v ' ' module.prop) +printf '%s\n' * | grep -Ev '(zip|build.sh)$' | xargs zip -r "magisk-$name-$version-$versionCode.zip" +adb push "magisk-$name-$version-$versionCode.zip" /sdcard/ diff --git a/customize.sh b/customize.sh index dcfdafc..ac4461b 100644 --- a/customize.sh +++ b/customize.sh @@ -1,15 +1,22 @@ #!/bin/sh $BOOTMODE || abort "! must be installed in the running system" if [[ -e /proc/config.gz ]]; then - zcat /proc/config.gz | grep -Eq 'CONFIG_USB_(CONFIGFS_)?F_HID=[my]' || abort "! kernel does not have the required modules" + zcat /proc/config.gz | grep -Eq 'CONFIG_USB_(CONFIGFS_)?F_HID=[my]' || abort "! kernel does not have the required modules" else - [[ -d /config/usb_gadget ]] || abort "! kernel does not have the required modules" - mkdir /config/usb_gadget/g1 || abort "! kernel does not have the required modules" - mkdir /config/usb_gadget/g1/functions/hid.usb0 || abort "! kernel does not have the required modules" + test -d /config/usb_gadget || abort "! kernel does not have the required modules" + mkdir /config/usb_gadget/g1 || abort "! kernel does not have the required modules" + mkdir /config/usb_gadget/g1/functions/hid.usb0 || abort "! kernel does not have the required modules" fi chmod 755 "$MODPATH/system/bin/ghid.sh" -sed "s@\[MODDIR\]@$MODPATH@g" "$MODPATH/system/bin/ghid.sh" | sed 's/modules_update/modules/g' >"$TMPDIR/ghid.sh" -cp "$TMPDIR/ghid.sh" "$MODPATH/system/bin/ghid.sh" +sed -i -e "s@\[MODDIR\]@${MODPATH%_update}@g" "$MODPATH/system/bin/ghid.sh" -. "$MODPATH/utils.sh" -. "$MODPATH/flash_script.sh" +mkdir -p "$MODPATH/system/system_ext/etc/selinux/" "$MODPATH/system/etc" +{ + grep -v /dev/hidg /system_ext/etc/selinux/system_ext_file_contexts + echo "/dev/hidg[0-9]+ u:object_r:null_device:s0" +} >"$MODPATH/system/system_ext/etc/selinux/system_ext_file_contexts" + +{ + grep -v /dev/hidg /system/etc/ueventd.rc + echo "/dev/hidg* 0666 root root" +} >"$MODPATH/system/etc/ueventd.rc" diff --git a/flash_script.sh b/flash_script.sh deleted file mode 100644 index f16c315..0000000 --- a/flash_script.sh +++ /dev/null @@ -1,60 +0,0 @@ -#MAGISK -############################################ -# Magisk Flash Script (updater-script) -############################################ - -############## -# Preparation -############## - -find_magisk_apk -# Default permissions -umask 022 - -OUTFD=$2 -APK="$3" -COMMONDIR=$INSTALLER/assets -CHROMEDIR=$INSTALLER/assets/chromeos - -setup_flashable - -############ -# Detection -############ - -if echo $MAGISK_VER | grep -q '\.'; then - PRETTY_VER=$MAGISK_VER -else - PRETTY_VER="$MAGISK_VER($MAGISK_VER_CODE)" -fi -print_title "Magisk $PRETTY_VER Installer" - -is_mounted /data || mount /data || is_mounted /cache || mount /cache -mount_partitions -check_data -get_flags -find_boot_image - -[ -z $BOOTIMAGE ] && abort "! Unable to detect target image" -ui_print "- Target image: $BOOTIMAGE" - -# Detect version and architecture -api_level_arch_detect - -[ $API -lt 21 ] && abort "! Magisk only support Android 5.0 and above" - -ui_print "- Device platform: $ARCH" - - -################## -# Image Patching -################## - -install_magisk - -# Cleanups -$BOOTMODE || recovery_cleanup -rm -rf $TMPDIR - -ui_print "- Done" -exit 0 diff --git a/module.prop b/module.prop index 9d95e04..7e57353 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ id=ghid name=ghid -version=0.11 -versionCode=38 +version=0.12.69 +versionCode=69 author=lordwelch description=creates ghid device files in /dev diff --git a/overlay.d/ghid.rc b/overlay.d/ghid.rc deleted file mode 100644 index 0839314..0000000 --- a/overlay.d/ghid.rc +++ /dev/null @@ -1,8 +0,0 @@ -on property:sys.usb.ffs.ready=1 && property:sys.usb.config=* && property:sys.usb.configfs=1 - exec u:r:magisk:s0 root root -- /system/bin/ghid.sh setup ${sys.usb.config} - start ghid - -service ghid /system/bin/ghid.sh setup ${sys.usb.config} - user root - disabled - oneshot diff --git a/service.sh b/service.sh new file mode 100644 index 0000000..47825a1 --- /dev/null +++ b/service.sh @@ -0,0 +1,8 @@ +#!/bin/sh +ueventd=$(getprop init.svc.ueventd) +if [ "$ueventd" = "running" ]; then + # ueventd ensures that the correct permissions get applied, it may also apply the correct selabel, not sure + stop ueventd + start ueventd +fi +/system/bin/ghid.sh init diff --git a/system/bin/ghid.sh b/system/bin/ghid.sh index 7ea75c5..0b26ada 100644 --- a/system/bin/ghid.sh +++ b/system/bin/ghid.sh @@ -2,7 +2,7 @@ # $1 setup controller=$(getprop sys.usb.controller) moddir=[MODDIR] -selected=keyboard-standard + exec >>$moddir/ghid.log exec 2>>$moddir/ghid.log date @@ -11,68 +11,59 @@ set -o nohup set +o errexit set +o sh set +o posix -exec >>$moddir/ghid.log -exec 2>>$moddir/ghid.log +exec >>$moddir/oghid.log +exec 2>>$moddir/oghid.log remove_ghid() { - echo "disabling ghid" - rm /config/usb_gadget/g1/configs/b.1/fhid - rmdir /config/usb_gadget/g1/functions/hid.usb0 + echo "disabling ghid" + rm /config/usb_gadget/g1/configs/b.1/fhid + rmdir /config/usb_gadget/g1/functions/hid.usb0 } enable_ghid() { - for f in $selected; do - echo "enabling ghid" - running=true - . "$moddir/definitions/$f" - if [ ! -d /config/usb_gadget/g1/functions/hid.usb0 ]; then - mkdir /config/usb_gadget/g1/functions/hid.usb0 - fi - current_protocol="$(cat /config/usb_gadget/g1/functions/hid.usb0/protocol)" - current_subclass="$(cat /config/usb_gadget/g1/functions/hid.usb0/subclass)" - current_report_length="$(cat /config/usb_gadget/g1/functions/hid.usb0/report_length)" - echo "current ghid" - echo current_protocol $current_protocol - echo current_subclass $current_subclass - echo current_report_length $current_report_length + . "$moddir/definitions/keyboard-standard" + if [ ! -d /config/usb_gadget/g1/functions/hid.usb0 ]; then + mkdir /config/usb_gadget/g1/functions/hid.usb0 + fi + current_protocol="$(cat /config/usb_gadget/g1/functions/hid.usb0/protocol)" + current_subclass="$(cat /config/usb_gadget/g1/functions/hid.usb0/subclass)" + current_report_length="$(cat /config/usb_gadget/g1/functions/hid.usb0/report_length)" - if [ -e /config/usb_gadget/g1/functions/hid.usb0 -a "$current_protocol" == "$protocol" -a "$current_subclass" == "$subclass" -a "$current_report_length" == "$report_length" ] && diff "$moddir/reports/$report_name" /config/usb_gadget/g1/functions/hid.usb0/report_desc ; then - echo nothing to update - return 0 - fi + if [ -e /config/usb_gadget/g1/functions/hid.usb0 -a "$current_protocol" == "$protocol" -a "$current_subclass" == "$subclass" -a "$current_report_length" == "$report_length" ] && diff "$moddir/reports/$report_name" /config/usb_gadget/g1/functions/hid.usb0/report_desc; then + echo nothing to update + cd /config/usb_gadget/g1/configs/b.1/ + /data/adb/magisk/busybox ln -nsf ../../../../usb_gadget/g1/functions/hid.usb0 ./fhid + return 0 + fi - echo new ghid + echo new ghid - echo $protocol - echo $subclass - echo $report_length + echo protocol: $protocol + echo subclass: $subclass + echo report_length: $report_length - rm /config/usb_gadget/g1/configs/b.1/fhid - echo $protocol >/config/usb_gadget/g1/functions/hid.usb0/protocol - echo $subclass >/config/usb_gadget/g1/functions/hid.usb0/subclass - echo $report_length >/config/usb_gadget/g1/functions/hid.usb0/report_length - cp "$moddir/reports/$report_name" /config/usb_gadget/g1/functions/hid.usb0/report_desc - cd /config/usb_gadget/g1/configs/b.1/ - /data/adb/magisk/busybox ln -nsf ../../../../usb_gadget/g1/functions/hid.usb0 ./fhid - done - # echo none >/config/usb_gadget/g1/UDC - # echo "$controller" >/config/usb_gadget/g1/UDC + echo $protocol >/config/usb_gadget/g1/functions/hid.usb0/protocol + echo $subclass >/config/usb_gadget/g1/functions/hid.usb0/subclass + echo $report_length >/config/usb_gadget/g1/functions/hid.usb0/report_length + cat "$moddir/reports/$report_name" >/config/usb_gadget/g1/functions/hid.usb0/report_desc + cd /config/usb_gadget/g1/configs/b.1/ + /data/adb/magisk/busybox ln -nsf ../../../../usb_gadget/g1/functions/hid.usb0 ./fhid } echo success ghid was run with: "$@" -if ! [[ "$1" == "setup" ]]; then - exit 1 -fi -shift - case "$1" in - ""|"none" ) - remove_ghid - ;; - * ) - enable_ghid - ;; +"init") + enable_ghid + ;; +"remove") + remove_ghid + ;; +*) + shift + exit 0 + ;; esac -sh <<<'chcon u:object_r:null_device:s0 /dev/hidg*;chmod 666 /dev/hidg*;sleep 5;chcon u:object_r:null_device:s0 /dev/hidg*;chmod 666 /dev/hidg*;ls -alZ /dev/hidg*;' & + +restorecon /dev/hidg* diff --git a/utils.sh b/utils.sh deleted file mode 100644 index 570bc13..0000000 --- a/utils.sh +++ /dev/null @@ -1,63 +0,0 @@ -# get_flags() { -# # override variables -# getvar KEEPVERITY -# getvar KEEPFORCEENCRYPT -# getvar RECOVERYMODE -# if [ -z $KEEPVERITY ]; then -# if $SYSTEM_ROOT; then -# KEEPVERITY=true -# ui_print "- System-as-root, keep dm/avb-verity" -# else -# KEEPVERITY=false -# fi -# fi -# ISENCRYPTED=false -# grep ' /data ' /proc/mounts | grep -q 'dm-' && ISENCRYPTED=true -# [ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true -# if [ -z $KEEPFORCEENCRYPT ]; then -# # No data access means unable to decrypt in recovery -# if $ISENCRYPTED || ! $DATA; then -# KEEPFORCEENCRYPT=true -# ui_print "- Encrypted data, keep forceencrypt" -# else -# KEEPFORCEENCRYPT=false -# fi -# fi -# [ -z $RECOVERYMODE ] && RECOVERYMODE=false -# } - -install_magisk() { - cd $TMPDIR - - mkdir boot_patching - cd boot_patching/ - - # Dump image for MTD/NAND character device boot partitions - if [ -c $BOOTIMAGE ]; then - nanddump -f boot.img $BOOTIMAGE - local BOOTNAND=$BOOTIMAGE - BOOTIMAGE=boot.img - fi - - if [ $API -ge 21 ]; then - eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true - $BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0" - fi - - # Source the boot patcher - . "$MODPATH/boot_patch.sh" - - if [ -f new-boot.img ]; then - ui_print "- Flashing new boot image" - - # Restore the original boot partition path - [ "$BOOTNAND" ] && BOOTIMAGE=$BOOTNAND - flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size" - - rm -f new-boot.img - - run_migrations - fi - - $MAGISKBIN/magiskboot cleanup -}