From 6c1f8e78c9205b710be7462a08c0c13392f972ad Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 3 Jan 2016 22:22:38 +0100 Subject: [PATCH] dump-file.py: added Also adds G2 and G4 from @invisiblek to the tested devices list. --- LICENSE | 2 +- README.md | 3 ++ dump-file.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100755 dump-file.py diff --git a/LICENSE b/LICENSE index 4110768..fd0f82e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015 Peter Wu +Copyright (c) 2015, 2016 Peter Wu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index df33f69..09b0d6e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Contents of this repository: (convenience script that uses partitions.py under the hood). By default the largest partitions (system, cache, cust, userdata) are not dumped though. This can be changed with the `--max-size` option. + - [dump-file.py](dump-file.py) - dumps a regular file from device. - [protocol.md](protocol.md) - Protocol documentation. - [lglaf.lua](lglaf.lua) - Wireshark dissector for LG LAF protocol. - [scripts/](scripts/) - Miscellaneous scripts. @@ -32,6 +33,8 @@ Tested with: - LG G3 (D855) on 64-bit Arch Linux (Python 3.5.1, pyusb 1.0.0b2, libusb 1.0.20) - LG G3 (D855) on 32-bit Windows XP (Python 3.4.4, LG drivers). + - LG G2 (VS985). + - LG G4 (VS986) on Linux (Python 3.5) and Windows. ## Usage This tool provides an interactive shell where you can execute commands in diff --git a/dump-file.py b/dump-file.py new file mode 100755 index 0000000..3b42e54 --- /dev/null +++ b/dump-file.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# +# Dumps the contents of a file. +# +# Copyright (C) 2016 Peter Wu +# Licensed under the MIT license . + +from contextlib import closing, contextmanager +import argparse, logging, os, struct, sys +import lglaf + +_logger = logging.getLogger("dump-file") + +def read_uint32(data, offset): + return struct.unpack_from(' 0: + _logger.debug("File size is %d", size) + with laf_open_ro(comm, args.file) as file_fd: + _logger.debug("Opened fd %d for file %s", file_fd, args.file) + dump_file(comm, file_fd, args.output_file, size) + else: + _logger.warning("Not a file or zero size, not writing file") + +if __name__ == '__main__': + try: + main() + except OSError as e: + # Ignore when stdout is closed in a pipe + if e.errno != 32: + raise