Skip to content

Commit

Permalink
config: Install FRP wipe script into recovery /system/bin
Browse files Browse the repository at this point in the history
Change-Id: I24e217e6af87f2002193ac7b6defb158cce0a776
  • Loading branch information
luk1337 committed Feb 22, 2025
1 parent 3d683b1 commit 4d616dc
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST += \
system/%/libfuse-lite.so \
system/%/libntfs-3g.so

# FRP
PRODUCT_COPY_FILES += \
vendor/lineage/prebuilt/common/bin/wipe-frp.sh:$(TARGET_COPY_OUT_RECOVERY)/root/system/bin/wipe-frp

# Openssh
PRODUCT_PACKAGES += \
scp \
Expand Down
68 changes: 68 additions & 0 deletions prebuilt/common/bin/wipe-frp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/system/bin/sh
#
# SPDX-FileCopyrightText: 2025 The LineageOS Project
# SPDX-License-Identifier: Apache-2.0
#

FRP_BLOCK=$(getprop ro.frp.pst)

if [[ -z "${FRP_BLOCK}" ]]; then
echo "FRP prop not set"
exit -1
fi

FRP_BLOCK_SIZE=$(blockdev --getsize64 "${FRP_BLOCK}")

if [[ "${FRP_BLOCK_SIZE}" -le 0 ]]; then
echo "FRP block size <= 0"
exit -1
fi

# Calculate offsets
DIGEST_SIZE=32
DIGEST_OFFSET=0

FRP_OEM_UNLOCK_SIZE=1
FRP_OEM_UNLOCK_OFFSET=$((${FRP_BLOCK_SIZE} - 1))

FRP_CREDENTIAL_RESERVED_SIZE=1000
FRP_CREDENTIAL_RESERVED_OFFSET=$((${FRP_OEM_UNLOCK_OFFSET} - ${FRP_CREDENTIAL_RESERVED_SIZE}))

TEST_MODE_RESERVED_SIZE=10000
TEST_MODE_RESERVED_OFFSET=$((${FRP_CREDENTIAL_RESERVED_OFFSET} - ${TEST_MODE_RESERVED_SIZE}))

FRP_SECRET_SIZE=32
FRP_SECRET_OFFSET=$((${TEST_MODE_RESERVED_OFFSET} - ${FRP_SECRET_SIZE}))

FRP_SECRET_MAGIC_SIZE=8
FRP_SECRET_MAGIC_OFFSET=$((${FRP_SECRET_OFFSET} - ${FRP_SECRET_MAGIC_SIZE}))

# Clear digest
dd if=/dev/zero of="${FRP_BLOCK}" \
seek="${DIGEST_OFFSET}" \
count="${DIGEST_SIZE}" \
bs=1

# Clear credential storage
dd if=/dev/zero of="${FRP_BLOCK}" \
seek="${FRP_CREDENTIAL_RESERVED_OFFSET}" \
count="${FRP_CREDENTIAL_RESERVED_SIZE}" \
bs=1

# Clear FRP secret
dd if=/dev/zero of="${FRP_BLOCK}" \
seek="${FRP_SECRET_OFFSET}" \
count="${FRP_SECRET_SIZE}" \
bs=1

# Write default FRP secret magic
printf "\xDA\xC2\xFC\xCD\xB9\x1B\x09\x88" | dd of="${FRP_BLOCK}" \
seek="${FRP_SECRET_MAGIC_OFFSET}" \
count="${FRP_SECRET_MAGIC_SIZE}" \
bs=1

# Write digest
sha256sum -b "${FRP_BLOCK}" | xxd -r -p | dd of="${FRP_BLOCK}" \
seek="${DIGEST_OFFSET}" \
count="${DIGEST_SIZE}" \
bs=1

0 comments on commit 4d616dc

Please sign in to comment.