Skip to content

Commit f9bcf2c

Browse files
fix(ozip): Implement proper support for oppo_ozip_decrypt
1 parent ad7e681 commit f9bcf2c

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

extractor.sh

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ star="$toolsdir/$HOST/bin/star"
9090

9191
romzip="$(realpath $1)"
9292
romzipext="${romzip##*.}"
93+
filename="$(basename ${romzip%%.*})"
9394
PARTITIONS="super system vendor cust odm oem factory product xrom modem dtbo dtb boot recovery tz systemex oppo_product preload_common system_ext system_other opproduct reserve india my_preload my_odm my_stock my_operator my_country my_product my_company my_engineering my_heytap my_custom my_manifest my_carrier my_region my_bigball my_version special_preload vendor_dlkm odm_dlkm system_dlkm init_boot vendor_kernel_boot vendor_boot mi_ext boot-debug vendor_boot-debug hw_product product_h preas preavs"
9495
EXT4PARTITIONS="system vendor cust odm oem factory product xrom systemex oppo_product preload_common hw_product product_h preas preavs"
9596
OTHERPARTITIONS="tz.mbn:tz tz.img:tz modem.img:modem NON-HLOS:modem boot-verified.img:boot dtbo-verified.img:dtbo"
@@ -105,14 +106,44 @@ mkdir -p "$outdir"
105106
cd $tmpdir
106107

107108
MAGIC=$(head -c12 "$romzip" | tr -d '\0')
108-
if [[ $MAGIC == "OPPOENCRYPT!" ]] || [[ "$romzipext" == "ozip" ]]; then
109-
echo "ozip detected"
110-
cp "$romzip" "$tmpdir/temp.ozip"
111-
python3 $ozipdecrypt "$tmpdir/temp.ozip"
112-
if [[ -d "$tmpdir/out" ]]; then
113-
7z a -r "$tmpdir/temp.zip" "$tmpdir/out/*"
109+
110+
# File is '.ozip'
111+
if [[ "${MAGIC}" == "OPPOENCRYPT!" ]] || [[ "${romzipext}" == "ozip" ]]; then
112+
113+
# Function to archive directories to a fake image.
114+
directory_archive() {
115+
# We probably have 'vendor/' extracted to a directory.
116+
7z x "${tmpdir}/$(basename ${romzip%%.*}).zip" -o"${tmpdir}/ozip/"
117+
118+
# Set a variable for working directory
119+
WORKING_OZIP=${tmpdir}/ozip
120+
121+
# Convert all directories to 'images' (even though it's an archive)
122+
for image in recovery system vendor; do
123+
# Archive to a '.zip', first
124+
7z a -r ${outdir}/${image}.zip ${WORKING_OZIP}/${image}/*
125+
126+
# Move '.zip' to .'img' to get recognized by dumper
127+
mv ${outdir}/${image}.zip ${outdir}/${image}.img
128+
129+
# Remove remaining directory
130+
rm -rf ${outdir}/${image}/
131+
done
132+
}
133+
134+
# Copy over encrypted archive to our directory
135+
cp ${romzip} "${tmpdir}"
136+
137+
# Start decrypting the archive
138+
echo "[INFO] Decrypting '.ozip' through 'oppo_ozip_decrypt'..."
139+
python3 $ozipdecrypt "${tmpdir}/${filename}.ozip"
140+
141+
# Run extractor over decrypted archive
142+
if $(7z l "${tmpdir}/${filename}.zip" | grep -q system.img); then
143+
"$LOCALDIR/extractor.sh" "${tmpdir}/${filename}.zip" "$outdir"
144+
else
145+
directory_archive
114146
fi
115-
"$LOCALDIR/extractor.sh" "$tmpdir/temp.zip" "$outdir"
116147
exit
117148
fi
118149

0 commit comments

Comments
 (0)