Skip to content

Commit

Permalink
Added -o OUTPUT_DIR argument
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano committed Jun 25, 2017
1 parent fe9e51a commit baa911e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ positional arguments:
filename Android kernel image
optional arguments:
-h, --help show this help message and exit
-n Do not extract, just output information
-h, --help show this help message and exit
-o OUTPUT_DIR Output directory
-n Do not extract, just output information
```

Example:
Expand All @@ -33,10 +34,10 @@ Example:
$ ./extract-dtb.py -n vmlinuz-motorola-titan
Found 8 appended dtbs
$ ./extract-dtb.py vmlinuz-motorola-titan
$ ./extract-dtb.py vmlinuz-motorola-titan -o /tmp/dtb
Extracted 8 appended dtbs + kernel
$ ls -l
$ ls -l /tmp/dtb
total 8808
-rw-rw-r-- 1 pablo pablo 194829 jun 25 17:14 dtbdump_1.dtb
-rw-rw-r-- 1 pablo pablo 194829 jun 25 17:14 dtbdump_2.dtb
Expand Down
12 changes: 8 additions & 4 deletions extract-dtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

import argparse
import sys
import os

DTB_HEADER = b"\xd0\x0d\xfe\xed"

Expand All @@ -45,23 +45,27 @@ def split(args):
return

if args.extract:
os.makedirs(args.output_dir, exist_ok=True)
last_pos = 0
for n, pos in enumerate(pos_dtb, 0):
dtb_filename = "dtbdump_{0}.dtb".format(n) if n != 0 else "kernel"
dump_file(dtb_filename, content[last_pos:pos])
dump_file(os.path.join(args.output_dir, dtb_filename), content[last_pos:pos])
last_pos = pos

# Last chunk
dtb_filename = "dtbdump_{0}.dtb".format(n)
dump_file(dtb_filename, content[last_pos:])
print("Extracted {0} appended dtbs + kernel".format(len(pos_dtb) - 1))
dump_file(os.path.join(args.output_dir, dtb_filename), content[last_pos:])
print("Extracted {0} appended dtbs + kernel to {1}"
.format(len(pos_dtb) - 1, args.output_dir))
else:
print("Found {0} appended dtbs".format(len(pos_dtb) - 1))


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Extract dtbs from kernel images.")
parser.add_argument("filename", help="Android kernel image")
parser.add_argument("-o", dest="output_dir", default="dtb",
required=False, help="Output directory")
parser.add_argument("-n", dest="extract", action="store_false", default=True,
required=False, help="Do not extract, just output information")
args = parser.parse_args()
Expand Down

0 comments on commit baa911e

Please sign in to comment.