# Path: avatar2/archs/arm.py
# class ARM(Architecture):
# 
#     get_qemu_executable = Architecture.resolve(QEMU)
#     get_panda_executable = Architecture.resolve(PANDA)
#     get_gdb_executable  = Architecture.resolve(GDB_MULTI)
#     get_oocd_executable = Architecture.resolve(OPENOCD)
# 
# 
# 
#     qemu_name = 'arm'
#     gdb_name = 'arm'
#     registers = {'r0': 0, 'r1': 1, 'r2': 2, 'r3': 3, 'r4': 4, 'r5': 5, 'r6': 6,
#                  'r7': 7, 'r8': 8, 'r9': 9, 'r10': 10, 'r11': 11, 'r12': 12, 'ip': 12,
#                  'sp': 13, 'lr': 14, 'pc': 15, 'cpsr': 25,
#                  }
#     unicorn_registers = {'r0': UC_ARM_REG_R0, 'r1': UC_ARM_REG_R1, 'r2': UC_ARM_REG_R2,
#                          'r3': UC_ARM_REG_R3, 'r4': UC_ARM_REG_R4, 'r5': UC_ARM_REG_R5,
#                          'r6': UC_ARM_REG_R6, 'r7': UC_ARM_REG_R7, 'r8': UC_ARM_REG_R8,
#                          'r9': UC_ARM_REG_R9, 'r10': UC_ARM_REG_R10, 'r11': UC_ARM_REG_R11,
#                          'r12': UC_ARM_REG_R12, 'sp': UC_ARM_REG_SP, 'lr': UC_ARM_REG_LR,
#                          'pc': UC_ARM_REG_PC, 'cpsr': UC_ARM_REG_CPSR}
#     pc_name = 'pc'
#     sr_name = 'cpsr'
#     unemulated_instructions = ['mcr', 'mrc']
#     capstone_arch = CS_ARCH_ARM
#     capstone_mode = CS_MODE_LITTLE_ENDIAN
#     keystone_arch = KS_ARCH_ARM
#     keystone_mode = KS_MODE_ARM
#     unicorn_arch = UC_ARCH_ARM
#     unicorn_mode = UC_MODE_ARM
# 
# Path: avatar2/targets/target.py
# class TargetStates(IntEnum):
#     """
#     A simple Enum for the different states a target can be in.
#     """
#     CREATED = 0x1
#     INITIALIZED = 0x2
#     STOPPED = 0x4
#     RUNNING = 0x8
#     SYNCING = 0x10
#     EXITED = 0x20
#     NOT_RUNNING = INITIALIZED | STOPPED
#     BREAKPOINT = SYNCING | STOPPED
# 
# Path: avatar2/message.py
# class AvatarMessage(object):
#     def __init__(self, origin):
#         self.origin = origin
# 
#     def __str__(self):
#         if self.origin:
#             return "%s from %s" % (self.__class__.__name__, self.origin.name)
#         else:
#             return "%s from unkown origin" % self.__class__.__name__
# 
# class UpdateStateMessage(AvatarMessage):
#     def __init__(self, origin, new_state):
#         super(UpdateStateMessage, self).__init__(origin)
#         self.state = new_state
# 
# class BreakpointHitMessage(UpdateStateMessage):
#     def __init__(self, origin, breakpoint_number, address):
#         super(BreakpointHitMessage, self).__init__(origin, TargetStates.BREAKPOINT)
#         self.breakpoint_number = breakpoint_number
#         self.address = address
# 
# class SyscallCatchedMessage(BreakpointHitMessage):
#     def __init__(self, origin, breakpoint_number, address, type='entry'):
#         super(self.__class__, self).__init__(origin, breakpoint_number, address)
#         self.type = type


import sys
import logging
import re
import pygdbmi.gdbcontroller
import parse
    import Queue as queue
    import queue
from threading import Thread, Event, Condition
from struct import pack, unpack
from codecs import encode
from avatar2.archs.arm import ARM
from avatar2.targets import TargetStates
from avatar2.message import AvatarMessage, UpdateStateMessage, BreakpointHitMessage, SyscallCatchedMessage
                                                  int(payload['frame']['addr'], 16))
            elif payload.get('reason') == 'exited-normally':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.EXITED)
            elif payload.get('reason') == 'end-stepping-range':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'signal-received':
                if payload.get('signal-name') == 'SIGSEGV':
                    avatar_msg = UpdateStateMessage(
                        self._origin, TargetStates.EXITED)
                elif payload.get('signal-name') == 'SIGTRAP':
                    avatar_msg = BreakpointHitMessage(self._origin, -1,
                                                      int(payload['frame']['addr'], 16))
                else:
                    avatar_msg = UpdateStateMessage(
                        self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'watchpoint-trigger':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'access-watchpoint-trigger':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'read-watchpoint-trigger':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'syscall-entry':
                avatar_msg = SyscallCatchedMessage(self._origin, int(payload['bkptno']),
                                                  int(payload['frame']['addr'], 16), 'entry')
            elif payload.get('reason') == 'syscall-return':

# Path: avatar2/archs/arm.py
# class ARM(Architecture):
# 
#     get_qemu_executable = Architecture.resolve(QEMU)
#     get_panda_executable = Architecture.resolve(PANDA)
#     get_gdb_executable  = Architecture.resolve(GDB_MULTI)
#     get_oocd_executable = Architecture.resolve(OPENOCD)
# 
# 
# 
#     qemu_name = 'arm'
#     gdb_name = 'arm'
#     registers = {'r0': 0, 'r1': 1, 'r2': 2, 'r3': 3, 'r4': 4, 'r5': 5, 'r6': 6,
#                  'r7': 7, 'r8': 8, 'r9': 9, 'r10': 10, 'r11': 11, 'r12': 12, 'ip': 12,
#                  'sp': 13, 'lr': 14, 'pc': 15, 'cpsr': 25,
#                  }
#     unicorn_registers = {'r0': UC_ARM_REG_R0, 'r1': UC_ARM_REG_R1, 'r2': UC_ARM_REG_R2,
#                          'r3': UC_ARM_REG_R3, 'r4': UC_ARM_REG_R4, 'r5': UC_ARM_REG_R5,
#                          'r6': UC_ARM_REG_R6, 'r7': UC_ARM_REG_R7, 'r8': UC_ARM_REG_R8,
#                          'r9': UC_ARM_REG_R9, 'r10': UC_ARM_REG_R10, 'r11': UC_ARM_REG_R11,
#                          'r12': UC_ARM_REG_R12, 'sp': UC_ARM_REG_SP, 'lr': UC_ARM_REG_LR,
#                          'pc': UC_ARM_REG_PC, 'cpsr': UC_ARM_REG_CPSR}
#     pc_name = 'pc'
#     sr_name = 'cpsr'
#     unemulated_instructions = ['mcr', 'mrc']
#     capstone_arch = CS_ARCH_ARM
#     capstone_mode = CS_MODE_LITTLE_ENDIAN
#     keystone_arch = KS_ARCH_ARM
#     keystone_mode = KS_MODE_ARM
#     unicorn_arch = UC_ARCH_ARM
#     unicorn_mode = UC_MODE_ARM
# 
# Path: avatar2/targets/target.py
# class TargetStates(IntEnum):
#     """
#     A simple Enum for the different states a target can be in.
#     """
#     CREATED = 0x1
#     INITIALIZED = 0x2
#     STOPPED = 0x4
#     RUNNING = 0x8
#     SYNCING = 0x10
#     EXITED = 0x20
#     NOT_RUNNING = INITIALIZED | STOPPED
#     BREAKPOINT = SYNCING | STOPPED
# 
# Path: avatar2/message.py
# class AvatarMessage(object):
#     def __init__(self, origin):
#         self.origin = origin
# 
#     def __str__(self):
#         if self.origin:
#             return "%s from %s" % (self.__class__.__name__, self.origin.name)
#         else:
#             return "%s from unkown origin" % self.__class__.__name__
# 
# class UpdateStateMessage(AvatarMessage):
#     def __init__(self, origin, new_state):
#         super(UpdateStateMessage, self).__init__(origin)
#         self.state = new_state
# 
# class BreakpointHitMessage(UpdateStateMessage):
#     def __init__(self, origin, breakpoint_number, address):
#         super(BreakpointHitMessage, self).__init__(origin, TargetStates.BREAKPOINT)
#         self.breakpoint_number = breakpoint_number
#         self.address = address
# 
# class SyscallCatchedMessage(BreakpointHitMessage):
#     def __init__(self, origin, breakpoint_number, address, type='entry'):
#         super(self.__class__, self).__init__(origin, breakpoint_number, address)
#         self.type = type


# Path: avatar2/protocols/gdb.py
import sys
import logging
import re
import pygdbmi.gdbcontroller
import parse
    import Queue as queue
    import queue
from threading import Thread, Event, Condition
from struct import pack, unpack
from codecs import encode
from avatar2.archs.arm import ARM
from avatar2.targets import TargetStates
from avatar2.message import AvatarMessage, UpdateStateMessage, BreakpointHitMessage, SyscallCatchedMessage

                                                  int(payload['frame']['addr'], 16))
            elif payload.get('reason') == 'exited-normally':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.EXITED)
            elif payload.get('reason') == 'end-stepping-range':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'signal-received':
                if payload.get('signal-name') == 'SIGSEGV':
                    avatar_msg = UpdateStateMessage(
                        self._origin, TargetStates.EXITED)
                elif payload.get('signal-name') == 'SIGTRAP':
                    avatar_msg = BreakpointHitMessage(self._origin, -1,
                                                      int(payload['frame']['addr'], 16))
                else:
                    avatar_msg = UpdateStateMessage(
                        self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'watchpoint-trigger':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'access-watchpoint-trigger':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'read-watchpoint-trigger':
                avatar_msg = UpdateStateMessage(
                    self._origin, TargetStates.STOPPED)
            elif payload.get('reason') == 'syscall-entry':
                avatar_msg = SyscallCatchedMessage(self._origin, int(payload['bkptno']),
                                                  int(payload['frame']['addr'], 16), 'entry')
            elif payload.get('reason') == 'syscall-return':

                avatar_msg = SyscallCatchedMessage(self._origin, int(payload['bkptno']),