示例#1
0
 def __init__(self, tty='/dev/ttyUSB0', fastboot_mode=True, debug=False):
     not_connected = True
     sys.stderr.write("Waiting for device...")
     sys.stderr.flush()
     while not_connected:
         try:
             self._client = HbootClient(tty,
                                        blocking_io=False,
                                        fastboot_mode=fastboot_mode,
                                        debug=debug)
             not_connected = False
         except Exception as e:
             time.sleep(1)
     sys.stderr.write("\r                     \r")
示例#2
0
    def connect_to_device(args):
        global fbc
        not_connected = True
        while not_connected:
            try:
                fbc = HbootClient(debug=args.debug)
                not_connected = False
            except Exception as e:
                time.sleep(1)

        return (True, 'OK')
示例#3
0
 def __init__(self, tty='/dev/ttyUSB0',
                    fastboot_mode=True,
                    debug=False):
     not_connected = True
     sys.stderr.write("Waiting for device...")
     sys.stderr.flush()
     while not_connected:
         try:
             self._client = HbootClient(tty,
                 blocking_io=False,
                 fastboot_mode=fastboot_mode,
                 debug=debug
             )
             not_connected = False
         except Exception as e:
             time.sleep(1)
     sys.stderr.write("\r                     \r")
示例#4
0
class HbootDbg:
    def __init__(self, tty='/dev/ttyUSB0', fastboot_mode=True, debug=False):
        not_connected = True
        sys.stderr.write("Waiting for device...")
        sys.stderr.flush()
        while not_connected:
            try:
                self._client = HbootClient(tty,
                                           blocking_io=False,
                                           fastboot_mode=fastboot_mode,
                                           debug=debug)
                not_connected = False
            except Exception as e:
                time.sleep(1)
        sys.stderr.write("\r                     \r")

    def attach(self):
        cmd = Command(COMMAND['attach'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def detach(self):
        cmd = Command(COMMAND['detach'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def read(self, address, size):
        cmd = Command(COMMAND['read'], address=address, size=size)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def write(self, address, size, data):
        cmd = Command(COMMAND['write'], address=address, size=size, data=data)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def insert_breakpoint(self, address, type=BREAKPOINT_NORMAL):
        cmd = Command(COMMAND['insert_breakpoint'],
                      address=address,
                      breakpoint_type=type)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def remove_breakpoint(self, address, type=BREAKPOINT_NORMAL):
        cmd = Command(COMMAND['remove_breakpoint'],
                      address=address,
                      breakpoint_type=type)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def breakpoint_continue(self):
        cmd = Command(COMMAND['breakpoint_continue'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def get_registers(self):
        cmd = Command(COMMAND['get_registers'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def call(self, address, args=(0, 0, 0, 0)):
        cmd = Command(COMMAND['call'], address=address, args=args)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def breakpoint(self):
        cmd = Command(COMMAND['breakpoint'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def flashlight(self, time_):
        cmd = Command(COMMAND['flashlight'], time_)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def fastboot_reboot(self):
        cmd = Command(COMMAND['fastboot_reboot'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def raw(self, data):
        return self._client.hbootdbg(data.to_bytes(4, sys.byteorder))

    def console(self):
        while True:
            cmd = input('hbootdbg> ').split()

            if cmd[0] not in CONSOLE_COMMAND:
                print('Unknown command %s' % cmd[0])
                continue

            if len(cmd) != CONSOLE_COMMAND[cmd[0]].nb_args + 1:
                print('Usage: %s' % CONSOLE_COMMAND[cmd[0]].usage)
                continue

            args = tuple([int(arg, 16) for arg in cmd[1:]])
            response = CONSOLE_COMMAND[cmd[0]].func(self, *args)

            if response.error != ERROR_SUCCESS:
                print(ERROR[response.error])

            if isinstance(response, Command) and response.data != None:
                print(binascii.hexlify(response.data))
            elif not isinstance(response, Command):
                print(binascii.hexlify(response))
示例#5
0
class HbootDbg:

    def __init__(self, tty='/dev/ttyUSB0',
                       fastboot_mode=True,
                       debug=False):
        not_connected = True
        sys.stderr.write("Waiting for device...")
        sys.stderr.flush()
        while not_connected:
            try:
                self._client = HbootClient(tty,
                    blocking_io=False,
                    fastboot_mode=fastboot_mode,
                    debug=debug
                )
                not_connected = False
            except Exception as e:
                time.sleep(1)
        sys.stderr.write("\r                     \r")

    def attach(self):
        cmd = Command(COMMAND['attach'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def detach(self):
        cmd = Command(COMMAND['detach'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def read(self, address, size):
        cmd = Command(COMMAND['read'],
                address=address,
                size=size)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def write(self, address, size, data):
        cmd = Command(COMMAND['write'],
                address=address,
                size=size,
                data=data)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def insert_breakpoint(self, address, type=BREAKPOINT_NORMAL):
        cmd = Command(COMMAND['insert_breakpoint'],
                address=address, breakpoint_type=type)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def remove_breakpoint(self, address, type=BREAKPOINT_NORMAL):
        cmd = Command(COMMAND['remove_breakpoint'],
                address=address, breakpoint_type=type)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def breakpoint_continue(self):
        cmd = Command(COMMAND['breakpoint_continue'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def get_registers(self):
        cmd = Command(COMMAND['get_registers'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def call(self, address, args = (0, 0, 0, 0)):
        cmd = Command(COMMAND['call'],
                address=address,
                args=args)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def breakpoint(self):
        cmd = Command(COMMAND['breakpoint'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def flashlight(self, time_):
        cmd = Command(COMMAND['flashlight'], time_)
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def fastboot_reboot(self):
        cmd = Command(COMMAND['fastboot_reboot'])
        return Command().unpack(self._client.hbootdbg(cmd.pack()))

    def raw(self, data):
        return self._client.hbootdbg(data.to_bytes(4, sys.byteorder))

    def console(self):
        while True:
            cmd = input('hbootdbg> ').split()

            if cmd[0] not in CONSOLE_COMMAND:
                print('Unknown command %s' % cmd[0])
                continue

            if len(cmd) != CONSOLE_COMMAND[cmd[0]].nb_args + 1:
                print('Usage: %s' % CONSOLE_COMMAND[cmd[0]].usage)
                continue

            args = tuple([int(arg, 16) for arg in cmd[1:]])
            response = CONSOLE_COMMAND[cmd[0]].func(self, *args)

            if response.error != ERROR_SUCCESS:
                print(ERROR[response.error])

            if isinstance(response, Command) and response.data != None:
                print(binascii.hexlify(response.data))
            elif not isinstance(response, Command):
                print(binascii.hexlify(response))