image_patcher.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #!/bin/bash
  2. # fakemurk.sh v1
  3. # by coolelectronics with help from r58
  4. # sets up all required scripts for spoofing os verification in devmode
  5. # this script bundles crossystem.sh and vpd.sh
  6. # crossystem.sh v3.0.0
  7. # made by r58Playz and stackoverflow
  8. # emulates crossystem but with static values to trick chromeos and google
  9. # version history:
  10. # v3.0.0 - implemented mutable crossystem values
  11. # v2.0.0 - implemented all functionality
  12. # v1.1.1 - hotfix for stupid crossystem
  13. # v1.1.0 - implemented <var>?<value> functionality (searches for value in var)
  14. # v1.0.0 - basic functionality implemented
  15. # image_patcher.sh
  16. # written based on the original by coolelectronics and r58, modified heavily for murkmod
  17. CURRENT_MAJOR=6
  18. CURRENT_MINOR=0
  19. CURRENT_VERSION=0
  20. # God damn, there are a lot of unused functions in here!
  21. # future rainestorme: finally cleaned it up! :D
  22. ascii_info() {
  23. echo -e " __ .___\n _____ __ _________| | __ _____ ____ __| _/\n / \| | \_ __ \ |/ // \ / _ \ / __ | \n| Y Y \ | /| | \/ <| Y Y ( <_> ) /_/ | \n|__|_| /____/ |__| |__|_ \__|_| /\____/\____ | \n \/ \/ \/ \/\n"
  24. echo " The fakemurk plugin manager - v$CURRENT_MAJOR.$CURRENT_MINOR.$CURRENT_VERSION"
  25. # spaces get mangled by makefile, so this must be separate
  26. }
  27. nullify_bin() {
  28. cat <<-EOF >$1
  29. #!/bin/bash
  30. exit
  31. EOF
  32. chmod 777 $1
  33. # shebangs crash makefile
  34. }
  35. . /usr/share/misc/chromeos-common.sh || :
  36. traps() {
  37. set -e
  38. trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
  39. trap 'echo "\"${last_command}\" command failed with exit code $?. THIS IS A BUG, REPORT IT HERE https://github.com/MercuryWorkshop/fakemurk"' EXIT
  40. }
  41. leave() {
  42. trap - EXIT
  43. echo "exiting successfully"
  44. exit
  45. }
  46. sed_escape() {
  47. echo -n "$1" | while read -n1 ch; do
  48. if [[ "$ch" == "" ]]; then
  49. echo -n "\n"
  50. # dumbass shellcheck not expanding is the entire point
  51. fi
  52. echo -n "\\x$(printf %x \'"$ch")"
  53. done
  54. }
  55. move_bin() {
  56. if test -f "$1"; then
  57. mv "$1" "$1.old"
  58. fi
  59. }
  60. disable_autoupdates() {
  61. # thanks phene i guess?
  62. # this is an intentionally broken url so it 404s, but doesn't trip up network logging
  63. sed -i "$ROOT/etc/lsb-release" -e "s/CHROMEOS_AUSERVER=.*/CHROMEOS_AUSERVER=$(sed_escape "https://updates.gooole.com/update")/"
  64. # we don't want to take ANY chances
  65. move_bin "$ROOT/usr/sbin/chromeos-firmwareupdate"
  66. nullify_bin "$ROOT/usr/sbin/chromeos-firmwareupdate"
  67. # bye bye trollers! (trollers being cros devs)
  68. rm -rf "$ROOT/opt/google/cr50/firmware/" || :
  69. }
  70. SCRIPT_DIR=$(dirname "$0")
  71. configure_binaries(){
  72. if [ -f /sbin/ssd_util.sh ]; then
  73. SSD_UTIL=/sbin/ssd_util.sh
  74. elif [ -f /usr/share/vboot/bin/ssd_util.sh ]; then
  75. SSD_UTIL=/usr/share/vboot/bin/ssd_util.sh
  76. elif [ -f "${SCRIPT_DIR}/lib/ssd_util.sh" ]; then
  77. SSD_UTIL="${SCRIPT_DIR}/lib/ssd_util.sh"
  78. else
  79. echo "ERROR: Cannot find the required ssd_util script. Please make sure you're executing this script inside the directory it resides in"
  80. exit 1
  81. fi
  82. }
  83. patch_root() {
  84. echo "Staging populator..."
  85. >$ROOT/population_required
  86. >$ROOT/reco_patched
  87. echo "Murkmod-ing root..."
  88. echo "Disabling autoupdates..."
  89. disable_autoupdates
  90. local milestone=$(lsbval CHROMEOS_RELEASE_CHROME_MILESTONE $ROOT/etc/lsb-release)
  91. echo "Installing startup scripts..."
  92. move_bin "$ROOT/sbin/chromeos_startup.sh"
  93. if [ "$milestone" -gt "116" ]; then
  94. echo "Detected newer version of CrOS, using new chromeos_startup"
  95. move_bin "$ROOT/sbin/chromeos_startup"
  96. install "chromeos_startup.sh" $ROOT/sbin/chromeos_startup
  97. chmod 755 $ROOT/sbin/chromeos_startup # whoops
  98. touch $ROOT/new-startup
  99. else
  100. move_bin "$ROOT/sbin/chromeos_startup.sh"
  101. install "chromeos_startup.sh" $ROOT/sbin/chromeos_startup.sh
  102. chmod 755 $ROOT/sbin/chromeos_startup.sh
  103. fi
  104. echo "Installing murkmod components..."
  105. install "daemon.sh" $ROOT/sbin/murkmod-daemon.sh
  106. move_bin "$ROOT/usr/bin/crosh"
  107. install "mush.sh" $ROOT/usr/bin/crosh
  108. echo "Installing startup services..."
  109. install "pre-startup.conf" $ROOT/etc/init/pre-startup.conf
  110. install "cr50-update.conf" $ROOT/etc/init/cr50-update.conf
  111. echo "Installing other utilities..."
  112. install "ssd_util.sh" $ROOT/usr/share/vboot/bin/ssd_util.sh
  113. install "image_patcher.sh" $ROOT/sbin/image_patcher.sh
  114. install "crossystem_boot_populator.sh" $ROOT/sbin/crossystem_boot_populator.sh
  115. install "ssd_util.sh" $ROOT/usr/share/vboot/bin/ssd_util.sh
  116. mkdir -p "$ROOT/etc/opt/chrome/policies/managed"
  117. install "pollen.json" $ROOT/etc/opt/chrome/policies/managed/policy.json
  118. echo "Chmod-ing everything..."
  119. chmod 777 $ROOT/sbin/murkmod-daemon.sh $ROOT/usr/bin/crosh $ROOT/usr/share/vboot/bin/ssd_util.sh $ROOT/sbin/image_patcher.sh $ROOT/etc/opt/chrome/policies/managed/policy.json $ROOT/sbin/crossystem_boot_populator.sh $ROOT/usr/share/vboot/bin/ssd_util.sh
  120. echo "Done."
  121. }
  122. # https://chromium.googlesource.com/chromiumos/docs/+/main/lsb-release.md
  123. lsbval() {
  124. local key="$1"
  125. local lsbfile="${2:-/etc/lsb-release}"
  126. if ! echo "${key}" | grep -Eq '^[a-zA-Z0-9_]+$'; then
  127. return 1
  128. fi
  129. sed -E -n -e \
  130. "/^[[:space:]]*${key}[[:space:]]*=/{
  131. s:^[^=]+=[[:space:]]*::
  132. s:[[:space:]]+$::
  133. p
  134. }" "${lsbfile}"
  135. }
  136. get_asset() {
  137. curl -s -f "https://api.github.com/repos/rainestorme/murkmod/contents/$1" | jq -r ".content" | base64 -d
  138. }
  139. install() {
  140. TMP=$(mktemp)
  141. get_asset "$1" >"$TMP"
  142. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  143. echo "Failed to install $1 to $2"
  144. rm -f "$TMP"
  145. exit
  146. fi
  147. # Don't mv, that would break permissions
  148. cat "$TMP" >"$2"
  149. rm -f "$TMP"
  150. }
  151. main() {
  152. traps
  153. ascii_info
  154. configure_binaries
  155. echo $SSD_UTIL
  156. if [ -z $1 ] || [ ! -f $1 ]; then
  157. echo "\"$1\" isn't a real file, dipshit! You need to pass the path to the recovery image. Optional args: <path to custom bootsplash: path to a png> <unfuck stateful: int 0 or 1>"
  158. exit
  159. fi
  160. if [ -z $2 ]; then
  161. echo "Not using a custom bootsplash."
  162. local bootsplash="0"
  163. elif [ "$2" == "cros" ]; then
  164. echo "Using cros bootsplash."
  165. local bootsplash="cros"
  166. elif [ ! -f $2 ]; then
  167. echo "File $2 not found for custom bootsplash"
  168. local bootsplash="0"
  169. else
  170. echo "Using custom bootsplash $2"
  171. local bootsplash=$2
  172. fi
  173. if [ -z $3 ]; then
  174. local unfuckstateful="1"
  175. else
  176. local unfuckstateful=$3
  177. fi
  178. if [ "$unfuckstateful" == "1" ]; then
  179. echo "Will unfuck stateful partition upon boot."
  180. fi
  181. local bin=$1
  182. echo "Creating loop device..."
  183. local loop=$(losetup -f)
  184. losetup -P "$loop" "$bin"
  185. echo "Disabling kernel verity..."
  186. $SSD_UTIL --debug --remove_rootfs_verification -i ${loop} --partitions 4
  187. echo "Enabling RW mount..."
  188. $SSD_UTIL --debug --remove_rootfs_verification --no_resign_kernel -i ${loop} --partitions 2
  189. # for good measure
  190. sync
  191. echo "Mounting target..."
  192. mkdir /tmp/mnt || :
  193. mount "${loop}p3" /tmp/mnt
  194. ROOT=/tmp/mnt
  195. patch_root
  196. if [ "$bootsplash" != "cros" ]; then
  197. if [ "$bootsplash" != "0" ]; then
  198. echo "Adding custom bootsplash..."
  199. for i in $(seq -f "%02g" 0 30); do
  200. rm $ROOT/usr/share/chromeos-assets/images_100_percent/boot_splash_frame${i}.png
  201. done
  202. cp $bootsplash $ROOT/usr/share/chromeos-assets/images_100_percent/boot_splash_frame00.png
  203. else
  204. echo "Adding murkmod bootsplash..."
  205. install "chromeos-bootsplash-v2.png" /tmp/bootsplash.png
  206. for i in $(seq -f "%02g" 0 30); do
  207. rm $ROOT/usr/share/chromeos-assets/images_100_percent/boot_splash_frame${i}.png
  208. done
  209. cp /tmp/bootsplash.png $ROOT/usr/share/chromeos-assets/images_100_percent/boot_splash_frame00.png
  210. rm /tmp/bootsplash.png
  211. fi
  212. fi
  213. if [ "$unfuckstateful" == "0" ]; then
  214. touch $ROOT/stateful_unfucked
  215. chmod 777 $ROOT/stateful_unfucked
  216. # by creating the flag in advance we can prevent running mkfs.ext4 on stateful upon next boot, thus retaining user data
  217. fi
  218. sleep 2
  219. sync
  220. echo "Done. Have fun."
  221. umount "$ROOT"
  222. sync
  223. losetup -D "$loop"
  224. sync
  225. sleep 2
  226. rm -rf /tmp/mnt
  227. leave
  228. }
  229. if [ "$0" = "$BASH_SOURCE" ]; then
  230. stty sane
  231. if [ "$EUID" -ne 0 ]; then
  232. echo "Please run as root"
  233. exit
  234. fi
  235. main "$@"
  236. fi