crossystem_boot_populator.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/bash
  2. # crossystem.sh v3.0.0
  3. # made by r58Playz and stackoverflow
  4. # emulates crossystem but with static values to trick chromeos and google
  5. # version history:
  6. # v3.0.0 - implemented mutable crossystem values
  7. # v2.0.0 - implemented all functionality
  8. # v1.1.1 - hotfix for stupid crossystem
  9. # v1.1.0 - implemented <var>?<value> functionality (searches for value in var)
  10. # v1.0.0 - basic functionality implemented
  11. # script gutted by rainestorme for murkmod
  12. . /usr/share/misc/chromeos-common.sh || :
  13. csys() {
  14. if [ "$COMPAT" == "1" ]; then
  15. crossystem "$@"
  16. elif test -f "$ROOT/usr/bin/crossystem.old"; then
  17. "$ROOT/usr/bin/crossystem.old" "$@"
  18. else
  19. "$ROOT/usr/bin/crossystem" "$@"
  20. fi
  21. }
  22. sed_escape() {
  23. echo -n "$1" | while read -n1 ch; do
  24. if [[ "$ch" == "" ]]; then
  25. echo -n "\n"
  26. # dumbass shellcheck not expanding is the entire point
  27. fi
  28. echo -n "\\x$(printf %x \'"$ch")"
  29. done
  30. }
  31. # the only reason this blob is still here is because i don't want to add network dependency for a boot-time script
  32. raw_crossystem_sh() {
  33. base64 -d <<-EOF | bunzip2 -dc
  34. QlpoOTFBWSZTWRXa7LcAA5f/kH/+Zvh///h////frv////4AEGAL+t924LTV3srpcuYdUAAAAAGlAAEMSE0mCaADRNU/SR6j0yma
  35. ah6j1Hkh4o09RoD9UA0PU3qj9Ub1MoGpkyCYhDTRQaeoAaAAaNAAAAANDaaQAMNVP00ymiahkeptQeoAAGgAAAAAAAADQ09QSalK
  36. j8pNPKPUYmJp6hoADRpkAaDQD1AAAAAAHDQDQAGgNAaAAABpo00AZAAANGmQYSJBACNAIBFPET0QaMQNNDRoAbUaDQ9RoNAN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
  68. oQmVIZfSexkCL8rr1S3SBDBQ0RoRbQwV7CozQxC+1BkrlPcdbbeIRE0lIKk5yCzsKIkilM7CzFGpiGEiSNpnjiSV+wMAiZqI/6CP
  69. MIsN1VpK0MmM9WntNXeys+Bu3CqtuDJeqQiEplmoz/231qK1H2GB69xrvXMwYBnANhkP1hdfWPruziGXSYr947gmhF5RSgbIPPRE
  70. BwqdQZgDQEjajysTORCDBUB2wG412634AYpbilG77BrAvDIxNyaSO2L6DlLIlEUcxhNrSUBs7ec5pKw2iytXqbpgVA35dxkBP7WU
  71. bzVPfi2mxFTkn/F3JFOFCQFdrstw
  72. EOF
  73. }
  74. drop_crossystem_sh() {
  75. # this weird space replacement is used because "read" has odd behaviour with spaces and newlines
  76. # i don't need to worry about the jank because crossystem will never have user controlled data
  77. vals=$(sed "s/ /THIS_IS_A_SPACE_DUMBASS/g" <<<"$(crossystem_values)")
  78. raw_crossystem_sh | sed -e "s/#__SED_REPLACEME_CROSSYSTEM_VALUES#/$(sed_escape "$vals")/g" | sed -e "s/THIS_IS_A_SPACE_DUMBASS/ /g" >"$ROOT/usr/bin/crossystem"
  79. chmod 777 "$ROOT/usr/bin/crossystem"
  80. }
  81. escape() {
  82. case $1 in
  83. '' | *[!0-9]*) echo -n "\"$1\"" ;;
  84. *) echo -n "$1" ;;
  85. esac
  86. }
  87. crossystem_values() {
  88. readarray -t csys_lines <<<"$(csys)"
  89. for element in "${csys_lines[@]}"; do
  90. line_stripped=$(echo "$element" | sed -e "s/#.*//g" | sed -e 's/ .*=/=/g')
  91. # sed 1: cuts out all chars after the #
  92. # sed 2: cuts out all spaces before =
  93. IFS='=' read -r -a pair <<<"$line_stripped"
  94. key=${pair[0]}
  95. # cut out all characters after an instance of 2 spaces in a row
  96. val="$(echo ${pair[1]} | sed -e 's/ .*//g')"
  97. if [ "$key" == "devsw_cur" ]; then
  98. val=0
  99. fi
  100. if [ "$key" == "devsw_boot" ]; then
  101. val=0
  102. fi
  103. if [ "$key" == "mainfw_type" ]; then
  104. val="normal"
  105. fi
  106. if [ "$key" == "mainfw_act" ]; then
  107. val="A"
  108. fi
  109. if [ "$key" == "cros_debug" ]; then
  110. val=1
  111. fi
  112. if [ "$key" == "dev_boot_legacy" ]; then
  113. val=0
  114. fi
  115. if [ "$key" == "dev_boot_signed_only" ]; then
  116. val=0
  117. fi
  118. if [ "$key" == "dev_boot_usb" ]; then
  119. val=0
  120. fi
  121. if [ "$key" == "dev_default_boot" ]; then
  122. val="disk"
  123. fi
  124. if [ "$key" == "dev_enable_udc" ]; then
  125. val=0
  126. fi
  127. if [ "$key" == "alt_os_enabled" ]; then
  128. val=0
  129. fi
  130. if [ "$key" == "recoverysw_boot" ]; then
  131. val=0
  132. fi
  133. if [ "$key" == "recoverysw_cur" ]; then
  134. val=0
  135. fi
  136. echo "$key=$(escape "$val")"
  137. done
  138. }
  139. mv "$ROOT/usr/bin/crossystem" "$ROOT/usr/bin/crossystem.old"
  140. drop_crossystem_sh