コード例 #1
0
ファイル: dump-file.py プロジェクト: visdom2000/lglaf
def main():
    args = parser.parse_args()
    logging.basicConfig(
        format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
        level=logging.DEBUG if args.debug else logging.INFO)

    comm = lglaf.autodetect_device()
    with closing(comm):
        lglaf.try_hello(comm)

        # Be careful: a too large read size will result in a hang while LAF
        # tries to read more data, requiring a reset.
        if args.size:
            offset = args.offset
            size = args.size
        else:
            offset = args.offset
            size = get_file_size(comm, args.file)
            if offset > size:
                _logger.warning(
                    "Offset %d is larger than the detected size %d", offset,
                    size)
            size -= offset
        if size > 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, offset)
        else:
            _logger.warning("Not a file or zero size, not writing file")
コード例 #2
0
def main():
    args = parser.parse_args()
    logging.basicConfig(
        format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
        level=logging.DEBUG if args.debug else logging.INFO)

    try:
        os.makedirs(args.outdir)
    except OSError:
        pass

    comm = lglaf.autodetect_device()
    with closing(comm):
        lglaf.try_hello(comm)
        _logger.debug("Using Protocol version: 0x%x" % comm.protocol_version)

        with partitions.laf_open_disk(comm) as disk_fd:
            _logger.debug("Opened fd %d for disk", disk_fd)
            dump_partitions(comm, disk_fd, args.outdir, args.max_size * 1024,
                            args.batch)

    if args.batch:
        print("#All finished")
    else:
        _logger.info("All finished!")
コード例 #3
0
def main():
    args = parser.parse_args()
    logging.basicConfig(format='%(name)s: %(levelname)s: %(message)s',
                        level=logging.DEBUG if args.debug else logging.INFO)

    comm = lglaf.autodetect_device()
    with closing(comm):
        do_challenge_response(comm)

        if not args.skip_hello:
            lglaf.try_hello(comm)
コード例 #4
0
def main():
    args = parser.parse_args()
    logging.basicConfig(format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
            level=logging.DEBUG if args.debug else logging.INFO)

    try: os.makedirs(args.outdir)
    except OSError: pass

    comm = lglaf.autodetect_device()
    with closing(comm):
        lglaf.try_hello(comm)
        with partitions.laf_open_disk(comm) as disk_fd:
            _logger.debug("Opened fd %d for disk", disk_fd)
            dump_partitions(comm, disk_fd, args.outdir, args.max_size * 1024)
コード例 #5
0
def main():
    args = parser.parse_args()
    logging.basicConfig(format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
            level=logging.DEBUG if args.debug else logging.INFO)

    try: os.makedirs(args.outdir)
    except OSError: pass

    comm = lglaf.autodetect_device()
    with closing(comm):
        if not args.skip_hello:
            lglaf.try_hello(comm)

        with partitions.laf_open_disk(comm) as disk_fd:
            _logger.debug("Opened fd %d for disk", disk_fd)
            dump_partitions(comm, disk_fd, args.outdir, args.max_size * 1024)
コード例 #6
0
ファイル: dump-file.py プロジェクト: Mathnerd314/lglaf
def main():
    args = parser.parse_args()
    logging.basicConfig(format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
            level=logging.DEBUG if args.debug else logging.INFO)

    comm = lglaf.autodetect_device()
    with closing(comm):
        lglaf.try_hello(comm)

        # Be careful: a too large read size will result in a hang while LAF
        # tries to read more data, requiring a reset.
        size = get_file_size(comm, args.file)
        if size > 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")
コード例 #7
0
def main():
    args = parser.parse_args()
    logging.basicConfig(
        format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
        level=logging.DEBUG if args.debug else logging.INFO)

    actions = (args.list, args.dump, args.restore, args.wipe)
    if sum(1 if x else 0 for x in actions) != 1:
        parser.error("Please specify one action from"
                     " --list / --dump / --restore / --wipe")
    if not args.partition and (args.dump or args.restore or args.wipe):
        parser.error("Please specify a partition")

    comm = lglaf.autodetect_device()
    with closing(comm):
        lglaf.try_hello(comm)

        if args.list:
            list_partitions(comm, args.partition)
            return

        partitions = get_partitions(comm)
        try:
            part_label, part_name = find_partition(partitions, args.partition)
        except ValueError as e:
            parser.error(e)

        part_offset, part_size = partition_info(comm, part_name)
        _logger.debug("Partition %s (%s) at offset %d (%#x) size %d (%#x)",
                      part_label, part_name, part_offset, part_offset,
                      part_size, part_size)
        with laf_open_disk(comm) as disk_fd:
            _logger.debug("Opened fd %d for disk", disk_fd)
            if args.dump:
                dump_partition(comm, disk_fd, args.dump, part_offset,
                               part_size)
            elif args.restore:
                write_partition(comm, disk_fd, args.restore, part_offset,
                                part_size)
            elif args.wipe:
                wipe_partition(comm, disk_fd, part_offset, part_size)
コード例 #8
0
ファイル: partitions.py プロジェクト: Mathnerd314/lglaf
def main():
    args = parser.parse_args()
    logging.basicConfig(format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
            level=logging.DEBUG if args.debug else logging.INFO)

    actions = (args.list, args.dump, args.restore, args.wipe)
    if sum(1 if x else 0 for x in actions) != 1:
        parser.error("Please specify one action from"
        " --list / --dump / --restore / --wipe")
    if not args.partition and (args.dump or args.restore or args.wipe):
        parser.error("Please specify a partition")

    comm = lglaf.autodetect_device()
    with closing(comm):
        lglaf.try_hello(comm)

        if args.list:
            list_partitions(comm, args.partition)
            return

        partitions = get_partitions(comm)
        try:
            part_label, part_name = find_partition(partitions, args.partition)
        except ValueError as e:
            parser.error(e)

        part_offset, part_size = partition_info(comm, part_name)
        _logger.debug("Partition %s (%s) at offset %d (%#x) size %d (%#x)",
                part_label, part_name, part_offset, part_offset, part_size, part_size)
        with laf_open_disk(comm) as disk_fd:
            _logger.debug("Opened fd %d for disk", disk_fd)
            if args.dump:
                dump_partition(comm, disk_fd, args.dump, part_offset, part_size)
            elif args.restore:
                write_partition(comm, disk_fd, args.restore, part_offset, part_size)
            elif args.wipe:
                wipe_partition(comm, disk_fd, part_offset, part_size)
コード例 #9
0
def main():
    args = parser.parse_args()
    logging.basicConfig(format='%(asctime)s %(name)s: %(levelname)s: %(message)s',
            level=logging.DEBUG if args.debug else logging.INFO)

    actions = (args.list, args.dump, args.restore, args.restoremisc, args.wipe)
    if sum(1 if x else 0 for x in actions) != 1:
        parser.error("Please specify one action from"
        " --list / --dump / --restore /--restoremisc / --wipe")
    if not args.partition and (args.dump or args.restore or args.wipe):
        parser.error("Please specify a partition")

    if args.partition and args.partition.isdigit():
        args.partition = int(args.partition)

    comm = lglaf.autodetect_device()
    with closing(comm):

        lglaf.try_hello(comm)
        _logger.debug("Using Protocol version: 0x%x" % comm.protocol_version)

        with laf_open_disk(comm) as disk_fd:
            if args.list:
                if args.batch:
                    list_partitions(comm, disk_fd, args.partition, True)
                else:
                    list_partitions(comm, disk_fd, args.partition, False)
                return

            diskinfo = get_partitions(comm, disk_fd)
            try:
                part = find_partition(diskinfo, args.partition)
            except ValueError as e:
                parser.error(e)

            info = get_partition_info_string(part)

            _logger.debug("%s", info)

            part_offset = part.first_lba * BLOCK_SIZE
            part_size = (part.last_lba - (part.first_lba - 1)) * BLOCK_SIZE

            _logger.debug("%s", info)

            _logger.debug("Opened fd %d for disk", disk_fd)
            if args.dump:
                if not args.batch:
                    dump_partition(comm, disk_fd, args.dump, part_offset, part_size, False)
                else:
                    dump_partition(comm, disk_fd, args.dump, part_offset, part_size, True)
            elif args.restore:
                if not args.batch:
                    write_partition(comm, disk_fd, args.restore, part_offset, part_size, False)
                else:
                    write_partition(comm, disk_fd, args.restore, part_offset, part_size, True)
            elif args.restoremisc:
                if not args.batch:
                    write_misc_partition(comm, disk_fd, args.restoremisc, part_offset, part_size, False)
                else:
                    write_misc_partition(comm, disk_fd, args.restoremisc, part_offset, part_size, True)
            elif args.wipe:
                if not args.batch:
                    wipe_partition(comm, disk_fd, part_offset, part_size, False)
                else:
                    wipe_partition(comm, disk_fd, part_offset, part_size, True)
コード例 #10
0
#!/usr/bin/env python
import lglaf

import argparse
import sys

comm = lglaf.autodetect_device()


def make_exec_request(shell_command):
    argv = b'sh -c eval\t"$*"\t -- '
    argv += shell_command.encode('ascii') if isinstance(shell_command,
                                                        str) else shell_command

    if len(argv) > 255:
        raise RuntimeError("Command length %d is larger than 255" % len(argv))

    return lglaf.make_request(b'EXEC', body=argv + b'\0')


def send_command(cmd):
    cmd = make_exec_request(cmd)
    return comm.call(cmd)[1]


def send_file(src, dst):
    with open(src, 'rb') as fp:
        fp.seek(0, 2)
        size = fp.tell()
        fp.seek(0)
コード例 #11
0
ファイル: send-file.py プロジェクト: langbeck/lglaf
#!/usr/bin/env python
import lglaf

import argparse
import sys


comm = lglaf.autodetect_device()


def make_exec_request(shell_command):
  argv = b'sh -c eval\t"$*"\t -- '
  argv += shell_command.encode('ascii') if isinstance(shell_command, str) else shell_command

  if len(argv) > 255:
    raise RuntimeError("Command length %d is larger than 255" % len(argv))

  return lglaf.make_request(b'EXEC', body=argv + b'\0')


def send_command(cmd):
  cmd = make_exec_request(cmd)
  return comm.call(cmd)[1]


def send_file(src, dst):
  with open(src, 'rb') as fp:
    fp.seek(0, 2)
    size = fp.tell()
    fp.seek(0)