[Miscellaneous Android Development] thecubed:
Hello everybody!

This will be my first XDA-wide release of my new utility for all LG phones.

What is this?

This is a utility to extract the new format KDZ files that LG distributes, specifically the 'compressed' ones.

LG frequently distributes firmware for phones as KDZ files, which are essentially a firmware image of the eMMC and a DLL file that is used by the downloader utility to communicate with the phone.

In the past, there were utilities to extract KDZ files to a DLL file and a DZ file, but no further (at least to my knowledge).

This utility lets you break the KDZ file into it's respective partitions (aboot, rpm, tz, and so on)
​

What good does this do me?

If you're an phone modder, haxxor, or just an enthusiast that has access to their phone's KDZ file and would like to have a copy of the actual partitions stored within, this will let you.

As an example, firmware for the new LG G2 on many device models is distributed as a KDZ file only.

Other phones use a TOT file, which is essentially a disk image of the eMMC with no compression.

If someone with a KDZ firmware-only phone wiped a partition (for example, modem) and wanted to get it back without flashing the whole phone all over again, they would be stuck.

TOT files are easily extractable, as there is software available currently for that but until today there was none (to my knowledge) for these new KDZ files.
​

How do I use this?

Glad you asked.

Inside the ZIP file you'll see two Python scripts, KDZFileTools.py and DZFileTools.py.

There's also a README.txt file for more in-depth information if you're curious.

Both scripts respond to --help or -h, so if you're even more curious, try that too!

KDZ files contain DZ files and DLL files, so the first step will be to split those into their respective parts:

LAS_V08d_pre3_00.kdz is the name of the KDZ file that I've copied to the working directory for this example.

# python KDZFileTools.py -l -f LAS_V08d_pre3_00.kdz
[+] KDZ Partition List
=========================================
0 : LAS_V08d_pre3_00.dz (1428092632 bytes)
1 : LGUP_8974.dll (1477632 bytes)

This shows me that there are two files inside the KDZ file: LAS_V08d_pre3_00.dz and LGUP_8974.dll

You can now extract them by ID by using the -s option, or by using -x to extract all of the files.

# python KDZFileTools.py -f LAS_V08d_pre3_00.kdz -x
[+] Extracting all partitions!

[+] Extracting LAS_V08d_pre3_00.dz to kdzextracted\LAS_V08d_pre3_00.dz
[+] Extracting LGUP_8974.dll to kdzextracted\LGUP_8974.dll

Now you'll see a folder called "kdzextracted" in your current working directory, which will contain the extracted files.

The next step would be to extract the DZ file to get the partitions it contains:

# python DZFileTools.py -f kdzextracted/LAS_V08d_pre3_00.dz -l
[+] DZ Partition List
=========================================
0 : PrimaryGPT_0.bin (4299 bytes)
1 : modem_32768.bin (25719664 bytes)
2 : sbl1_163840.bin (179443 bytes)
3 : dbi_165888.bin (10505 bytes)
4 : aboot_229376.bin (288082 bytes)
5 : rpm_231424.bin (93084 bytes)
6 : boot_262144.bin (8959565 bytes)
7 : tz_294912.bin (149388 bytes)
8 : persist_393216.bin (23621 bytes)
9 : recovery_458752.bin (10454494 bytes)
10 : laf_622592.bin (14244284 bytes)
11 : system_7176192.bin (66791740 bytes)
12 : system_7438336.bin (2651 bytes)
13 : system_7440008.bin (2313 bytes)
14 : system_7444120.bin (103727934 bytes)
15 : system_7704592.bin (114239263 bytes)
16 : system_7964296.bin (2313 bytes)
17 : system_7968408.bin (103349001 bytes)
18 : system_8228880.bin (121921125 bytes)
19 : system_8488584.bin (2313 bytes)
20 : system_8492696.bin (101078725 bytes)
21 : system_8753168.bin (125454806 bytes)
22 : system_9012872.bin (2313 bytes)
23 : system_9016984.bin (105806605 bytes)
24 : system_9277456.bin (115830981 bytes)
25 : system_9537160.bin (2313 bytes)
26 : system_9541272.bin (108458465 bytes)
27 : system_9801744.bin (83280847 bytes)
28 : system_10063888.bin (67940827 bytes)
29 : system_10326032.bin (91997923 bytes)
30 : system_10588176.bin (58015487 bytes)
31 : system_10846208.bin (2314 bytes)
32 : system_11108352.bin (2314 bytes)
33 : system_11370496.bin (2314 bytes)
34 : system_11632640.bin (2314 bytes)
35 : system_11894784.bin (2314 bytes)
36 : system_12156928.bin (2314 bytes)
37 : system_12419072.bin (2314 bytes)
38 : system_12681216.bin (2314 bytes)
39 : system_12943360.bin (2314 bytes)
40 : system_13205504.bin (2314 bytes)
41 : system_13467648.bin (2314 bytes)
42 : system_13729792.bin (2652 bytes)
43 : system_13731464.bin (2314 bytes)
44 : BackupGPT_61070336.bin (4286 bytes)

Excellent! All the files are there!

Large images are split up by LG, and can be combined with "cat" or something like that.

The filename actually is in the form "partname_offset.bin" where "offset" is the actual location that the file should be written to on the phone's eMMC (handy!)

You can substitute -l in the options for -x again to extract all the partitions to the folder "dzextracted" in the current working directory as well.

The option --out or -o will change the output directory, so it doesn't have to output to {kdz|dz}extracted
​

Where can I download this?

[URL="http://downloads.codefi.re/thecubed/androidtools/Compressed_KDZUtils.zip"]http://downloads.codefi.re/thecubed/androidtools/Compressed_KDZUtils.zip[/URL]

Please don't mirror this file, as having it in one location makes it easy for me to keep it up to date, or pull it if there are problems with this script
​

It doesn't work? Can you help me?!

Sure, join #lg-g2 on Freenode and ask for IOMonster and I'll try to help out as best I can.

I will not answer questions in PM or via email, please don't PM me about this script!

As usual, if this script eats your dog/cat/uncle please don't blame me either. I didn't mean to do it, I swear!
​

Whoo! Thanks! It works! How can I say thanks?

"Thanking" this thread is great!

If you feel that I absolutely saved you many hours of time, feel free to click on the "Donate to Me" button next to my username in this post.

This project was funded by a boring day at work and lots of caffiene :)
​

Alright guys, let me know if you've got any questions and I'll see what I can do!