Last active
October 8, 2024 16:43
-
-
Save thurask/bdd10b0799a17a608f7f9533562a844d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import gzip | |
import os | |
import shutil | |
import subprocess | |
import tarfile | |
import zipfile | |
from defusedxml import ElementTree | |
import yaml | |
""" | |
READ THIS FIRST: | |
*Run this on Linux, first of all | |
*Python 3.5+ is needed | |
*It will ask you for your sudo password, if you have a password set for it | |
*Have simg2img, abootimg, cpio, lz4 and Java (8 or 9) in your path (apt install simg2img abootimg cpio liblz4-tool on *buntu) | |
*Have pyyaml and defusedxml installed via pip (pip3/pip install pyyaml defusedxml) | |
*Have the apktool jar as ~/apktool_2.3.4.jar (change in script as needed) | |
*Run this script from same folder as the OS dump zip (blablabla.zip) | |
*Make sure only the download zip from SamFirm/Updato/whatever is in the folder | |
*Comment out the main#() functions in the bottom block if necessary | |
Currently tested on: | |
*S9 Oreo (USA, Canada, International, Korea) | |
*S8 Oreo (International) | |
*S8 Nougat (USA, Canada, International, Korea, China, Japan) | |
*S7 (USA, Korea, Japan) | |
*S6 (India) | |
*Note 8 Oreo (Canada) | |
*Note 8 Nougat (USA, Canada, International, Korea, China, Japan) | |
*Note FE (Korea) | |
*A8 2018 (International) | |
*A7 2017 (International, Korea) | |
*A5 2017 (Canada, International, Korea) | |
*A3 2017 (International) | |
*A5 2016 (International) | |
*C7 (China) | |
*J7 Prime (International) | |
*Tab S3 (WiFi, LTE) | |
""" | |
def md5out(indir): | |
files = [x for x in os.listdir(indir) if x.endswith(".tar.md5")] | |
fnames = [x.split("_")[0].replace("HOME", "HOME_CSC") for x in files] | |
fdict = {y:z for y, z in zip(fnames, files)} | |
for folder, name in fdict.items(): | |
print("DECOMPRESSING: {0}".format(name)) | |
with tarfile.open(name) as tarf: | |
tarf.extractall(os.path.join(indir, folder)) | |
def lz4out(indir): | |
dirs = [x for x in os.listdir(indir) if os.path.isdir(x)] | |
for dirx in dirs: | |
files = [os.path.join(indir, dirx, x) for x in os.listdir(dirx) if x.endswith(".lz4")] | |
for lzfile in files: | |
print("DECOMPRESSING: {0}".format(lzfile.replace(indir, ""))) | |
subprocess.run(["lz4", "-d", lzfile, lzfile.replace(".lz4", "")]) | |
def simg2img(indir, excepts=None): | |
if excepts is None: | |
excepts = ["dummy.nevergonnahappen"] | |
exts = [os.path.join(indir, x) for x in os.listdir(indir) if x.endswith(".img.ext4") and x not in excepts] | |
if not exts: | |
exts = [os.path.join(indir, x) for x in os.listdir(indir) if x.endswith(".img") and ".raw" not in x and x not in excepts] | |
for ext in exts: | |
print("DECOMPRESSING: {0}".format(os.path.basename(ext))) | |
subprocess.run(["simg2img", ext, ext.replace(".ext4", "").replace(".img", ".raw.img")]) | |
def indiv_abootimg(imgfile): | |
imgdir = os.path.dirname(imgfile) | |
imgname = os.path.basename(imgfile).split(".")[0] | |
outdir = os.path.join(imgdir, "output", imgname) | |
here = os.getcwd() | |
os.chdir(outdir) | |
with open(os.devnull, "wb") as dnull: | |
subprocess.run(["abootimg", "-x", imgfile], stdout=dnull, stderr=subprocess.STDOUT) | |
for image in ["initrd.img", "stage2.img"]: | |
imagepath = os.path.join(outdir, image) | |
if not os.path.exists(imagepath): | |
pass | |
else: | |
imagedir = os.path.join(outdir, image.split(".")[0]) | |
if not os.path.exists(imagedir): | |
os.makedirs(imagedir) | |
os.chdir(imagedir) | |
try: | |
gzdata = gunzip(imagepath) | |
except OSError: | |
continue | |
else: | |
with open(os.devnull, "wb") as dnull: | |
subprocess.run(["cpio", "-id"], input=gzdata, stdout=dnull, stderr=subprocess.STDOUT) | |
os.chdir(here) | |
def gunzip(gzfile): | |
with gzip.open(gzfile) as gunfile: | |
data = gunfile.read() | |
return data | |
def boot_recovery_extract(indir): | |
prep_output_dirs(indir, ["boot", "recovery"]) | |
for img in ["boot.img", "recovery.img"]: | |
indiv_abootimg(os.path.join(indir, img)) | |
def prep_output_dirs(indir, dirlist): | |
for dir in dirlist: | |
if not os.path.exists(dir): | |
os.makedirs(os.path.join(indir, "output", dir)) | |
def prep_dirs(indir): | |
loopdir = os.path.join(indir, "loop") | |
outdir = os.path.join(indir, "output") | |
for dir in (loopdir, outdir): | |
if not os.path.exists(dir): | |
os.makedirs(dir) | |
def remove_loop(indir): | |
os.rmdir(os.path.join(indir, "loop")) | |
def remove_empty_dirs(indir): | |
for root, dirs, files in os.walk(indir): | |
if not dirs and not files: | |
os.removedirs(root) | |
def indiv_imgextract(imgfile, fstype): | |
imgdir = os.path.dirname(imgfile) | |
imgname = os.path.basename(imgfile).split(".")[0] | |
subprocess.run(["sudo", "mount", "-t", fstype, "-o", "loop", os.path.join(imgdir, imgfile), os.path.join(imgdir, "loop")]) | |
with open(os.devnull, "wb") as dnull: | |
subprocess.run(["sudo", "cp", "-r", os.path.join(imgdir, "loop"), os.path.join(imgdir, "output")], stdout=dnull, stderr=subprocess.STDOUT) | |
subprocess.run(["sudo", "mv", os.path.join(imgdir, "output", "loop"), os.path.join(imgdir, "output", imgname)]) | |
subprocess.run(["sudo", "umount", os.path.join(imgdir, "loop")]) | |
def imgextract(indir, excepts=None): | |
images = [x for x in os.listdir(indir) if x.endswith(".raw.img")] | |
if excepts is not None: | |
images = [x for x in images if x not in excepts and ".raw" in x] | |
for img in images: | |
print("EXTRACTING IMAGE: {0}".format(img)) | |
indiv_imgextract(os.path.join(indir, img), "ext4") | |
def csc_zip_extract(indir): | |
zipdir = os.path.join(indir, "output", "cache", "recovery") | |
try: | |
zipf = [x for x in os.listdir(zipdir) if x.endswith(".zip")][0] | |
except IndexError: | |
pass | |
else: | |
print("EXTRACTING: {0}".format(zipf)) | |
with zipfile.ZipFile(os.path.join(zipdir, zipf)) as zipx: | |
try: | |
zipx.extractall(os.path.join(zipdir, os.path.basename(zipf).split(".")[0])) | |
except PermissionError: | |
pass | |
def non_hlos_extract(indir): | |
print("EXTRACTING: NON-HLOS.bin") | |
indiv_imgextract(os.path.join(indir, "NON-HLOS.bin"), "vfat") | |
def tar_param_extract(indir): | |
files = ["param.bin", "up_param.bin"] | |
for filex in files: | |
if os.path.exists(os.path.join(indir, filex)): | |
print("EXTRACTING: {0}".format(filex)) | |
with tarfile.open(os.path.join(indir, filex)) as tarf: | |
tarf.extractall(os.path.join(indir, "output", filex.replace(".bin", ""))) | |
def fota_extract(indir): | |
zipdir = os.path.join(indir, "meta-data") | |
zipf = os.path.join(zipdir, "fota.zip") | |
print("EXTRACTING: fota.zip") | |
with zipfile.ZipFile(zipf) as zipx: | |
zipx.extractall(zipf.replace(".zip", ""), pwd=b"fotatest1234") | |
def apktool(apkdir, basedir, apktoolpath=None, framedir=None, carrier_s8b=False): | |
if apktoolpath is None: | |
apktoolversion = "2.3.4" | |
apktoolpath = os.path.join(os.path.expanduser("~"), "apktool_{0}.jar".format(apktoolversion)) | |
apkname = "{0}.apk".format(apkdir.split(os.sep)[-1]) | |
if carrier_s8b: | |
apkname = apkname.replace(".apk", "", 1) | |
apkdir = os.path.dirname(apkdir).replace(".apk", "", 1) | |
if framedir is None: | |
framedir = os.path.join(basedir, "system", "framework", "samsung-framework-res") | |
framedir2 = os.path.basename(framedir) | |
framedir3 = os.path.join(framedir2, "arm64") | |
with open(os.devnull, "wb") as dnull: | |
subprocess.run(["java", "-jar", apktoolpath, "d", os.path.join(apkdir, apkname), "-s", "-f", "-p", framedir, "-p", framedir2, "-p", framedir3, "-o", os.path.join(apkdir, apkname).replace(".apk", "")], stdout=dnull, stderr=subprocess.STDOUT) | |
#subprocess.run(["java", "-jar", apktoolpath, "d", os.path.join(apkdir, apkname), "-s", "-f", "-p", framedir, "-p", framedir2, "-p", framedir3, "-o", os.path.join(apkdir, apkname).replace(".apk", "")]) | |
def get_yml_info(yamlfile): | |
with open(yamlfile, "r") as afile: | |
skiptag = next(afile) | |
ydata = yaml.load(afile.read()) | |
sdkinfo = ydata["sdkInfo"] | |
if sdkinfo is None: | |
sdkinfo = {"minSdkVersion": "unknown"} | |
elif "minSdkVersion" not in sdkinfo.keys(): | |
sdkinfo = {"minSdkVersion": "unknown"} | |
return sdkinfo, ydata["versionInfo"] | |
def get_xml_info(xmlfile): | |
tree = ElementTree.parse(xmlfile) | |
root = tree.getroot() | |
return root.attrib["package"] | |
def is_odexed(apkdir): | |
status = "deodexed" if "classes.dex" in os.listdir(apkdir) else "odexed" | |
return status | |
def get_apk_filename(apkdir, carrier_s8b=False): | |
if carrier_s8b: | |
apkdir = os.path.dirname(apkdir).replace(".apk", "", 1) | |
sdkinfo, versioninfo = get_yml_info(os.path.join(apkdir, "apktool.yml")) | |
packname = get_xml_info(os.path.join(apkdir, "AndroidManifest.xml")) | |
status = is_odexed(apkdir) | |
filename = "{0}_{1}-{2}_minAPI{3}_{4}.apk".format(packname, versioninfo["versionName"], versioninfo["versionCode"], sdkinfo["minSdkVersion"], status) | |
return filename | |
def indiv_apkextract(basedir, outdir, apkdir, apktoolpath=None, framedir=None, carrier_s8a=False, carrier_s8b=False, carrier_n8a=False, carrier_n8b=False, carrier_s9a=False): | |
apktool(apkdir, basedir, apktoolpath, framedir, carrier_s8b) | |
apkname = apkdir.split(os.sep)[-1] | |
try: | |
fname = get_apk_filename(os.path.join(apkdir, apkname), carrier_s8b) | |
except FileNotFoundError: | |
pass | |
else: | |
newdir = apkdir.replace(basedir, outdir).replace(apkname, "", 1) | |
if carrier_s8a: | |
apptype = newdir.split(os.sep)[-2] | |
carrname = apkdir.split(os.sep)[-4] | |
newdir = os.path.join(outdir, "csc", carrname, apptype) | |
if carrier_s8b: | |
apkname = apkname.replace(".apk", "", 1) | |
apkdir = os.path.dirname(apkdir).replace(".apk", "", 1) | |
if carrier_n8a: | |
carrname = apkdir.split(os.sep)[-3] | |
newdir = os.path.join(outdir, carrname) | |
if carrier_n8b: | |
carrname = apkdir.split(os.sep)[-3] | |
newdir = os.path.join(outdir, "omc", carrname) | |
if carrier_s9a: | |
newdir = outdir | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
shutil.copy(os.path.join(apkdir, "{0}.apk".format(apkname)), os.path.join(newdir, fname)) | |
shutil.rmtree(os.path.join(apkdir, apkname), ignore_errors=True) | |
def filter_apkfolders(apkfolders): | |
excludes = ("mcRegistry",) | |
return [j for j in apkfolders if j not in excludes] | |
def apkextract_base(indir, outdir, tips, apktoolpath=None, framedir=None): | |
for root in tips: | |
olddir = os.path.join(indir, root[0], root[1]) | |
if are_there_apks(olddir): | |
newddir = os.path.join(outdir, root[0], root[1]) | |
rawfolders = filter_apkfolders(os.listdir(olddir)) | |
apkfolders = [os.path.join(olddir, x) for x in rawfolders if os.path.isdir(os.path.join(olddir, x))] | |
for folder in apkfolders: | |
bname = os.path.basename(folder) | |
if os.path.exists(folder) and are_there_apks(folder): | |
print("COPYING APK: {0}.apk".format(os.path.join(root[0], root[1], bname))) | |
indiv_apkextract(indir, outdir, folder, apktoolpath, framedir) | |
else: | |
continue | |
def apkextract(indir, outdir, tips=None, apktoolpath=None, framedir=None): | |
if tips is None: | |
tips = [("system", "app"), ("system", "priv-app"), ("system", "container"), ("userdata", "app"), ("vendor", "app")] | |
apkextract_base(indir, outdir, tips, apktoolpath, framedir) | |
def prep_apks(indir, tips=None): | |
if tips is None: | |
tips = [("system", "app"), ("system", "priv-app"), ("system", "container"), ("userdata", "app"), ("vendor", "app")] | |
for root in tips: | |
if not os.path.exists(os.path.join(indir, "apks", root[0], root[1])): | |
os.makedirs(os.path.join(indir, "apks", root[0], root[1])) | |
def generic_extension_search(indir, ending): | |
for root, dirs, files in os.walk(indir): | |
for file in files: | |
if file.lower().endswith(ending): | |
return True | |
return False | |
def are_there_apks(indir): | |
return generic_extension_search(indir, ".apk") | |
def are_there_lz4s(indir): | |
return generic_extension_search(indir, ".lz4") | |
def carrierapk_note8a(indir, outdir, basedir, apktoolpath=None): | |
if are_there_apks(indir): | |
print("COPYING CARRIER APPS") | |
framedir = os.path.join(basedir, "system", "framework", "samsung-framework-res") | |
goodcarriers = [x for x in os.listdir(indir) if len(os.listdir(os.path.join(indir, x))) > 1] | |
for carrier in goodcarriers: | |
print("COPYING APPS FOR CSC: {0}".format(carrier)) | |
olddir = os.path.join(indir, carrier) | |
newdir = os.path.join(outdir, carrier) | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
typefolders = [os.path.join(olddir, x) for x in os.listdir(olddir) if os.path.isdir(os.path.join(olddir, x))] | |
for app in typefolders: | |
apkfolders = [os.path.join(app, x) for x in os.listdir(app) if os.path.isdir(os.path.join(app, x))] | |
for folder in apkfolders: | |
bname = os.path.basename(folder) | |
findir = os.path.join(newdir, os.path.basename(bname)) | |
print("COPYING APK: {0}.apk".format(bname)) | |
try: | |
indiv_apkextract(indir, outdir, folder, apktoolpath, framedir, carrier_n8a=True) | |
except FileNotFoundError: | |
continue | |
print("") | |
else: | |
pass | |
def carrierapk_s9a(indir, outdir, apktoolpath=None, framedir=None): | |
if are_there_apks(indir): | |
print("COPYING CARRIER APPS") | |
goodcarriers = ["app", "priv-app"] | |
for carrier in goodcarriers: | |
olddir = os.path.join(indir, carrier) | |
newdir = os.path.join(outdir, "odm", carrier) | |
if os.path.exists(olddir): | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
apkfolders = [os.path.join(olddir, x) for x in os.listdir(olddir) if os.path.isdir(os.path.join(olddir, x))] | |
for folder in apkfolders: | |
bname = os.path.basename(folder) | |
if os.path.exists(os.path.join(olddir, bname, "{0}.apk".format(bname))): | |
if os.path.getsize(os.path.join(olddir, bname, "{0}.apk".format(bname))) > 0: | |
print("COPYING APK: {0}.apk".format(bname)) | |
try: | |
indiv_apkextract(olddir, newdir, folder, apktoolpath=apktoolpath, framedir=framedir, carrier_s9a=True) | |
except FileNotFoundError: | |
pass | |
else: | |
pass | |
def carrierapk_s8a(indir, outdir, apktoolpath=None, framedir=None): | |
if are_there_apks(indir): | |
print("COPYING CARRIER APPS") | |
carrs = [x for x in os.listdir(indir) if os.path.isdir(os.path.join(indir, x))] | |
tips = [("system", "app"), ("system", "priv-app")] | |
carriers = {carr: [os.path.join(tip[0], tip[1]) for tip in tips] for carr in carrs} | |
maybecarriers = [] | |
for carr in carriers.keys(): | |
maybecarriers.append(os.path.join(carr, carriers[carr][0])) | |
maybecarriers.append(os.path.join(carr, carriers[carr][1])) | |
goodcarriers = [x for x in maybecarriers if os.path.exists(os.path.join(indir, x)) and len(os.listdir(os.path.join(indir, x))) > 1] | |
for carrier in goodcarriers: | |
olddir = os.path.join(indir, carrier) | |
newtag = os.sep.join(carrier.split(os.sep)[::2]) | |
newdir = os.path.join(outdir, "csc", newtag) | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
apkfolders = [os.path.join(olddir, x) for x in os.listdir(olddir) if os.path.isdir(os.path.join(olddir, x))] | |
for folder in apkfolders: | |
bname = os.path.basename(folder) | |
findir = os.path.join(newdir, os.path.basename(bname)) | |
if os.path.exists(os.path.join(olddir, bname, "{0}.apk".format(bname))): | |
if os.path.getsize(os.path.join(olddir, bname, "{0}.apk".format(bname))) > 0: | |
print("COPYING APK: {0}.apk".format(bname)) | |
try: | |
indiv_apkextract(indir, outdir, folder, apktoolpath=apktoolpath, framedir=framedir, carrier_s8a=True) | |
except FileNotFoundError: | |
pass | |
else: | |
pass | |
def carrierapk_s8b(indir, outdir, apktoolpath=None, framedir=None): | |
if are_there_apks(indir): | |
print("COPYING CARRIER APPS") | |
carrs = [x for x in os.listdir(indir) if os.path.isdir(os.path.join(indir, x)) and are_there_apks(os.path.join(indir, x))] | |
goodcarrs = [x.replace("Common_app", "common_app") for x in carrs] | |
for incarr, outcarr in zip(carrs, goodcarrs): | |
olddir = os.path.join(indir, incarr) | |
if "hidden_app" in os.listdir(olddir): | |
olddir = os.path.join(indir, incarr, "hidden_app") | |
newdir = os.path.join(outdir, "csc") | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
oldapps = [os.path.join(olddir, x) for x in os.listdir(olddir) if x.endswith(".apk")] | |
for app in oldapps: | |
bname = os.path.basename(app) | |
print("COPYING APK: {0}".format(bname)) | |
try: | |
indiv_apkextract(olddir, newdir, app, apktoolpath=apktoolpath, framedir=framedir, carrier_s8b=True) | |
except FileNotFoundError: | |
pass | |
else: | |
pass | |
def carrierapk_note8b(indir, outdir, apktoolpath=None, framedir=None): | |
if are_there_apks(indir): | |
print("COPYING CARRIER APPS") | |
goodcarriers = [os.path.join("common_app", "app"), os.path.join("common_app", "priv-app")] | |
for carrier in goodcarriers: | |
olddir = os.path.join(indir, carrier) | |
newtag = os.sep.join(carrier.split(os.sep)[::2]) | |
newdir = os.path.join(outdir, "omc", newtag) | |
if os.path.exists(olddir): | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
apkfolders = [os.path.join(olddir, x) for x in os.listdir(olddir) if os.path.isdir(os.path.join(olddir, x))] | |
for folder in apkfolders: | |
bname = os.path.basename(folder) | |
findir = os.path.join(newdir, os.path.basename(bname)) | |
if os.path.exists(os.path.join(olddir, bname, "{0}.apk".format(bname))): | |
if os.path.getsize(os.path.join(olddir, bname, "{0}.apk".format(bname))) > 0: | |
print("COPYING APK: {0}.apk".format(bname)) | |
try: | |
indiv_apkextract(indir, outdir, folder, apktoolpath=apktoolpath, framedir=framedir, carrier_n8b=True) | |
except FileNotFoundError: | |
pass | |
else: | |
pass | |
def preloadapk(indir, basedir): | |
print("COPYING PRELOAD APKS") | |
tips = [("system", "preload")] | |
if os.path.exists(os.path.join(basedir, "system", "preloadFactoryResetOnly")): | |
tips.append(("system", "preloadFactoryResetOnly")) | |
prep_apks(indir, tips) | |
apkextract(basedir, os.path.join(indir, "apks"), tips) | |
def trim_path_carrier(indir, outdir): | |
if os.path.exists(outdir): | |
shutil.rmtree(outdir, ignore_errors=True) | |
shutil.copytree(indir, outdir) | |
def main_zip_extract(indir): | |
zipf = [x for x in os.listdir(indir) if x.endswith(".zip")][0] | |
with zipfile.ZipFile(os.path.join(indir, zipf), allowZip64=True) as zipx: | |
zipx.extractall(indir) | |
def main0(indir): | |
fzip = [x for x in os.listdir(indir) if x.endswith(".zip")][0] | |
print("EXTRACTING: {0}".format(fzip)) | |
main_zip_extract(indir) | |
print("FULL ZIP EXTRACTION COMPLETE!\n") | |
def main1(indir): | |
md5out(indir) | |
print("MD5 EXTRACTION COMPLETE!\n") | |
if are_there_lz4s(indir): | |
lz4out(indir) | |
print("LZ4 EXTRACTION COMPLETE!\n") | |
def main2(indir): | |
cscout = ["CSC"] | |
if any("HOME_CSC" in x for x in os.listdir(indir)): | |
cscout.append("HOME_CSC") | |
for outdir in (cscout): | |
main2_csc(indir, outdir) | |
for outdir in ("BL",): | |
main2_bl(indir, outdir) | |
for outdir in ("AP",): | |
main2_ap(indir, outdir) | |
if "USERDATA" in os.listdir(indir): | |
for outdir in ("USERDATA",): | |
main2_userdata(indir, outdir) | |
def main2_csc(indir, outdir): | |
print("EXTRACTING: {0}".format(outdir)) | |
simg2img(os.path.join(indir, outdir)) | |
prep_dirs(os.path.join(indir, outdir)) | |
imgextract(os.path.join(indir, outdir)) | |
csc_zip_extract(os.path.join(indir, outdir)) | |
remove_loop(os.path.join(indir, outdir)) | |
print("{0} EXTRACTION COMPLETE!\n".format(outdir)) | |
def main2_bl(indir, outdir): | |
print("EXTRACTING: {0}".format(outdir)) | |
prep_dirs(os.path.join(indir, outdir)) | |
if "NON-HLOS.bin" in os.listdir(os.path.join(indir, outdir)): | |
non_hlos_extract(os.path.join(indir, outdir)) | |
if "param.bin" in os.listdir(os.path.join(indir, outdir)): | |
tar_param_extract(os.path.join(indir, outdir)) | |
remove_loop(os.path.join(indir, outdir)) | |
print("{0} EXTRACTION COMPLETE!\n".format(outdir)) | |
def main2_ap(indir, outdir): | |
print("EXTRACTING: {0}".format(outdir)) | |
simg2img(os.path.join(indir, outdir), ("boot.img", "recovery.img")) | |
prep_dirs(os.path.join(indir, outdir)) | |
imgextract(os.path.join(indir, outdir), ("boot.img", "recovery.img")) | |
fota_extract(os.path.join(indir, outdir)) | |
remove_loop(os.path.join(indir, outdir)) | |
boot_recovery_extract(os.path.join(indir, outdir)) | |
print("{0} EXTRACTION COMPLETE!\n".format(outdir)) | |
def main2_userdata(indir, outdir): | |
for outdir in ("USERDATA",): | |
print("EXTRACTING: {0}".format(outdir)) | |
simg2img(os.path.join(indir, outdir)) | |
prep_dirs(os.path.join(indir, outdir)) | |
imgextract(os.path.join(indir, outdir)) | |
remove_loop(os.path.join(indir, outdir)) | |
print("{0} EXTRACTION COMPLETE!\n".format(outdir)) | |
def main3(indir): | |
prep_apks(indir) | |
basedir = os.path.join(indir, "AP", "output") | |
preloaddir = os.path.join(basedir, "system", "preload") | |
if os.path.exists(preloaddir) and are_there_apks(preloaddir): | |
preloadapk(indir, basedir) | |
if any(odm in os.listdir(os.path.join(indir, "CSC")) for odm in ["odm.img", "odm.img.ext4"]) and are_there_apks(os.path.join(indir, "CSC")): | |
main3_s9a(indir, basedir) | |
#print("S9A") | |
elif "USERDATA" in os.listdir(indir) and are_there_apks(os.path.join(indir, "USERDATA")): | |
main3_note8a(indir, basedir) | |
#print("N8A") | |
elif "omr.img" in os.listdir(os.path.join(indir, "CSC")) and are_there_apks(os.path.join(indir, "CSC")): | |
main3_note8b(indir, basedir) | |
#print("N8B") | |
elif "hidden" in os.listdir(os.path.join(indir, "CSC", "output")) and are_there_apks(os.path.join(indir, "CSC", "output", "hidden")): | |
main3_s8b(indir, basedir) | |
#print("S8B") | |
elif not are_there_apks(os.path.join(indir, "CSC")): | |
main3_nocarrier(indir, basedir) | |
#print("NOAPKS") | |
else: | |
main3_s8a(indir, basedir) | |
#print("S8A") | |
remove_empty_dirs(os.path.join(indir, "apks")) | |
print("APP EXTRACTION COMPLETE!\n") | |
def main3_s9a(indir, basedir): | |
basedir2 = basedir.replace(os.path.join("AP", "output"), os.path.join("CSC", "output")) | |
if are_there_apks(os.path.join(basedir2, "odm")): | |
if not os.path.exists(os.path.join(indir, "apks", "odm")): | |
os.makedirs(os.path.join(indir, "apks", "odm")) | |
framedir = os.path.join(basedir, "system", "framework", "samsung-framework-res") | |
carrierapk_s9a(os.path.join(basedir2, "odm"), os.path.join(indir, "apks"), framedir=framedir) | |
print("COPYING SYSTEM APPS") | |
apkextract(basedir, os.path.join(indir, "apks")) | |
def main3_s8a(indir, basedir): | |
basedir2 = basedir.replace(os.path.join("AP", "output"), os.path.join("CSC", "output")) | |
tryomc = os.path.join(basedir2, "cache", "recovery", "sec_omc", "system", "omc") | |
if os.path.exists(tryomc) and are_there_apks(tryomc): | |
secondpath = tryomc | |
else: | |
secondpath = tryomc.replace("omc", "csc") | |
trim_path_carrier(secondpath, os.path.join(basedir2, "csc")) | |
if are_there_apks(os.path.join(basedir2, "csc")): | |
if not os.path.exists(os.path.join(indir, "apks", "csc")): | |
os.makedirs(os.path.join(indir, "apks", "csc")) | |
framedir = os.path.join(basedir, "system", "framework", "samsung-framework-res") | |
carrierapk_s8a(os.path.join(basedir2, "csc"), os.path.join(indir, "apks"), framedir=framedir) | |
shutil.rmtree(os.path.join(basedir2, "csc"), ignore_errors=True) | |
print("COPYING SYSTEM APPS") | |
apkextract(basedir, os.path.join(indir, "apks")) | |
def main3_s8b(indir, basedir): | |
basedir2 = basedir.replace(os.path.join("AP", "output"), os.path.join("CSC", "output")) | |
if are_there_apks(os.path.join(basedir2, "hidden")): | |
for potdir in os.listdir(os.path.join(basedir2, "hidden")): | |
if are_there_apks(os.path.join(basedir2, "hidden", potdir)): | |
if not os.path.exists(os.path.join(indir, "apks", potdir)): | |
os.makedirs(os.path.join(indir, "apks", potdir)) | |
framedir = os.path.join(basedir, "system", "framework", "samsung-framework-res") | |
carrierapk_s8b(os.path.join(basedir2, "hidden"), os.path.join(indir, "apks"), framedir=framedir) | |
print("COPYING SYSTEM APPS") | |
apkextract(basedir, os.path.join(indir, "apks")) | |
def main3_note8a(indir, basedir): | |
basedir2 = basedir.replace(os.path.join("AP", "output"), os.path.join("USERDATA", "output")) | |
tips = [("system", "app"), ("system", "priv-app"), ("system", "container")] | |
tips2 = [("userdata", "app")] | |
if are_there_apks(os.path.join(basedir, "system", "carrier")): | |
prep_apks(indir, [("system", "carrier")]) | |
carrierapk_note8a(os.path.join(basedir, "system", "carrier"), os.path.join(indir, "apks", "system", "carrier"), basedir) | |
print("COPYING SYSTEM APPS") | |
apkextract(basedir, os.path.join(indir, "apks"), tips) | |
apkextract(basedir2, os.path.join(indir, "apks"), tips2) | |
def main3_note8b(indir, basedir): | |
basedir2 = basedir.replace(os.path.join("AP", "output"), os.path.join("CSC", "output")) | |
trim_path_carrier(os.path.join(basedir2, "cache", "recovery", "sec_omc", "system", "omc"), os.path.join(basedir2, "omc")) | |
if are_there_apks(os.path.join(basedir2, "omc")): | |
if not os.path.exists(os.path.join(indir, "apks", "omc")): | |
os.makedirs(os.path.join(indir, "apks", "omc")) | |
framedir = os.path.join(basedir, "system", "framework", "samsung-framework-res") | |
carrierapk_note8b(os.path.join(basedir2, "omc"), os.path.join(indir, "apks"), framedir=framedir) | |
shutil.rmtree(os.path.join(basedir2, "omc"), ignore_errors=True) | |
print("COPYING SYSTEM APPS") | |
apkextract(basedir, os.path.join(indir, "apks")) | |
def main3_nocarrier(indir, basedir): | |
print("COPYING SYSTEM APPS") | |
apkextract(basedir, os.path.join(indir, "apks")) | |
if __name__ == "__main__": | |
indir = os.path.abspath(os.getcwd()) | |
main0(indir) | |
main1(indir) | |
main2(indir) | |
main3(indir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got a couple error while decrypting.
Here is the full out put.
(base) root@GooF-PC:/mnt/e/0# phython3 samsung_extract.py
Command 'phython3' not found, did you mean:
command 'python3' from deb python3 (3.8.2-0ubuntu2)
Try: apt install
(base) root@GooF-PC:/mnt/e/0# phython samsung_extract.py
phython: command not found
(base) root@GooF-PC:/mnt/e/0# python3 samsung_extract.py
EXTRACTING: SM-G998U_1_20211005165607_zt4kacmk28_fac.zip
FULL ZIP EXTRACTION COMPLETE!
DECOMPRESSING: AP_G998USQS4AUIR_CL22275169_QB44171590_REV00_user_low_ship_MULTI_CERT_meta_OS11.tar.md5
DECOMPRESSING: BL_G998USQS4AUIR_CL22275169_QB44171590_REV00_user_low_ship_MULTI_CERT.tar.md5
DECOMPRESSING: CP_G998USQS4AUIR_CP20504345_CL22275169_QB44171590_REV00_user_low_ship_MULTI_CERT.tar.md5
DECOMPRESSING: CSC_OMC_OYN_G998UOYN4AUIR_CL22275169_QB44171590_REV00_user_low_ship_MULTI_CERT.tar.md5
DECOMPRESSING: HOME_CSC_OMC_OYN_G998UOYN4AUIR_CL22275169_QB44171590_REV00_user_low_ship_MULTI_CERT.tar.md5
DECOMPRESSING: USERDATA_TMB_G998USQS4AUIR_CL22275169_QB44171590_REV00_user_low_ship_MULTI_CERT.tar.md5
MD5 EXTRACTION COMPLETE!
DECOMPRESSING: /AP/boot.img.lz4
/mnt/e/0/AP/boot.img : decoded 100663296 bytes
DECOMPRESSING: /AP/carrier.img.lz4
/mnt/e/0/AP/carrier. : decoded 53360 bytes
DECOMPRESSING: /AP/dtbo.img.lz4
/mnt/e/0/AP/dtbo.img : decoded 25165824 bytes
DECOMPRESSING: /AP/misc.bin.lz4
/mnt/e/0/AP/misc.bin : decoded 520704 bytes
DECOMPRESSING: /AP/persist.img.lz4
/mnt/e/0/AP/persist. : decoded 704648 bytes
DECOMPRESSING: /AP/recovery.img.lz4
/mnt/e/0/AP/recovery : decoded 81788928 bytes
DECOMPRESSING: /AP/super.img.lz4
/mnt/e/0/AP/super.im : decoded 10276309084 bytes
DECOMPRESSING: /AP/vbmeta.img.lz4
/mnt/e/0/AP/vbmeta.i : decoded 9664 bytes
DECOMPRESSING: /AP/vbmeta_system.img.lz4
/mnt/e/0/AP/vbmeta_s : decoded 3392 bytes
DECOMPRESSING: /AP/vendor_boot.img.lz4
/mnt/e/0/AP/vendor_b : decoded 100663296 bytes
DECOMPRESSING: /BL/abl.elf.lz4
/mnt/e/0/BL/abl.elf. : decoded 4194304 bytes
DECOMPRESSING: /BL/aop.mbn.lz4
/mnt/e/0/BL/aop.mbn. : decoded 244348 bytes
DECOMPRESSING: /BL/apdp.mbn.lz4
/mnt/e/0/BL/apdp.mbn : decoded 14020 bytes
DECOMPRESSING: /BL/bksecapp.mbn.lz4
/mnt/e/0/BL/bksecapp : decoded 40196 bytes
DECOMPRESSING: /BL/cpucp.elf.lz4
/mnt/e/0/BL/cpucp.el : decoded 105220 bytes
DECOMPRESSING: /BL/devcfg.mbn.lz4
/mnt/e/0/BL/devcfg.m : decoded 120276 bytes
DECOMPRESSING: /BL/dspso.bin.lz4
/mnt/e/0/BL/dspso.bi : decoded 67108864 bytes
DECOMPRESSING: /BL/engmode.mbn.lz4
/mnt/e/0/BL/engmode. : decoded 1161281 bytes
DECOMPRESSING: /BL/hypvm.mbn.lz4
/mnt/e/0/BL/hypvm.mb : decoded 8388608 bytes
DECOMPRESSING: /BL/km41.mbn.lz4
/mnt/e/0/BL/km41.mbn : decoded 264581 bytes
DECOMPRESSING: /BL/NON-HLOS.bin.lz4
/mnt/e/0/BL/NON-HLOS : decoded 111956480 bytes
DECOMPRESSING: /BL/quest.fv.lz4
/mnt/e/0/BL/quest.fv : decoded 590336 bytes
DECOMPRESSING: /BL/qupv3fw.elf.lz4
/mnt/e/0/BL/qupv3fw. : decoded 57761 bytes
DECOMPRESSING: /BL/sec.elf.lz4
/mnt/e/0/BL/sec.elf. : decoded 13276 bytes
DECOMPRESSING: /BL/shrm.elf.lz4
/mnt/e/0/BL/shrm.elf : decoded 46168 bytes
DECOMPRESSING: /BL/spunvm.bin.lz4
/mnt/e/0/BL/spunvm.b : decoded 356352 bytes
DECOMPRESSING: /BL/storsec.mbn.lz4
/mnt/e/0/BL/storsec. : decoded 21233 bytes
DECOMPRESSING: /BL/testvector.fv.lz4
/mnt/e/0/BL/testvect : decoded 8389120 bytes
DECOMPRESSING: /BL/tz.mbn.lz4
/mnt/e/0/BL/tz.mbn.l : decoded 4194304 bytes
DECOMPRESSING: /BL/tz_hdm.mbn.lz4
/mnt/e/0/BL/tz_hdm.m : decoded 1195187 bytes
DECOMPRESSING: /BL/tz_iccc.mbn.lz4
/mnt/e/0/BL/tz_iccc. : decoded 148029 bytes
DECOMPRESSING: /BL/tz_kg.mbn.lz4
/mnt/e/0/BL/tz_kg.mb : decoded 1336786 bytes
DECOMPRESSING: /BL/uefi_sec.mbn.lz4
/mnt/e/0/BL/uefi_sec : decoded 125337 bytes
DECOMPRESSING: /BL/vaultkeeper.mbn.lz4
/mnt/e/0/BL/vaultkee : decoded 1293485 bytes
DECOMPRESSING: /BL/vbmeta.img.lz4
/mnt/e/0/BL/vbmeta.i : decoded 9664 bytes
DECOMPRESSING: /BL/xbl.elf.lz4
/mnt/e/0/BL/xbl.elf. : decoded 4718592 bytes
DECOMPRESSING: /BL/xbl_config.elf.lz4
/mnt/e/0/BL/xbl_conf : decoded 219264 bytes
DECOMPRESSING: /CP/modem.bin.lz4
/mnt/e/0/CP/modem.bi : decoded 106574336 bytes
DECOMPRESSING: /CSC/cache.img.lz4
/mnt/e/0/CSC/cache.i : decoded 78044 bytes
DECOMPRESSING: /CSC/omr.img.lz4
/mnt/e/0/CSC/omr.img : decoded 53360 bytes
DECOMPRESSING: /CSC/optics.img.lz4
/mnt/e/0/CSC/optics. : decoded 1245320 bytes
DECOMPRESSING: /CSC/prism.img.lz4
/mnt/e/0/CSC/prism.i : decoded 186142952 bytes
DECOMPRESSING: /HOME_CSC/cache.img.lz4
/mnt/e/0/HOME_CSC/ca : decoded 78044 bytes
DECOMPRESSING: /HOME_CSC/optics.img.lz4
/mnt/e/0/HOME_CSC/op : decoded 1245320 bytes
DECOMPRESSING: /HOME_CSC/prism.img.lz4
/mnt/e/0/HOME_CSC/pr : decoded 186142952 bytes
DECOMPRESSING: /USERDATA/cache.img.lz4
/mnt/e/0/USERDATA/ca : decoded 78044 bytes
DECOMPRESSING: /USERDATA/metadata.img.lz4
/mnt/e/0/USERDATA/me : decoded 53360 bytes
DECOMPRESSING: /USERDATA/misc.bin.lz4
/mnt/e/0/USERDATA/mi : decoded 520704 bytes
DECOMPRESSING: /USERDATA/userdata.img.lz4
/mnt/e/0/USERDATA/us : decoded 975893024 bytes
LZ4 EXTRACTION COMPLETE!
EXTRACTING: CSC
DECOMPRESSING: cache.img
DECOMPRESSING: omr.img
DECOMPRESSING: optics.img
DECOMPRESSING: prism.img
EXTRACTING IMAGE: cache.raw.img
EXTRACTING IMAGE: omr.raw.img
EXTRACTING IMAGE: optics.raw.img
EXTRACTING IMAGE: prism.raw.img
CSC EXTRACTION COMPLETE!
EXTRACTING: HOME_CSC
DECOMPRESSING: cache.img
DECOMPRESSING: optics.img
DECOMPRESSING: prism.img
EXTRACTING IMAGE: cache.raw.img
EXTRACTING IMAGE: optics.raw.img
EXTRACTING IMAGE: prism.raw.img
HOME_CSC EXTRACTION COMPLETE!
EXTRACTING: BL
EXTRACTING: NON-HLOS.bin
BL EXTRACTION COMPLETE!
EXTRACTING: AP
DECOMPRESSING: carrier.img
DECOMPRESSING: dtbo.img
Invalid sparse file format at header magic
Failed to read sparse file
DECOMPRESSING: persist.img
DECOMPRESSING: super.img
DECOMPRESSING: vbmeta.img
Invalid sparse file format at header magic
Failed to read sparse file
DECOMPRESSING: vbmeta_system.img
Invalid sparse file format at header magic
Failed to read sparse file
DECOMPRESSING: vendor_boot.img
Invalid sparse file format at header magic
Failed to read sparse file
EXTRACTING IMAGE: carrier.raw.img
EXTRACTING IMAGE: dtbo.raw.img
mount: /mnt/e/0/AP/loop: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
umount: /mnt/e/0/AP/loop: not mounted.
EXTRACTING IMAGE: persist.raw.img
EXTRACTING IMAGE: super.raw.img
mount: /mnt/e/0/AP/loop: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
umount: /mnt/e/0/AP/loop: not mounted.
EXTRACTING IMAGE: vbmeta.raw.img
mount: /mnt/e/0/AP/loop: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
umount: /mnt/e/0/AP/loop: not mounted.
EXTRACTING IMAGE: vbmeta_system.raw.img
mount: /mnt/e/0/AP/loop: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
umount: /mnt/e/0/AP/loop: not mounted.
EXTRACTING IMAGE: vendor_boot.raw.img
mount: /mnt/e/0/AP/loop: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
umount: /mnt/e/0/AP/loop: not mounted.
EXTRACTING: fota.zip
^ATraceback (most recent call last):
File "samsung_extract.py", line 654, in
main2(indir)
File "samsung_extract.py", line 502, in main2
main2_ap(indir, outdir)
File "samsung_extract.py", line 536, in main2_ap
boot_recovery_extract(os.path.join(indir, outdir))
File "samsung_extract.py", line 110, in boot_recovery_extract
indiv_abootimg(os.path.join(indir, img))
File "samsung_extract.py", line 81, in indiv_abootimg
subprocess.run(["abootimg", "-x", imgfile], stdout=dnull, stderr=subprocess.STDOUT)
File "/root/anaconda3/lib/python3.8/subprocess.py", line 493, in run
with Popen(*popenargs, **kwargs) as process:
File "/root/anaconda3/lib/python3.8/subprocess.py", line 858, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/root/anaconda3/lib/python3.8/subprocess.py", line 1706, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'abootimg'
(base) root@GooF-PC:/mnt/e/0#
(base) root@GooF-PC:/mnt/e/0#
(base) root@GooF-PC:/mnt/e/0#