Last active
November 27, 2021 17:30
-
-
Save topin89/b109342b135649bf8c2e405a6ae79a39 to your computer and use it in GitHub Desktop.
Extract files from LG Backup .lbf file
This file contains 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
# For modern LG backup files use a script from here: https://github.com/Mysak0CZ/LBFtool | |
# with details from there https://forum.xda-developers.com/android/general/tool-lg-restore-com-lge-bnr-lbf-file-t4053579 | |
# Fair warning, this script was designed for really old version of LGBackup and won't work on with new devices | |
# So, if you don't get what you wanted, try to use every data carving tools you can get | |
# | |
# Also, good person with nickname SEVENTY ONE recommends ExtractJPEG( https://www.gunamoi.com.au/soft/extractjpeg/download.html ) | |
# To, well, extract JPG Images from a backup | |
# 0. You will need 7-zip context menu "Extract here". | |
# 1. Edit filename to your backup file | |
# 2. Run this script from same folder | |
# 3. Select all *.brokenscript and choose 7-zip > Extract here | |
# 4. On overwrite request, choose either "Yes to all" or "No to all", id doesn't matter | |
# 5. Ta-da! You just got your files. | |
# 6. Most .db files are in fact SQLite DBs, you can open 'em with SQLiteStudio | |
# 7. Sms/sms.vmsg you can read here: http://sms-vmsg.org/sms-reader-app/free-app/ | |
# 8. Guess you can import SMS and MMS to your phone with this app (I don't know, It was friend's backup) https://play.google.com/store/apps/details?id=com.aoe.vmgconverter&hl=ru | |
# 9. All else, I don't know | |
# 10. May google be with you | |
import mmap | |
index=0 | |
filename=f"LGBackup_xxxxxx.lbf" | |
def read_in_chunks(file_object, chunk_size=1024): | |
"""Lazy function (generator) to read a file piece by piece. | |
Default chunk size: 1k.""" | |
while True: | |
data = file_object.read(chunk_size) | |
if not data: | |
break | |
yield data | |
def find_in_file(f,signature, startpos): | |
prev=b'' | |
chunk_size=2**20 | |
for i,cur in enumerate(read_in_chunks(f,chunk_size)): | |
searchee=prev+cur | |
pos=searchee.find(signature) | |
if pos>=0: | |
return i*chunk_size+pos-len(prev)+startpos | |
prev=cur | |
else: | |
return -1 | |
with open(filename,"rb") as backup: | |
starpos=0 | |
while True: | |
pos=find_in_file(backup, b'PK\x03\x04',starpos) | |
if pos<0: | |
break | |
print(backup.tell()) | |
backup.seek(pos) | |
print(backup.tell()) | |
index+=1 | |
filename=f"{index}.brokenzip" | |
with open(filename,"wb") as nextfile: | |
for chunk in read_in_chunks(backup,2**20): | |
nextfile.write(chunk) | |
starpos=pos+1 | |
backup.seek(starpos) | |
print(backup.tell()) | |
print() |
This file contains 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
# For modern LG backup files use a script from here: https://github.com/Mysak0CZ/LBFtool | |
# with details from there https://forum.xda-developers.com/android/general/tool-lg-restore-com-lge-bnr-lbf-file-t4053579 | |
# Fair warning, this script was designed for really old version of LGBackup and won't work on with new devices | |
# So, if you don't get what you wanted, try to use every data carving tools you can get | |
# | |
# Also, good person with nickname SEVENTY ONE recommends ExtractJPEG( https://www.gunamoi.com.au/soft/extractjpeg/download.html ) | |
# To, well, extract JPG Images from a backup | |
# 0. You will need 7-zip. | |
# 1. Find 7z.exe in a 7-zip folder in Program Files (or whenever you install it) and copy it to a folder with the script | |
# 2. Edit filename to your backup file | |
# 3. Run this script from same folder | |
# 4. Wait a bit (maybe a lot). New subfolder "restored" should appear. | |
# 5. Ta-da! You just got your files. | |
# 6. Most .db files are in fact SQLite DBs, you can open 'em with SQLiteStudio | |
# 7. Sms/sms.vmsg you can read here: http://sms-vmsg.org/sms-reader-app/free-app/ | |
# 8. Guess you can import SMS and MMS to your phone with this app (I don't know, It was friend's backup) https://play.google.com/store/apps/details?id=com.aoe.vmgconverter&hl=ru | |
# 9. All else, I don't know | |
# 10. May google be with you | |
import mmap | |
from os import system, remove | |
filename=f"LGBackup_xxxxxx.lbf" | |
filename_output=f"one_and_only.brokenzip" | |
def read_in_chunks(file_object, chunk_size=1024): | |
"""Lazy function (generator) to read a file piece by piece. | |
Default chunk size: 1k.""" | |
while True: | |
data = file_object.read(chunk_size) | |
if not data: | |
break | |
yield data | |
def find_in_file(f,signature, startpos): | |
prev=b'' | |
chunk_size=2**20 | |
for i,cur in enumerate(read_in_chunks(f,chunk_size)): | |
searchee=prev+cur | |
pos=searchee.find(signature) | |
if pos>=0: | |
return i*chunk_size+pos-len(prev)+startpos | |
prev=cur | |
else: | |
return -1 | |
def unpack_brokenzip(filename_output): | |
system(f"7z x -aou -orestored {filename_output}") | |
with open(filename,"rb") as backup: | |
starpos=0 | |
while True: | |
pos=find_in_file(backup, b'PK\x03\x04',starpos) | |
if pos<0: | |
break | |
backup.seek(pos) | |
print(backup.tell()) | |
with open(filename_output,"wb") as nextfile: | |
for chunk in read_in_chunks(backup,2**20): | |
nextfile.write(chunk) | |
unpack_brokenzip(filename_output) | |
starpos=pos+1 | |
backup.seek(starpos) | |
remove(filename_output) |
This file contains 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
# For modern LG backup files use a script from here: https://github.com/Mysak0CZ/LBFtool | |
# with details from there https://forum.xda-developers.com/android/general/tool-lg-restore-com-lge-bnr-lbf-file-t4053579 | |
filename="LGBackup_xxxxxx.lbf" | |
filename_out="LGBackup_xxxxxx_headers_only.lbf" | |
CHUNK_LENGTH=4096 | |
HEADER=b'PK\x03\x04' | |
with open(filename,"rb") as backup, open(filename_out,"wb") as newfile: | |
window=bytearray(backup.read(CHUNK_LENGTH*2)) | |
while window: | |
header_pos=window.find(HEADER) | |
if header_pos > -1: | |
newfile.write(b'0'*header_pos+HEADER) | |
del window[:header_pos+4] | |
elif len(window)>CHUNK_LENGTH: | |
newfile.write(b'0'*CHUNK_LENGTH) | |
del window[:CHUNK_LENGTH] | |
else: | |
newfile.write(b'0'*len(window)) | |
del window[:] | |
window+=bytearray(backup.read(CHUNK_LENGTH)) |
Try python3 lbf_extractor.py
. Default python is still python2 on most Linux distros.
Also, unless your phone is really old, I suggest https://github.com/Mysak0CZ/LBFtool
The author actually used debugger to get lbf structure and it should extract all files, not just zip archives.
Hi,
I have a backup file of my phone in LBF format. Could someone help me write my photos?
I can pay.
I do not speak English. I use a translator.
Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I download zip file and extract theme. After extracting i copied my backup into same folder :
I changed filename=f"LGBackup_201102.lbf" in lbf_extractor.py and run it but i got
How can i run ?