# Path: avatar2/message.py
# class UpdateStateMessage(AvatarMessage):
#     def __init__(self, origin, new_state):
#         super(UpdateStateMessage, self).__init__(origin)
#         self.state = new_state
# 
# class RemoteMemoryReadMessage(AvatarMessage):
#     def __init__(self, origin, id, pc, address, size, dst=None):
#         super(self.__class__, self).__init__(origin)
#         self.id = id
#         self.pc = pc
#         self.address = address
#         self.size = size
#         self.dst = dst
#         self.num_words = 1
#         self.raw = False
# 
# class RemoteMemoryWriteMessage(AvatarMessage):
#     def __init__(self, origin, id, pc, address, value, size, dst=None):
#         super(self.__class__, self).__init__(origin)
#         self.id = id
#         self.pc = pc
#         self.address = address
#         self.value = value
#         self.size = size
#         self.dst = dst
# 
# 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
# 
# 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/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


import sys
    import Queue as queue
    import queue
import struct
import unicorn
import logging
from threading import Thread
from collections import namedtuple
from avatar2.message import UpdateStateMessage, RemoteMemoryReadMessage, \
    RemoteMemoryWriteMessage, BreakpointHitMessage
from avatar2.targets import TargetStates
from avatar2.archs.arm import ARM

    def _breakpoint_hook(self, uc, address, size, bkptno):
        """Unicorn hook for breakpoints."""
        if bkptno in self.pending_bp:
            return
        bp = self._breakpoints[bkptno]
        if bp.ignore_count > 0:
            bp.ignore_count -= 1
            return

        self.pending_bp.add(bkptno)
        self._worker_queue.put(UnicornWorkerBreakpointMessage(bkptno, address))
        self.uc.emu_stop()

        if bp.temporary:
            self.remove_breakpoint(bkptno)

    def _watchpoint_hook(self, uc, access, address, size, value, bkptno):
        """Unicorn hook for watchpoints."""
        if bkptno in self.pending_bp:
            return
        self.pending_bp.add(bkptno)
        self.stop()

    def _worker_emu_start(self, single_step=False):
        """Start the emulation inside the worker."""
        self._worker_queue.put(UnicornWorkerEmuStartMessage(single_step))

    def _worker_emu_stop(self):
        """Stop the emulation inside the worker."""

# Path: avatar2/message.py
# class UpdateStateMessage(AvatarMessage):
#     def __init__(self, origin, new_state):
#         super(UpdateStateMessage, self).__init__(origin)
#         self.state = new_state
# 
# class RemoteMemoryReadMessage(AvatarMessage):
#     def __init__(self, origin, id, pc, address, size, dst=None):
#         super(self.__class__, self).__init__(origin)
#         self.id = id
#         self.pc = pc
#         self.address = address
#         self.size = size
#         self.dst = dst
#         self.num_words = 1
#         self.raw = False
# 
# class RemoteMemoryWriteMessage(AvatarMessage):
#     def __init__(self, origin, id, pc, address, value, size, dst=None):
#         super(self.__class__, self).__init__(origin)
#         self.id = id
#         self.pc = pc
#         self.address = address
#         self.value = value
#         self.size = size
#         self.dst = dst
# 
# 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
# 
# 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/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/protocols/unicorn_protocol.py
import sys
    import Queue as queue
    import queue
import struct
import unicorn
import logging
from threading import Thread
from collections import namedtuple
from avatar2.message import UpdateStateMessage, RemoteMemoryReadMessage, \
    RemoteMemoryWriteMessage, BreakpointHitMessage
from avatar2.targets import TargetStates
from avatar2.archs.arm import ARM


    def _breakpoint_hook(self, uc, address, size, bkptno):
        """Unicorn hook for breakpoints."""
        if bkptno in self.pending_bp:
            return
        bp = self._breakpoints[bkptno]
        if bp.ignore_count > 0:
            bp.ignore_count -= 1
            return

        self.pending_bp.add(bkptno)
        self._worker_queue.put(UnicornWorkerBreakpointMessage(bkptno, address))
        self.uc.emu_stop()

        if bp.temporary:
            self.remove_breakpoint(bkptno)

    def _watchpoint_hook(self, uc, access, address, size, value, bkptno):
        """Unicorn hook for watchpoints."""
        if bkptno in self.pending_bp:
            return
        self.pending_bp.add(bkptno)
        self.stop()

    def _worker_emu_start(self, single_step=False):
        """Start the emulation inside the worker."""
        self._worker_queue.put(UnicornWorkerEmuStartMessage(single_step))

    def _worker_emu_stop(self):
        """Stop the emulation inside the worker."""

        self._worker_queue.put(UnicornWorkerUpdateStateMessage(TargetStates.STOPPED))